Skip to content

Commit 6a44a0b

Browse files
author
Kartik Raj
committed
Corrected configSettings bug
1 parent 761d674 commit 6a44a0b

File tree

6 files changed

+17
-21
lines changed

6 files changed

+17
-21
lines changed

src/client/activation/languageServer/analysisOptions.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import { inject, injectable, named } from 'inversify';
77
import * as path from 'path';
8-
import { CancellationToken, CompletionContext, ConfigurationChangeEvent, Disposable, DocumentFilter, Event, EventEmitter, OutputChannel, Position, TextDocument } from 'vscode';
8+
import { CancellationToken, CompletionContext, ConfigurationChangeEvent, Disposable, Event, EventEmitter, OutputChannel, Position, TextDocument } from 'vscode';
99
import { LanguageClientOptions, ProvideCompletionItemsSignature } from 'vscode-languageclient';
1010
import { IWorkspaceService } from '../../common/application/types';
1111
import { isTestExecution, PYTHON_LANGUAGE, STANDARD_OUTPUT_CHANNEL } from '../../common/constants';

src/client/activation/languageServer/manager.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export class LanguageServerExtension implements ILanguageServerExtension {
8686
this.disposable.dispose();
8787
}
8888
}
89-
public async register(): Promise<void> {
89+
public register(): Promise<void> {
9090
if (this.disposable) {
9191
return;
9292
}

src/client/activation/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export const ILanguageServerExtension = Symbol('ILanguageServerExtension');
9292
export interface ILanguageServerExtension extends IDisposable {
9393
readonly invoked: Event<void>;
9494
loadExtensionArgs?: {};
95-
register(): Promise<void>;
95+
register(): void;
9696
}
9797
export const ILanguageServer = Symbol('ILanguageServer');
9898
export interface ILanguageServer extends IDisposable {

src/client/common/configSettings.ts

+10
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,15 @@ export class PythonSettings implements IPythonSettings {
373373
protected getPythonExecutable(pythonPath: string) {
374374
return getPythonExecutable(pythonPath);
375375
}
376+
protected onWorkspaceFoldersChanged() {
377+
//If an activated workspace folder was removed, delete its key
378+
const workspaceKeys = this.workspace.workspaceFolders!.map(workspaceFolder => workspaceFolder.uri.fsPath);
379+
const activatedWkspcKeys = Array.from(PythonSettings.pythonSettings.keys());
380+
const activatedWkspcFoldersRemoved = activatedWkspcKeys.filter(x => workspaceKeys.indexOf(x) < 0);
381+
if (activatedWkspcFoldersRemoved.length > 0) {
382+
PythonSettings.pythonSettings.delete(activatedWkspcFoldersRemoved[0]);
383+
}
384+
}
376385
protected initialize(): void {
377386
const onDidChange = () => {
378387
const currentConfig = this.workspace.getConfiguration('python', this.workspaceRoot);
@@ -382,6 +391,7 @@ export class PythonSettings implements IPythonSettings {
382391
// Let's defer the change notification.
383392
this.debounceChangeNotification();
384393
};
394+
this.disposables.push(this.workspace.onDidChangeWorkspaceFolders(this.onWorkspaceFoldersChanged, this));
385395
this.disposables.push(this.interpreterAutoSelectionService.onDidChangeAutoSelectedInterpreter(onDidChange.bind(this)));
386396
this.disposables.push(this.workspace.onDidChangeConfiguration((event: ConfigurationChangeEvent) => {
387397
if (event.affectsConfiguration('python')) {

src/test/activation/activationManager.unit.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ suite('Activation - ActivationManager', () => {
174174

175175
documentManager.verifyAll();
176176
verify(workspaceService.onDidChangeWorkspaceFolders).once();
177-
verify(workspaceService.workspaceFolders).once();
177+
verify(workspaceService.workspaceFolders).atLeast(1);
178178
verify(workspaceService.hasWorkspaceFolders).once();
179179
verify(workspaceService.getWorkspaceFolder(anything())).atLeast(1);
180180
verify(activationService1.activate(resource)).once();
@@ -230,7 +230,7 @@ suite('Activation - ActivationManager', () => {
230230

231231
documentManager.verifyAll();
232232
verify(workspaceService.onDidChangeWorkspaceFolders).once();
233-
verify(workspaceService.workspaceFolders).once();
233+
verify(workspaceService.workspaceFolders).atLeast(1);
234234
verify(workspaceService.hasWorkspaceFolders).once();
235235

236236
//Removed no. of folders to one
@@ -240,7 +240,7 @@ suite('Activation - ActivationManager', () => {
240240

241241
workspaceFoldersChangedHandler.call(managerTest);
242242

243-
verify(workspaceService.workspaceFolders).twice();
243+
verify(workspaceService.workspaceFolders).atLeast(1);
244244
verify(workspaceService.hasWorkspaceFolders).twice();
245245
});
246246
});

src/test/activation/languageServer/manager.unit.test.ts

+1-15
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ suite('xLanguage Server - Manager', () => {
8989
verify(analysisOptions.getAnalysisOptions()).once();
9090
verify(serviceContainer.get<ILanguageServer>(ILanguageServer)).once();
9191
verify(languageServer.start(resource, languageClientOptions)).once();
92+
expect(invoked).to.be.true;
9293
expect(analysisHandlerRegistered).to.be.true;
9394
verify(languageServer.dispose()).never();
9495
}
@@ -176,21 +177,6 @@ suite('xLanguage Server - Manager', () => {
176177
verify(serviceContainer.get<ILanguageServer>(ILanguageServer)).thrice();
177178
verify(languageServer.start(resource, languageClientOptions)).thrice();
178179
});
179-
// Write system test to test this
180-
// test('Must load extension when command is sent', async () => {
181-
// const args = { x: 1 };
182-
// when(lsExtension.loadExtensionArgs).thenReturn(undefined);
183-
// await startLanguageServer();
184-
185-
// verify(languageServer.loadExtension(args)).never();
186-
187-
// await extension.register();
188-
// const cb = capture(commandManager.registerCommand).first()[1] as Function;
189-
// cb.call(manager, args);
190-
191-
// verify(languageServer.loadExtension(args)).once();
192-
// commandRegistrationDisposable.verify(d => d.dispose(), typemoq.Times.never());
193-
// });
194180
test('Must load extension when command was been sent before starting LS', async () => {
195181
const args = { x: 1 };
196182
when(lsExtension.loadExtensionArgs).thenReturn(args as any);

0 commit comments

Comments
 (0)