Use ctx.subscriptions to manage disposables (#1326)

* Use ctx.subscriptions to manage disposables

* Remove deactivateInternal
This commit is contained in:
Brandon Waterloo [MSFT] 2019-10-08 13:13:28 -04:00 коммит произвёл GitHub
Родитель 582a849848
Коммит 113b97f5d6
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 11 добавлений и 28 удалений

Просмотреть файл

@ -9,8 +9,8 @@
* everything else will be in private modules in extension.bundle.js.
*/
// Export activate/deactivate for main.js
export { activateInternal, deactivateInternal } from './src/extension';
// Export activate for main.js
export { activateInternal } from './src/extension';
// Exports for tests
// The tests are not packaged with the webpack bundle and therefore only have access to code exported from this file.

Просмотреть файл

@ -25,7 +25,7 @@ async function activate(ctx) {
}
async function deactivate(ctx) {
return await extension.deactivateInternal();
// No-op
}
exports.activate = activate;

Просмотреть файл

@ -127,7 +127,7 @@ export async function activateInternal(ctx: vscode.ExtensionContext, perfStats:
refreshDockerode();
await consolidateDefaultRegistrySettings();
activateLanguageClient();
activateLanguageClient(ctx);
});
}
@ -185,18 +185,7 @@ async function setRequestDefaults(): Promise<void> {
ext.request = requestWithDefaults;
}
export async function deactivateInternal(): Promise<void> {
if (!client) {
return undefined;
}
// perform cleanup
Configuration.dispose();
return await client.stop();
}
namespace Configuration {
let configurationListener: vscode.Disposable;
export function computeConfiguration(params: ConfigurationParams): vscode.WorkspaceConfiguration[] {
let result: vscode.WorkspaceConfiguration[] = [];
for (let item of params.items) {
@ -215,8 +204,8 @@ namespace Configuration {
return result;
}
export function initialize(): void {
configurationListener = vscode.workspace.onDidChangeConfiguration(
export function initialize(ctx: vscode.ExtensionContext): void {
ctx.subscriptions.push(vscode.workspace.onDidChangeConfiguration(
async (e: vscode.ConfigurationChangeEvent) => {
// notify the language server that settings have change
client.sendNotification(DidChangeConfigurationNotification.type, {
@ -237,18 +226,11 @@ namespace Configuration {
setRequestDefaults();
}
}
);
}
export function dispose(): void {
if (configurationListener) {
// remove this listener when disposed
configurationListener.dispose();
}
));
}
}
function activateLanguageClient(): void {
function activateLanguageClient(ctx: vscode.ExtensionContext): void {
// Don't wait
callWithTelemetryAndErrorHandling('docker.languageclient.activate', async (context: IActionContext) => {
context.telemetry.properties.isActivationEvent = 'true';
@ -300,9 +282,10 @@ function activateLanguageClient(): void {
// tslint:disable-next-line:no-floating-promises
client.onReady().then(() => {
// attach the VS Code settings listener
Configuration.initialize();
Configuration.initialize(ctx);
});
client.start();
ctx.subscriptions.push(client.start());
});
}