Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change error display length on all line instead of first char #12

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,9 +362,11 @@ async function refreshDiagnostics(result: ResultType) {
for (let path in result.files) {
const pathItem = result.files[path]
const diagnostics: vscode.Diagnostic[] = []
const document = await getDocumentFromPath(path)

for (const messageItem of pathItem.messages) {
const line = messageItem.line ? messageItem.line - 1 : 0
const range = new vscode.Range(line, 0, line, 0)
const range = getRangeFromDocumentAndLine(document, line)
const diagnostic = new vscode.Diagnostic(
range,
messageItem.message,
Expand All @@ -382,6 +384,31 @@ async function refreshDiagnostics(result: ResultType) {
}
}

async function getDocumentFromPath(path: string) {
try {
return await vscode.workspace.openTextDocument(vscode.Uri.file(path))
} catch (error) {
setStatusBarError(error, "Document not found")
return null
}
}

function getRangeFromDocumentAndLine(
document: vscode.TextDocument | null,
line: number
) {
if (!document) {
return new vscode.Range(line, 0, line, 0)
}
const textLine = document?.lineAt(line)
return new vscode.Range(
line,
textLine.firstNonWhitespaceCharacterIndex,
line,
textLine.range.end.character
)
}

function getWorkspacePath() {
const [folder] = vscode.workspace.workspaceFolders || []
return folder ? folder.uri.fsPath : null
Expand Down