From 8743761d4d80ac03ec250facd5dc6f0f52fcc7c3 Mon Sep 17 00:00:00 2001 From: Yann Dardot Date: Wed, 31 Aug 2022 20:30:40 +0200 Subject: [PATCH 1/2] change error display length on all line instead of first char (issue: #6) --- src/extension.ts | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/extension.ts b/src/extension.ts index 687377b..ccc0582 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -362,9 +362,28 @@ async function refreshDiagnostics(result: ResultType) { for (let path in result.files) { const pathItem = result.files[path] const diagnostics: vscode.Diagnostic[] = [] + let document: vscode.TextDocument = null + try { + document = await vscode.workspace.openTextDocument( + vscode.Uri.file(path) + ) + } catch (error) { + setStatusBarError(error, "Document not found") + } for (const messageItem of pathItem.messages) { const line = messageItem.line ? messageItem.line - 1 : 0 - const range = new vscode.Range(line, 0, line, 0) + let range: vscode.Range = null + if (document) { + const lineText = document?.lineAt(line) + range = new vscode.Range( + line, + lineText.firstNonWhitespaceCharacterIndex, + line, + lineText.range.end.character + ) + } else { + range = new vscode.Range(line, 0, line, 0) + } const diagnostic = new vscode.Diagnostic( range, messageItem.message, From 427c83aa9426af549cfdab399bcd21f29a40feda Mon Sep 17 00:00:00 2001 From: Yann Dardot Date: Thu, 1 Sep 2022 10:09:56 +0200 Subject: [PATCH 2/2] change line error display code to better understanding --- src/extension.ts | 48 ++++++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index ccc0582..c92c440 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -362,28 +362,11 @@ async function refreshDiagnostics(result: ResultType) { for (let path in result.files) { const pathItem = result.files[path] const diagnostics: vscode.Diagnostic[] = [] - let document: vscode.TextDocument = null - try { - document = await vscode.workspace.openTextDocument( - vscode.Uri.file(path) - ) - } catch (error) { - setStatusBarError(error, "Document not found") - } + const document = await getDocumentFromPath(path) + for (const messageItem of pathItem.messages) { const line = messageItem.line ? messageItem.line - 1 : 0 - let range: vscode.Range = null - if (document) { - const lineText = document?.lineAt(line) - range = new vscode.Range( - line, - lineText.firstNonWhitespaceCharacterIndex, - line, - lineText.range.end.character - ) - } else { - range = new vscode.Range(line, 0, line, 0) - } + const range = getRangeFromDocumentAndLine(document, line) const diagnostic = new vscode.Diagnostic( range, messageItem.message, @@ -401,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