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

Fix gotype-live errors showing in wrong file #923

Merged
merged 5 commits into from
Apr 17, 2017
Merged
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
25 changes: 17 additions & 8 deletions src/goLiveErrors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ export function goLiveErrorsEnabled() {
if (goConfig === null || goConfig === undefined || !goConfig.enabled) {
return false;
}
let autoSave = vscode.workspace.getConfiguration('files')['autoSave'];
if (autoSave !== null && autoSave !== undefined && autoSave !== 'off') {
let files = vscode.workspace.getConfiguration('files');
let autoSave = files['autoSave'];
let autoSaveDelay = files['autoSaveDelay'];
if (autoSave !== null && autoSave !== undefined &&
autoSave === 'afterDelay' && autoSaveDelay < goConfig.delay * 1.5) {
return false;
}
return goConfig.enabled;
Expand Down Expand Up @@ -51,7 +54,6 @@ export function parseLiveFile(e: vscode.TextDocumentChangeEvent) {

// processFile does the actual work once the timeout has fired
function processFile(e: vscode.TextDocumentChangeEvent) {
let uri = e.document.uri;
let gotypeLive = getBinPath('gotype-live');
let fileContents = e.document.getText();
let fileName = e.document.fileName;
Expand All @@ -62,26 +64,33 @@ function processFile(e: vscode.TextDocumentChangeEvent) {
return;
}

errorDiagnosticCollection.delete(uri);
errorDiagnosticCollection.clear();

if (err) {
// we want to take the error path here because the command we are calling
// returns a non-zero exit status if the checks fail
let diagnostics = [];
let diagnosticMap: Map<string, vscode.Diagnostic[]> = new Map();

stderr.split('\n').forEach(error => {
if (error === null || error.length === 0) {
return;
}
// extract the line, column and error message from the gotype output
let [_, line, column, message] = /^.+:(\d+):(\d+):\s+(.+)/.exec(error);

let [_, file, line, column, message] = /^(.+):(\d+):(\d+):\s+(.+)/.exec(error);
let range = new vscode.Range(+line - 1, +column, +line - 1, +column);
let diagnostic = new vscode.Diagnostic(range, message, vscode.DiagnosticSeverity.Error);

let diagnostics = diagnosticMap.get(file);
if (!diagnostics) {
diagnostics = [];
}
diagnostics.push(diagnostic);
diagnosticMap.set(file, diagnostics);
});

errorDiagnosticCollection.set(uri, diagnostics);
diagnosticMap.forEach((diagnostics, file) => {
errorDiagnosticCollection.set(vscode.Uri.parse('file://' + file), diagnostics);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just curious... why add the prefix file:// before parsing the file to get the uri? vscode.Uri.parse should work with just the file path as well

});
}
});
p.stdin.end(fileContents);
Expand Down