Skip to content
This repository has been archived by the owner on Sep 24, 2021. It is now read-only.

Catch error when calling updateGoPathGoRootFromConfig #17

Closed
wants to merge 1 commit into from
Closed
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
7 changes: 6 additions & 1 deletion src-vscode-mock/activate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ export async function activate(lspClient: LspClient, lspServer: LspServer, logge
return updateGoPathGoRootFromConfig().then(() => {
lspClient.sendTelemetryEvent(workspace.getConfiguration('go'));
offerToInstallTools();
}).catch((e) => {
lspClient.showMessage({
type: MessageType.Error,
message: e.stack,
});
});
}

Expand All @@ -127,4 +132,4 @@ export function mockActivate(lspClient: LspClient) {

errorDiagnosticCollection.onSet(lspClient.publishDiagnostics.bind(lspClient));
warningDiagnosticCollection.onSet(lspClient.publishDiagnostics.bind(lspClient));
}
}
5 changes: 5 additions & 0 deletions src/goInstallTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,11 @@ export function updateGoPathGoRootFromConfig(): Promise<void> {

// If GOPATH is still not set, then use the one from `go env`
let goRuntimePath = getGoRuntimePath();

Copy link
Member

Choose a reason for hiding this comment

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

This could go into vscode-go. Have you considered posting a PR there? I try to keep the possibility to rebase without major problems for as long as possible.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is complicated for us (long/complicated/dumb corporate procedures) to contribute to other projects than those we've been specifically allowed to. Can you open a PR yourself instead?

if (!goRuntimePath) {
return Promise.reject(new Error('Cannot find "go" binary. Update PATH or GOROOT appropriately'));
}

return new Promise<void>((resolve, reject) => {
cp.execFile(goRuntimePath, ['env', 'GOPATH'], (err, stdout, stderr) => {
if (err) {
Expand Down
15 changes: 13 additions & 2 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,18 @@ export interface ICheckResult {
*/
export function runTool(args: string[], cwd: string, severity: string, useStdErr: boolean, toolName: string, env: any, printUnexpectedOutput: boolean, token?: vscode.CancellationToken): Promise<ICheckResult[]> {
let goRuntimePath = getGoRuntimePath();
let cmd = toolName ? getBinPath(toolName) : goRuntimePath;
let cmd;
Copy link
Member

Choose a reason for hiding this comment

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

Same as above: Could vscode-go benefit from that change as well?


if (toolName) {
cmd = getBinPath(toolName);
} else {
if (!goRuntimePath) {
return Promise.reject(new Error('Cannot find "go" binary. Update PATH or GOROOT appropriately'));
}

cmd = goRuntimePath;
}

let p: cp.ChildProcess;
if (token) {
token.onCancellationRequested(() => {
Expand Down Expand Up @@ -764,4 +775,4 @@ export function killTree(processId: number): void {
} catch (err) {
}
}
}
}