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

Commit 0de9d7a

Browse files
zmb3ramya-rao-a
authored andcommitted
Close gocode daemon on deactivation (#2137)
* 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
1 parent a22bbc5 commit 0de9d7a

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/goMain.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -563,5 +563,7 @@ function checkToolExists(tool: string) {
563563
}
564564

565565
function registerCompletionProvider(ctx: vscode.ExtensionContext) {
566-
ctx.subscriptions.push(vscode.languages.registerCompletionItemProvider(GO_MODE, new GoCompletionItemProvider(ctx.globalState), '.', '\"'));
566+
let provider = new GoCompletionItemProvider(ctx.globalState);
567+
ctx.subscriptions.push(provider);
568+
ctx.subscriptions.push(vscode.languages.registerCompletionItemProvider(GO_MODE, provider, '.', '\"'));
567569
}

src/goSuggest.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ const lineCommentRegex = /^\s*\/\/\s+/;
5555
const exportedMemberRegex = /(const|func|type|var)(\s+\(.*\))?\s+([A-Z]\w*)/;
5656
const gocodeNoSupportForgbMsgKey = 'dontshowNoSupportForgb';
5757

58-
export class GoCompletionItemProvider implements vscode.CompletionItemProvider {
59-
58+
export class GoCompletionItemProvider implements vscode.CompletionItemProvider, vscode.Disposable {
6059
private pkgsList = new Map<string, string>();
6160
private killMsgShown: boolean = false;
6261
private setGocodeOptions: boolean = true;
@@ -209,6 +208,14 @@ export class GoCompletionItemProvider implements vscode.CompletionItemProvider {
209208
});
210209
}
211210

211+
public dispose() {
212+
let gocodeName = this.isGoMod ? 'gocode-gomod' : 'gocode';
213+
let gocode = getBinPath(gocodeName);
214+
if (path.isAbsolute(gocode)) {
215+
cp.spawn(gocode, ['close'], { env: getToolsEnvVars() });
216+
}
217+
}
218+
212219
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[]> {
213220
return new Promise<vscode.CompletionItem[]>((resolve, reject) => {
214221
let gocodeName = this.isGoMod ? 'gocode-gomod' : 'gocode';

0 commit comments

Comments
 (0)