Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Commit

Permalink
Fix on save diagnostics
Browse files Browse the repository at this point in the history
  • Loading branch information
ramya-rao-a committed Nov 8, 2017
1 parent 2db5302 commit 99f0957
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 38 deletions.
4 changes: 2 additions & 2 deletions src/goLint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function lintCurrentPackage(): Promise<ICheckResult[]> {
let goConfig = vscode.workspace.getConfiguration('go', documentUri);
outputChannel.clear();
goLint(documentUri, goConfig)
.then(handleDiagnosticErrors(editor ? editor.document : null))
.then(warnings => handleDiagnosticErrors(editor ? editor.document : null, warnings))
.catch(err => {
vscode.window.showInformationMessage('Error: ' + err);
});
Expand All @@ -40,7 +40,7 @@ export function lintWorkspace() {
let goConfig = vscode.workspace.getConfiguration('go', documentUri);
outputChannel.clear();
goLint(documentUri, goConfig, true)
.then(handleDiagnosticErrors(editor ? editor.document : null))
.then(warnings => handleDiagnosticErrors(editor ? editor.document : null, warnings))
.catch(err => {
vscode.window.showInformationMessage('Error: ' + err);
});
Expand Down
4 changes: 2 additions & 2 deletions src/goMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,10 @@ function runBuilds(document: vscode.TextDocument, goConfig: vscode.WorkspaceConf

let uri = document.uri;
check(uri, goConfig)
.then(() => {
.then((errors) => {
errorDiagnosticCollection.clear();
warningDiagnosticCollection.clear();
handleDiagnosticErrors(document);
handleDiagnosticErrors(document, errors);
})
.catch(err => {
vscode.window.showInformationMessage('Error: ' + err);
Expand Down
68 changes: 34 additions & 34 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -568,40 +568,40 @@ export function runTool(args: string[], cwd: string, severity: string, useStdErr
});
}

export function handleDiagnosticErrors(document: vscode.TextDocument) {
return (errors: ICheckResult[]) => {
let diagnosticMap: Map<string, Map<vscode.DiagnosticSeverity, vscode.Diagnostic[]>> = new Map();

errors.forEach(error => {
let canonicalFile = vscode.Uri.file(error.file).toString();
let startColumn = 0;
let endColumn = 1;
if (document && document.uri.toString() === canonicalFile) {
let range = new vscode.Range(error.line - 1, 0, error.line - 1, document.lineAt(error.line - 1).range.end.character + 1);
let text = document.getText(range);
let [_, leading, trailing] = /^(\s*).*(\s*)$/.exec(text);
startColumn = leading.length;
endColumn = text.length - trailing.length;
}
let range = new vscode.Range(error.line - 1, startColumn, error.line - 1, endColumn);
let severity = mapSeverityToVSCodeSeverity(error.severity);
let diagnostic = new vscode.Diagnostic(range, error.msg, severity);
let diagnostics = diagnosticMap.get(canonicalFile);
if (!diagnostics) {
diagnostics = new Map<vscode.DiagnosticSeverity, vscode.Diagnostic[]>();
}
if (!diagnostics[severity]) {
diagnostics[severity] = [];
}
diagnostics[severity].push(diagnostic);
diagnosticMap.set(canonicalFile, diagnostics);
});
diagnosticMap.forEach((diagMap, file) => {
errorDiagnosticCollection.set(vscode.Uri.parse(file), diagMap[vscode.DiagnosticSeverity.Error]);
warningDiagnosticCollection.set(vscode.Uri.parse(file), diagMap[vscode.DiagnosticSeverity.Warning]);
});
};
}
export function handleDiagnosticErrors(document: vscode.TextDocument, errors: ICheckResult[]) {

let diagnosticMap: Map<string, Map<vscode.DiagnosticSeverity, vscode.Diagnostic[]>> = new Map();

errors.forEach(error => {
let canonicalFile = vscode.Uri.file(error.file).toString();
let startColumn = 0;
let endColumn = 1;
if (document && document.uri.toString() === canonicalFile) {
let range = new vscode.Range(error.line - 1, 0, error.line - 1, document.lineAt(error.line - 1).range.end.character + 1);
let text = document.getText(range);
let [_, leading, trailing] = /^(\s*).*(\s*)$/.exec(text);
startColumn = leading.length;
endColumn = text.length - trailing.length;
}
let range = new vscode.Range(error.line - 1, startColumn, error.line - 1, endColumn);
let severity = mapSeverityToVSCodeSeverity(error.severity);
let diagnostic = new vscode.Diagnostic(range, error.msg, severity);
let diagnostics = diagnosticMap.get(canonicalFile);
if (!diagnostics) {
diagnostics = new Map<vscode.DiagnosticSeverity, vscode.Diagnostic[]>();
}
if (!diagnostics[severity]) {
diagnostics[severity] = [];
}
diagnostics[severity].push(diagnostic);
diagnosticMap.set(canonicalFile, diagnostics);
});
diagnosticMap.forEach((diagMap, file) => {
errorDiagnosticCollection.set(vscode.Uri.parse(file), diagMap[vscode.DiagnosticSeverity.Error]);
warningDiagnosticCollection.set(vscode.Uri.parse(file), diagMap[vscode.DiagnosticSeverity.Warning]);
});
};


function mapSeverityToVSCodeSeverity(sev: string): vscode.DiagnosticSeverity {
switch (sev) {
Expand Down

0 comments on commit 99f0957

Please sign in to comment.