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

Commit

Permalink
Close gocode daemon on deactivation (#2137)
Browse files Browse the repository at this point in the history
* Close gocode daemon on deactivation

Note that the extension doesn't actually start the gocode daemon,
the gocode client itself does that as necessary.

It is safe to close the daemon for the same reason however.
If other clients were using the daemon, it will be restarted
on their next request.

Fixes #2132

* Fix linting error

* Close gocode only if its found
  • Loading branch information
zmb3 authored and ramya-rao-a committed Nov 29, 2018
1 parent a22bbc5 commit 0de9d7a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/goMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -563,5 +563,7 @@ function checkToolExists(tool: string) {
}

function registerCompletionProvider(ctx: vscode.ExtensionContext) {
ctx.subscriptions.push(vscode.languages.registerCompletionItemProvider(GO_MODE, new GoCompletionItemProvider(ctx.globalState), '.', '\"'));
let provider = new GoCompletionItemProvider(ctx.globalState);
ctx.subscriptions.push(provider);
ctx.subscriptions.push(vscode.languages.registerCompletionItemProvider(GO_MODE, provider, '.', '\"'));
}
11 changes: 9 additions & 2 deletions src/goSuggest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ const lineCommentRegex = /^\s*\/\/\s+/;
const exportedMemberRegex = /(const|func|type|var)(\s+\(.*\))?\s+([A-Z]\w*)/;
const gocodeNoSupportForgbMsgKey = 'dontshowNoSupportForgb';

export class GoCompletionItemProvider implements vscode.CompletionItemProvider {

export class GoCompletionItemProvider implements vscode.CompletionItemProvider, vscode.Disposable {
private pkgsList = new Map<string, string>();
private killMsgShown: boolean = false;
private setGocodeOptions: boolean = true;
Expand Down Expand Up @@ -209,6 +208,14 @@ export class GoCompletionItemProvider implements vscode.CompletionItemProvider {
});
}

public dispose() {
let gocodeName = this.isGoMod ? 'gocode-gomod' : 'gocode';
let gocode = getBinPath(gocodeName);
if (path.isAbsolute(gocode)) {
cp.spawn(gocode, ['close'], { env: getToolsEnvVars() });
}
}

private runGoCode(document: vscode.TextDocument, filename: string, inputText: string, offset: number, inString: boolean, position: vscode.Position, lineText: string, currentWord: string, includeUnimportedPkgs: boolean, config: vscode.WorkspaceConfiguration): Thenable<vscode.CompletionItem[]> {
return new Promise<vscode.CompletionItem[]>((resolve, reject) => {
let gocodeName = this.isGoMod ? 'gocode-gomod' : 'gocode';
Expand Down

0 comments on commit 0de9d7a

Please # to comment.