Skip to content

Commit b6b922c

Browse files
benoitffbricon
authored andcommitted
API that is returning Disposable should be added to subscriptions so they're disposed during the stop lifecycle of the plug-in.
handle it for registerCommand and workspace.registerTextDocumentContentProvider and window.onDidChangeActiveTextEditor Change-Id: I10e3f0b96337e69c91d0d98590722f1f4364e4aa Signed-off-by: Florent Benoit <[email protected]>
1 parent d8cc49d commit b6b922c

File tree

3 files changed

+46
-46
lines changed

3 files changed

+46
-46
lines changed

src/buildpath.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
import { window, commands, Uri } from 'vscode';
3+
import { window, commands, ExtensionContext, Uri } from 'vscode';
44
import { Commands } from './commands';
55

66
interface Result {
@@ -19,26 +19,26 @@ interface ListCommandResult extends Result {
1919
data?: SourcePath[];
2020
}
2121

22-
export function registerCommands() {
23-
commands.registerCommand(Commands.ADD_TO_SOURCEPATH, async (uri: Uri) => {
22+
export function registerCommands(context: ExtensionContext) {
23+
context.subscriptions.push(commands.registerCommand(Commands.ADD_TO_SOURCEPATH, async (uri: Uri) => {
2424
const result = await <any>commands.executeCommand(Commands.EXECUTE_WORKSPACE_COMMAND, Commands.ADD_TO_SOURCEPATH, uri.toString());
2525
if (result.status) {
2626
window.showInformationMessage(result.message ? result.message : 'Successfully added the folder to the source path.');
2727
} else {
2828
window.showErrorMessage(result.message);
2929
}
30-
});
30+
}));
3131

32-
commands.registerCommand(Commands.REMOVE_FROM_SOURCEPATH, async (uri: Uri) => {
32+
context.subscriptions.push(commands.registerCommand(Commands.REMOVE_FROM_SOURCEPATH, async (uri: Uri) => {
3333
const result = await <any>commands.executeCommand(Commands.EXECUTE_WORKSPACE_COMMAND, Commands.REMOVE_FROM_SOURCEPATH, uri.toString());
3434
if (result.status) {
3535
window.showInformationMessage(result.message ? result.message : 'Successfully removed the folder from the source path.');
3636
} else {
3737
window.showErrorMessage(result.message);
3838
}
39-
});
39+
}));
4040

41-
commands.registerCommand(Commands.LIST_SOURCEPATHS, async() => {
41+
context.subscriptions.push(commands.registerCommand(Commands.LIST_SOURCEPATHS, async() => {
4242
const result: ListCommandResult = await commands.executeCommand<ListCommandResult>(Commands.EXECUTE_WORKSPACE_COMMAND, Commands.LIST_SOURCEPATHS);
4343
if (result.status) {
4444
if (!result.data || !result.data.length) {
@@ -54,5 +54,5 @@ export function registerCommands() {
5454
} else {
5555
window.showErrorMessage(result.message);
5656
}
57-
});
57+
}));
5858
}

src/extension.ts

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -190,39 +190,39 @@ export function activate(context: ExtensionContext): Promise<ExtensionAPI> {
190190
return commands.executeCommand(params.command, ...params.arguments);
191191
});
192192

193-
commands.registerCommand(Commands.OPEN_OUTPUT, () => {
193+
context.subscriptions.push(commands.registerCommand(Commands.OPEN_OUTPUT, () => {
194194
languageClient.outputChannel.show(ViewColumn.Three);
195-
});
196-
commands.registerCommand(Commands.SHOW_JAVA_REFERENCES, (uri: string, position: LSPosition, locations: LSLocation[]) => {
195+
}));
196+
context.subscriptions.push(commands.registerCommand(Commands.SHOW_JAVA_REFERENCES, (uri: string, position: LSPosition, locations: LSLocation[]) => {
197197
commands.executeCommand(Commands.SHOW_REFERENCES, Uri.parse(uri), languageClient.protocol2CodeConverter.asPosition(position), locations.map(languageClient.protocol2CodeConverter.asLocation));
198-
});
199-
commands.registerCommand(Commands.SHOW_JAVA_IMPLEMENTATIONS, (uri: string, position: LSPosition, locations: LSLocation[]) => {
198+
}));
199+
context.subscriptions.push(commands.registerCommand(Commands.SHOW_JAVA_IMPLEMENTATIONS, (uri: string, position: LSPosition, locations: LSLocation[]) => {
200200
commands.executeCommand(Commands.SHOW_REFERENCES, Uri.parse(uri), languageClient.protocol2CodeConverter.asPosition(position), locations.map(languageClient.protocol2CodeConverter.asLocation));
201-
});
201+
}));
202202

203-
commands.registerCommand(Commands.CONFIGURATION_UPDATE, uri => projectConfigurationUpdate(languageClient, uri));
203+
context.subscriptions.push(commands.registerCommand(Commands.CONFIGURATION_UPDATE, uri => projectConfigurationUpdate(languageClient, uri)));
204204

205-
commands.registerCommand(Commands.IGNORE_INCOMPLETE_CLASSPATH, (data?: any) => setIncompleteClasspathSeverity('ignore'));
205+
context.subscriptions.push(commands.registerCommand(Commands.IGNORE_INCOMPLETE_CLASSPATH, (data?: any) => setIncompleteClasspathSeverity('ignore')));
206206

207-
commands.registerCommand(Commands.IGNORE_INCOMPLETE_CLASSPATH_HELP, (data?: any) => {
207+
context.subscriptions.push(commands.registerCommand(Commands.IGNORE_INCOMPLETE_CLASSPATH_HELP, (data?: any) => {
208208
commands.executeCommand(Commands.OPEN_BROWSER, Uri.parse('https://github.com/redhat-developer/vscode-java/wiki/%22Classpath-is-incomplete%22-warning'));
209-
});
209+
}));
210210

211-
commands.registerCommand(Commands.PROJECT_CONFIGURATION_STATUS, (uri, status) => setProjectConfigurationUpdate(languageClient, uri, status));
211+
context.subscriptions.push(commands.registerCommand(Commands.PROJECT_CONFIGURATION_STATUS, (uri, status) => setProjectConfigurationUpdate(languageClient, uri, status)));
212212

213-
commands.registerCommand(Commands.APPLY_WORKSPACE_EDIT, (obj) => {
213+
context.subscriptions.push(commands.registerCommand(Commands.APPLY_WORKSPACE_EDIT, (obj) => {
214214
applyWorkspaceEdit(obj, languageClient);
215-
});
215+
}));
216216

217-
commands.registerCommand(Commands.EXECUTE_WORKSPACE_COMMAND, (command, ...rest) => {
217+
context.subscriptions.push(commands.registerCommand(Commands.EXECUTE_WORKSPACE_COMMAND, (command, ...rest) => {
218218
const params: ExecuteCommandParams = {
219219
command,
220220
arguments: rest
221221
};
222222
return languageClient.sendRequest(ExecuteCommandRequest.type, params);
223-
});
223+
}));
224224

225-
commands.registerCommand(Commands.COMPILE_WORKSPACE, (isFullCompile : boolean) => {
225+
context.subscriptions.push(commands.registerCommand(Commands.COMPILE_WORKSPACE, (isFullCompile : boolean) => {
226226
return window.withProgress({ location: ProgressLocation.Window }, async p => {
227227
if (typeof isFullCompile !== 'boolean') {
228228
const selection = await window.showQuickPick(['Incremental', 'Full'], {'placeHolder' : 'please choose compile type:'});
@@ -243,9 +243,9 @@ export function activate(context: ExtensionContext): Promise<ExtensionAPI> {
243243
}, humanVisibleDelay);
244244
});
245245
});
246-
});
246+
}));
247247

248-
commands.registerCommand(Commands.UPDATE_SOURCE_ATTACHMENT, async (classFileUri: Uri): Promise<boolean> => {
248+
context.subscriptions.push(commands.registerCommand(Commands.UPDATE_SOURCE_ATTACHMENT, async (classFileUri: Uri): Promise<boolean> => {
249249
const resolveRequest: SourceAttachmentRequest = {
250250
classFileUri: classFileUri.toString(),
251251
};
@@ -286,14 +286,14 @@ export function activate(context: ExtensionContext): Promise<ExtensionAPI> {
286286
jdtEventEmitter.fire(classFileUri);
287287
return true;
288288
}
289-
});
289+
}));
290290

291-
buildpath.registerCommands();
292-
sourceAction.registerCommands(languageClient);
291+
buildpath.registerCommands(context);
292+
sourceAction.registerCommands(languageClient, context);
293293

294-
window.onDidChangeActiveTextEditor((editor) => {
294+
context.subscriptions.push(window.onDidChangeActiveTextEditor((editor) => {
295295
toggleItem(editor, item);
296-
});
296+
}));
297297

298298
let provider: TextDocumentContentProvider = <TextDocumentContentProvider>{
299299
onDidChange: jdtEventEmitter.event,
@@ -303,7 +303,7 @@ export function activate(context: ExtensionContext): Promise<ExtensionAPI> {
303303
});
304304
}
305305
};
306-
workspace.registerTextDocumentContentProvider('jdt', provider);
306+
context.subscriptions.push(workspace.registerTextDocumentContentProvider('jdt', provider));
307307
excludeProjectSettingsFiles();
308308
});
309309

@@ -318,12 +318,12 @@ export function activate(context: ExtensionContext): Promise<ExtensionAPI> {
318318

319319
languageClient.start();
320320
// Register commands here to make it available even when the language client fails
321-
commands.registerCommand(Commands.OPEN_SERVER_LOG, () => openServerLogFile(workspacePath));
321+
context.subscriptions.push(commands.registerCommand(Commands.OPEN_SERVER_LOG, () => openServerLogFile(workspacePath)));
322322

323323
let extensionPath = context.extensionPath;
324-
commands.registerCommand(Commands.OPEN_FORMATTER, async () => openFormatter(extensionPath));
324+
context.subscriptions.push(commands.registerCommand(Commands.OPEN_FORMATTER, async () => openFormatter(extensionPath)));
325325

326-
commands.registerCommand(Commands.CLEAN_WORKSPACE, () => cleanWorkspace(workspacePath));
326+
context.subscriptions.push(commands.registerCommand(Commands.CLEAN_WORKSPACE, () => cleanWorkspace(workspacePath)));
327327

328328
context.subscriptions.push(onConfigurationChange());
329329
toggleItem(window.activeTextEditor, item);

src/sourceAction.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
'use strict';
22

3-
import { commands, window } from 'vscode';
3+
import { commands, window, ExtensionContext } from 'vscode';
44
import { CodeActionParams, LanguageClient } from 'vscode-languageclient';
55
import { Commands } from './commands';
66
import { applyWorkspaceEdit } from './extension';
77
import { ListOverridableMethodsRequest, AddOverridableMethodsRequest, CheckHashCodeEqualsStatusRequest, GenerateHashCodeEqualsRequest } from './protocol';
88

9-
export function registerCommands(languageClient: LanguageClient) {
10-
registerOverrideMethodsCommand(languageClient);
11-
registerHashCodeEqualsCommand(languageClient);
9+
export function registerCommands(languageClient: LanguageClient, context: ExtensionContext) {
10+
registerOverrideMethodsCommand(languageClient, context);
11+
registerHashCodeEqualsCommand(languageClient, context);
1212
}
1313

14-
function registerOverrideMethodsCommand(languageClient: LanguageClient): void {
15-
commands.registerCommand(Commands.OVERRIDE_METHODS_PROMPT, async (params: CodeActionParams) => {
14+
function registerOverrideMethodsCommand(languageClient: LanguageClient, context: ExtensionContext): void {
15+
context.subscriptions.push(commands.registerCommand(Commands.OVERRIDE_METHODS_PROMPT, async (params: CodeActionParams) => {
1616
const result = await languageClient.sendRequest(ListOverridableMethodsRequest.type, params);
1717
if (!result || !result.methods || !result.methods.length) {
1818
window.showWarningMessage('No overridable methods found in the super type.');
@@ -55,11 +55,11 @@ function registerOverrideMethodsCommand(languageClient: LanguageClient): void {
5555
overridableMethods: selectedItems.map((item) => item.originalMethod),
5656
});
5757
applyWorkspaceEdit(workspaceEdit, languageClient);
58-
});
58+
}));
5959
}
6060

61-
function registerHashCodeEqualsCommand(languageClient: LanguageClient): void {
62-
commands.registerCommand(Commands.HASHCODE_EQUALS_PROMPT, async (params: CodeActionParams) => {
61+
function registerHashCodeEqualsCommand(languageClient: LanguageClient, context: ExtensionContext): void {
62+
context.subscriptions.push(commands.registerCommand(Commands.HASHCODE_EQUALS_PROMPT, async (params: CodeActionParams) => {
6363
const result = await languageClient.sendRequest(CheckHashCodeEqualsStatusRequest.type, params);
6464
if (!result || !result.fields || !result.fields.length) {
6565
window.showErrorMessage(`The operation is not applicable to the type ${result.type}.`);
@@ -98,5 +98,5 @@ function registerHashCodeEqualsCommand(languageClient: LanguageClient): void {
9898
regenerate
9999
});
100100
applyWorkspaceEdit(workspaceEdit, languageClient);
101-
});
102-
}
101+
}));
102+
}

0 commit comments

Comments
 (0)