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

Fixes #310 - install Missing Analysis Tool. Better feedback would be nice #375

Merged
merged 5 commits into from
Jul 23, 2016
Merged
Show file tree
Hide file tree
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
42 changes: 34 additions & 8 deletions src/goInstallTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,41 @@ let tools: { [key: string]: string } = {
guru: 'golang.org/x/tools/cmd/guru'
};

export function installTool(tool: string) {
outputChannel.clear();
export function installTools(missing: string[]) {
outputChannel.show();
cp.exec('go get -u -v ' + tools[tool], { env: process.env }, (err, stdout, stderr) => {
outputChannel.append(stdout.toString());
outputChannel.append(stderr.toString());
if (err) {
outputChannel.append('exec error: ' + err);
outputChannel.clear();
outputChannel.appendLine('Installing ' + missing.length + ' missing tools');
missing.forEach((missingTool, index, missing) => {
outputChannel.appendLine(' ' + missingTool);
});

outputChannel.appendLine(''); // Blank line for spacing.

Promise.all(missing.map(tool => new Promise<string>((resolve, reject) => {
Copy link
Contributor

@lukehoban lukehoban Jul 16, 2016

Choose a reason for hiding this comment

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

One thing I was meaning to look into/change was running these serially instead of in parallel. I'm pretty sure go get has issues when multiple gets are run in parallel, and users have reported that the existing extension occasionally runs into errors. Since you are making changes here - may make sense to also just change this to do the gets serially?

cp.exec('go get -u -v ' + tools[tool], { env: process.env }, (err, stdout, stderr) => {
if (err) {
outputChannel.appendLine('Installing ' + tool + ' FAILED');
let failureReason = tool + ';;' + err + stdout.toString() + stderr.toString();
resolve(failureReason);
} else {
outputChannel.appendLine('Installing ' + tool + ' SUCCEEDED');
resolve();
}
});
}))).then(res => {
outputChannel.appendLine(''); // Blank line for spacing
let failures = res.filter(x => x != null);
if (failures.length === 0) {
outputChannel.appendLine('All tools successfully installed. You\'re ready to Go :).');
return;
}

outputChannel.appendLine(failures.length + ' tools failed to install.\n');
failures.forEach((failure, index, failures) => {
let reason = failure.split(';;');
outputChannel.appendLine(reason[0] + ':');
outputChannel.appendLine(reason[1]);
});
});
}

Expand Down Expand Up @@ -80,7 +106,7 @@ export function setupGoPathAndOfferToInstallTools() {
let item = {
title: 'Install',
command() {
missing.forEach(installTool);
installTools(missing);
}
};
vscode.window.showInformationMessage('Some Go analysis tools are missing from your GOPATH. Would you like to install them?', item).then(selection => {
Expand Down
4 changes: 2 additions & 2 deletions src/goReferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import cp = require('child_process');
import path = require('path');
import { getBinPath } from './goPath';
import { byteOffsetAt, canonicalizeGOPATHPrefix } from './util';
import { installTool } from './goInstallTools';
import { installTools } from './goInstallTools';

export class GoReferenceProvider implements vscode.ReferenceProvider {

Expand Down Expand Up @@ -40,7 +40,7 @@ export class GoReferenceProvider implements vscode.ReferenceProvider {
try {
if (err && (<any>err).code === 'ENOENT') {
vscode.window.showInformationMessage('The "guru" command is not available. Use "go get -v golang.org/x/tools/cmd/guru" to install.', 'Install').then(selected => {
installTool('guru');
installTools(['guru']);
Copy link
Contributor

Choose a reason for hiding this comment

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

FWIW -There's another open issue tracking adding this logic to all of the places where we put up an error about a tool not being available. Would be great to address this as well either as part of this change or as a follow-on change.

});
return resolve(null);
}
Expand Down
1 change: 1 addition & 0 deletions src/goSuggest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export class GoCompletionItemProvider implements vscode.CompletionItemProvider {
currentWord = word.substr(0, position.character - wordAtPosition.start.character);
}


Copy link
Contributor

Choose a reason for hiding this comment

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

not needed?

if (currentWord.match(/^\d+$/)) {
return resolve([]);
}
Expand Down