diff --git a/src/client/activation/common/outputChannel.ts b/src/client/activation/common/outputChannel.ts index 60a99687793e..c11437dd0114 100644 --- a/src/client/activation/common/outputChannel.ts +++ b/src/client/activation/common/outputChannel.ts @@ -13,21 +13,21 @@ import { ILanguageServerOutputChannel } from '../types'; @injectable() export class LanguageServerOutputChannel implements ILanguageServerOutputChannel { public output: ILogOutputChannel | undefined; - private registered = false; constructor( @inject(IApplicationShell) private readonly appShell: IApplicationShell, @inject(ICommandManager) private readonly commandManager: ICommandManager, - @inject(IDisposableRegistry) private readonly disposable: IDisposableRegistry, + @inject(IDisposableRegistry) private readonly disposables: IDisposableRegistry, ) {} public get channel(): ILogOutputChannel { if (!this.output) { - this.output = this.appShell.createOutputChannel(OutputChannelNames.languageServer); - this.disposable.push(this.output); + this.output = this.appShell.createOutputChannel(OutputChannelNames.LanguageServer); + this.disposables.push(this.output); this.registerCommand().ignoreErrors(); } + return this.output; } @@ -39,10 +39,10 @@ export class LanguageServerOutputChannel implements ILanguageServerOutputChannel // This controls the visibility of the command used to display the LS Output panel. // We don't want to display it when Jedi is used instead of LS. await this.commandManager.executeCommand('setContext', 'python.hasLanguageServerOutputChannel', true); - this.disposable.push( + this.disposables.push( this.commandManager.registerCommand('python.viewLanguageServerOutput', () => this.output?.show(true)), ); - this.disposable.push({ + this.disposables.push({ dispose: () => { this.registered = false; }, diff --git a/src/client/activation/node/languageServerProxy.ts b/src/client/activation/node/languageServerProxy.ts index 45d1d1a17fee..d82d0a58802a 100644 --- a/src/client/activation/node/languageServerProxy.ts +++ b/src/client/activation/node/languageServerProxy.ts @@ -98,8 +98,10 @@ export class NodeLanguageServerProxy implements ILanguageServerProxy { const api = extension?.exports; if (api && api.client && api.client.isEnabled()) { - this.pylanceApi = api; - await api.client.start(); + if (!api.client.supportsSelfManagedLifecycle) { + this.pylanceApi = api; + await api.client.start(); + } return; } @@ -151,6 +153,15 @@ export class NodeLanguageServerProxy implements ILanguageServerProxy { } } + public async restartSelfManagedClient(): Promise { + const api = (await this.getPylanceExtension())?.exports; + if (api?.client?.supportsSelfManagedLifecycle && api.client.restart) { + await api.client.restart(); + return true; + } + return false; + } + // eslint-disable-next-line class-methods-use-this public loadExtension(): void { // No body. diff --git a/src/client/activation/node/manager.ts b/src/client/activation/node/manager.ts index 5a66e4abecd0..ac04bc558d7d 100644 --- a/src/client/activation/node/manager.ts +++ b/src/client/activation/node/manager.ts @@ -102,6 +102,9 @@ export class NodeLanguageServerManager implements ILanguageServerManager { @traceDecoratorError('Failed to restart language server') @traceDecoratorVerbose('Restarting language server') protected async restartLanguageServer(): Promise { + if (await this.languageServerProxy.restartSelfManagedClient()) { + return; + } await this.stopLanguageServer(); await this.startLanguageServer(); } diff --git a/src/client/activation/node/pylanceApi.ts b/src/client/activation/node/pylanceApi.ts index 4b3d21d7527e..4eaa9012009a 100644 --- a/src/client/activation/node/pylanceApi.ts +++ b/src/client/activation/node/pylanceApi.ts @@ -12,9 +12,11 @@ import { export interface PylanceApi { client?: { + readonly supportsSelfManagedLifecycle?: boolean; isEnabled(): boolean; start(): Promise; stop(): Promise; + restart?(): Promise; }; notebook?: { registerJupyterPythonPathFunction(func: (uri: Uri) => Promise): void; diff --git a/src/client/api.ts b/src/client/api.ts index 908da4be7103..e20999f85f85 100644 --- a/src/client/api.ts +++ b/src/client/api.ts @@ -145,12 +145,10 @@ export function buildApi( }, }, pylance: { + supportsSelfManagedPylance: true, createClient: (...args: any[]): BaseLanguageClient => { - // Make sure we share output channel so that we can share one with - // Jedi as well. const clientOptions = args[1] as LanguageClientOptions; clientOptions.outputChannel = clientOptions.outputChannel ?? outputChannel.channel; - return new LanguageClient(PYTHON_LANGUAGE, PYLANCE_NAME, args[0], clientOptions); }, start: (client: BaseLanguageClient): Promise => client.start(), diff --git a/src/client/browser/api.ts b/src/client/browser/api.ts index ac2df8d0ffed..955523be6eef 100644 --- a/src/client/browser/api.ts +++ b/src/client/browser/api.ts @@ -19,6 +19,7 @@ export interface IBrowserExtensionApi { export function buildApi(reporter: TelemetryReporter): IBrowserExtensionApi { const api: IBrowserExtensionApi = { pylance: { + supportsSelfManagedPylance: true, // eslint-disable-next-line @typescript-eslint/no-explicit-any createClient: (...args: any[]): BaseLanguageClient => new LanguageClient(PYTHON_LANGUAGE, 'Python Language Server', args[0], args[1]), diff --git a/src/client/browser/extension.ts b/src/client/browser/extension.ts index 76a608837b10..ee8e4622edee 100644 --- a/src/client/browser/extension.ts +++ b/src/client/browser/extension.ts @@ -67,8 +67,10 @@ async function runPylance( pylanceExtension = await getActivatedExtension(pylanceExtension); const api = pylanceExtension.exports; if (api.client && api.client.isEnabled()) { - pylanceApi = api; - await api.client.start(); + if (!api.client.supportsSelfManagedLifecycle) { + pylanceApi = api; + await api.client.start(); + } return; } diff --git a/src/client/common/utils/localize.ts b/src/client/common/utils/localize.ts index 178e7f263761..06415c155ba5 100644 --- a/src/client/common/utils/localize.ts +++ b/src/client/common/utils/localize.ts @@ -279,7 +279,7 @@ export namespace InterpreterQuickPickList { } export namespace OutputChannelNames { - export const languageServer = l10n.t('Python Language Server'); + export const LanguageServer = l10n.t('Python Language Server'); export const python = l10n.t('Python'); } diff --git a/src/client/languageServer/jediLSExtensionManager.ts b/src/client/languageServer/jediLSExtensionManager.ts index 4cbfb6f33466..5f6430680fce 100644 --- a/src/client/languageServer/jediLSExtensionManager.ts +++ b/src/client/languageServer/jediLSExtensionManager.ts @@ -32,7 +32,6 @@ export class JediLSExtensionManager implements IDisposable, ILanguageServerExten constructor( serviceContainer: IServiceContainer, - outputChannel: ILanguageServerOutputChannel, _experimentService: IExperimentService, workspaceService: IWorkspaceService, configurationService: IConfigurationService, @@ -41,6 +40,7 @@ export class JediLSExtensionManager implements IDisposable, ILanguageServerExten environmentService: IEnvironmentVariablesProvider, commandManager: ICommandManager, ) { + const outputChannel = serviceContainer.get(ILanguageServerOutputChannel); this.analysisOptions = new JediLanguageServerAnalysisOptions( environmentService, outputChannel, diff --git a/src/client/languageServer/watcher.ts b/src/client/languageServer/watcher.ts index 39e6e0bb1ece..2c62d0751fec 100644 --- a/src/client/languageServer/watcher.ts +++ b/src/client/languageServer/watcher.ts @@ -5,9 +5,10 @@ import * as path from 'path'; import { inject, injectable } from 'inversify'; import { ConfigurationChangeEvent, l10n, Uri, WorkspaceFoldersChangeEvent } from 'vscode'; import { LanguageServerChangeHandler } from '../activation/common/languageServerChangeHandler'; -import { IExtensionActivationService, ILanguageServerOutputChannel, LanguageServerType } from '../activation/types'; +import { IExtensionActivationService, LanguageServerType } from '../activation/types'; import { IApplicationShell, ICommandManager, IWorkspaceService } from '../common/application/types'; import { IFileSystem } from '../common/platform/types'; + import { IConfigurationService, IDisposableRegistry, @@ -30,6 +31,7 @@ import { ILanguageServerExtensionManager, ILanguageServerWatcher } from './types import { sendTelemetryEvent } from '../telemetry'; import { EventName } from '../telemetry/constants'; import { StopWatch } from '../common/utils/stopWatch'; +import { ILanguageServerOutputChannel } from '../activation/types'; @injectable() /** @@ -53,7 +55,6 @@ export class LanguageServerWatcher implements IExtensionActivationService, ILang constructor( @inject(IServiceContainer) private readonly serviceContainer: IServiceContainer, - @inject(ILanguageServerOutputChannel) private readonly lsOutputChannel: ILanguageServerOutputChannel, @inject(IConfigurationService) private readonly configurationService: IConfigurationService, @inject(IExperimentService) private readonly experimentService: IExperimentService, @inject(IInterpreterHelper) private readonly interpreterHelper: IInterpreterHelper, @@ -62,7 +63,6 @@ export class LanguageServerWatcher implements IExtensionActivationService, ILang @inject(IEnvironmentVariablesProvider) private readonly environmentService: IEnvironmentVariablesProvider, @inject(IWorkspaceService) private readonly workspaceService: IWorkspaceService, @inject(ICommandManager) private readonly commandManager: ICommandManager, - @inject(IFileSystem) private readonly fileSystem: IFileSystem, @inject(IExtensions) private readonly extensions: IExtensions, @inject(IApplicationShell) readonly applicationShell: IApplicationShell, @inject(IDisposableRegistry) readonly disposables: IDisposableRegistry, @@ -233,7 +233,6 @@ export class LanguageServerWatcher implements IExtensionActivationService, ILang case LanguageServerType.Jedi: lsManager = new JediLSExtensionManager( this.serviceContainer, - this.lsOutputChannel, this.experimentService, this.workspaceService, this.configurationService, @@ -246,7 +245,7 @@ export class LanguageServerWatcher implements IExtensionActivationService, ILang case LanguageServerType.Node: lsManager = new PylanceLSExtensionManager( this.serviceContainer, - this.lsOutputChannel, + this.serviceContainer.get(ILanguageServerOutputChannel), this.experimentService, this.workspaceService, this.configurationService, @@ -254,7 +253,7 @@ export class LanguageServerWatcher implements IExtensionActivationService, ILang this.interpreterService, this.environmentService, this.commandManager, - this.fileSystem, + this.serviceContainer.get(IFileSystem), this.extensions, this.applicationShell, ); diff --git a/src/client/pylanceApi.ts b/src/client/pylanceApi.ts index b839d0d9c2b7..d206b0bc31a3 100644 --- a/src/client/pylanceApi.ts +++ b/src/client/pylanceApi.ts @@ -18,6 +18,7 @@ export interface TelemetryReporter { } export interface ApiForPylance { + readonly supportsSelfManagedPylance: true; // eslint-disable-next-line @typescript-eslint/no-explicit-any createClient(...args: any[]): BaseLanguageClient; start(client: BaseLanguageClient): Promise; diff --git a/src/test/activation/outputChannel.unit.test.ts b/src/test/activation/outputChannel.unit.test.ts index f8f38783bb0e..0954b181e4ac 100644 --- a/src/test/activation/outputChannel.unit.test.ts +++ b/src/test/activation/outputChannel.unit.test.ts @@ -25,7 +25,7 @@ suite('Language Server Output Channel', () => { test('Create output channel if one does not exist before and return it', async () => { appShell - .setup((a) => a.createOutputChannel(OutputChannelNames.languageServer)) + .setup((a) => a.createOutputChannel(OutputChannelNames.LanguageServer)) .returns(() => output.object) .verifiable(TypeMoq.Times.once()); const { channel } = languageServerOutputChannel; diff --git a/src/test/activation/serviceRegistry.unit.test.ts b/src/test/activation/serviceRegistry.unit.test.ts index 177eae810810..9e73bbc89302 100644 --- a/src/test/activation/serviceRegistry.unit.test.ts +++ b/src/test/activation/serviceRegistry.unit.test.ts @@ -4,13 +4,8 @@ import { instance, mock, verify } from 'ts-mockito'; import { ExtensionActivationManager } from '../../client/activation/activationManager'; import { ExtensionSurveyPrompt } from '../../client/activation/extensionSurvey'; -import { LanguageServerOutputChannel } from '../../client/activation/common/outputChannel'; import { registerTypes } from '../../client/activation/serviceRegistry'; -import { - IExtensionActivationManager, - IExtensionSingleActivationService, - ILanguageServerOutputChannel, -} from '../../client/activation/types'; +import { IExtensionActivationManager, IExtensionSingleActivationService } from '../../client/activation/types'; import { ServiceManager } from '../../client/ioc/serviceManager'; import { IServiceManager } from '../../client/ioc/types'; import { LoadLanguageServerExtension } from '../../client/activation/common/loadLanguageServerExtension'; @@ -29,12 +24,6 @@ suite('Unit Tests - Language Server Activation Service Registry', () => { verify( serviceManager.add(IExtensionActivationManager, ExtensionActivationManager), ).once(); - verify( - serviceManager.addSingleton( - ILanguageServerOutputChannel, - LanguageServerOutputChannel, - ), - ).once(); verify( serviceManager.addSingleton( IExtensionSingleActivationService, diff --git a/src/test/languageServer/jediLSExtensionManager.unit.test.ts b/src/test/languageServer/jediLSExtensionManager.unit.test.ts index b57a0bbd096d..559b6db7ca5c 100644 --- a/src/test/languageServer/jediLSExtensionManager.unit.test.ts +++ b/src/test/languageServer/jediLSExtensionManager.unit.test.ts @@ -2,9 +2,15 @@ // Licensed under the MIT License. import * as assert from 'assert'; + import { ILanguageServerOutputChannel } from '../../client/activation/types'; import { IWorkspaceService, ICommandManager } from '../../client/common/application/types'; -import { IExperimentService, IConfigurationService, IInterpreterPathService } from '../../client/common/types'; +import { + IExperimentService, + IConfigurationService, + IInterpreterPathService, + ILogOutputChannel, +} from '../../client/common/types'; import { IEnvironmentVariablesProvider } from '../../client/common/variables/types'; import { IInterpreterService } from '../../client/interpreter/contracts'; import { IServiceContainer } from '../../client/ioc/types'; @@ -15,9 +21,21 @@ suite('Language Server - Jedi LS extension manager', () => { let manager: JediLSExtensionManager; setup(() => { + // Create a mock ILogOutputChannel + const mockOutputChannel = {} as ILogOutputChannel; + + // Create a mock service container with the required get method + const mockServiceContainer = { + get: (serviceIdentifier: any) => { + if (serviceIdentifier === ILanguageServerOutputChannel) { + return { channel: mockOutputChannel }; + } + return undefined; + }, + } as IServiceContainer; + manager = new JediLSExtensionManager( - {} as IServiceContainer, - {} as ILanguageServerOutputChannel, + mockServiceContainer, {} as IExperimentService, {} as IWorkspaceService, {} as IConfigurationService, diff --git a/src/test/languageServer/pylanceLSExtensionManager.unit.test.ts b/src/test/languageServer/pylanceLSExtensionManager.unit.test.ts index 751b26d37d3c..b10e30f6c77b 100644 --- a/src/test/languageServer/pylanceLSExtensionManager.unit.test.ts +++ b/src/test/languageServer/pylanceLSExtensionManager.unit.test.ts @@ -2,6 +2,10 @@ // Licensed under the MIT License. import * as assert from 'assert'; +import * as sinon from 'sinon'; +import { LanguageClientOptions } from 'vscode-languageclient/node'; +import { NodeLanguageServerProxy } from '../../client/activation/node/languageServerProxy'; +import { ILanguageClientFactory } from '../../client/activation/types'; import { ILanguageServerOutputChannel } from '../../client/activation/types'; import { IWorkspaceService, ICommandManager, IApplicationShell } from '../../client/common/application/types'; import { IFileSystem } from '../../client/common/platform/types'; @@ -40,6 +44,47 @@ suite('Language Server - Pylance LS extension manager', () => { ); }); + suite('Language Server - Pylance lifecycle compatibility', () => { + for (const selfManaged of [false, true]) { + test(`Python ${selfManaged ? 'delegates' : 'manages'} the Pylance client lifecycle`, async () => { + const start = sinon.stub().resolves(); + const stop = sinon.stub().resolves(); + const restart = sinon.stub().resolves(); + const createLanguageClient = sinon.stub(); + const proxy = new NodeLanguageServerProxy( + ({ createLanguageClient } as unknown) as ILanguageClientFactory, + {} as IExperimentService, + {} as IInterpreterPathService, + {} as IEnvironmentVariablesProvider, + {} as IWorkspaceService, + ({ + getExtension: () => ({ + isActive: true, + packageJSON: { version: '1.0.0' }, + exports: { + client: { + supportsSelfManagedLifecycle: selfManaged, + isEnabled: () => true, + start, + stop, + restart, + }, + }, + }), + } as unknown) as IExtensions, + ); + + await proxy.start(undefined, undefined, {} as LanguageClientOptions); + assert.strictEqual(start.callCount, selfManaged ? 0 : 1); + assert.strictEqual(createLanguageClient.callCount, 0); + assert.strictEqual(await proxy.restartSelfManagedClient(), selfManaged); + assert.strictEqual(restart.callCount, selfManaged ? 1 : 0); + await proxy.stop(); + assert.strictEqual(stop.callCount, selfManaged ? 0 : 1); + }); + } + }); + test('Constructor should create a client proxy, a server manager and a server proxy', () => { assert.notStrictEqual(manager.clientFactory, undefined); assert.notStrictEqual(manager.serverManager, undefined); diff --git a/src/test/languageServer/watcher.unit.test.ts b/src/test/languageServer/watcher.unit.test.ts index e86e19cf2055..685e5ebce98e 100644 --- a/src/test/languageServer/watcher.unit.test.ts +++ b/src/test/languageServer/watcher.unit.test.ts @@ -5,16 +5,16 @@ import * as assert from 'assert'; import * as sinon from 'sinon'; import { ConfigurationChangeEvent, Uri, WorkspaceFolder, WorkspaceFoldersChangeEvent } from 'vscode'; import { JediLanguageServerManager } from '../../client/activation/jedi/manager'; -import { NodeLanguageServerManager } from '../../client/activation/node/manager'; + import { ILanguageServerOutputChannel, LanguageServerType } from '../../client/activation/types'; import { IApplicationShell, ICommandManager, IWorkspaceService } from '../../client/common/application/types'; -import { IFileSystem } from '../../client/common/platform/types'; import { IConfigurationService, IDisposable, IExperimentService, IExtensions, IInterpreterPathService, + ILogOutputChannel, } from '../../client/common/types'; import { LanguageService } from '../../client/common/utils/localize'; import { IEnvironmentVariablesProvider } from '../../client/common/variables/types'; @@ -23,11 +23,42 @@ import { IServiceContainer } from '../../client/ioc/types'; import { JediLSExtensionManager } from '../../client/languageServer/jediLSExtensionManager'; import { NoneLSExtensionManager } from '../../client/languageServer/noneLSExtensionManager'; import { PylanceLSExtensionManager } from '../../client/languageServer/pylanceLSExtensionManager'; +import { NodeLanguageServerManager } from '../../client/activation/node/manager'; + import { ILanguageServerExtensionManager } from '../../client/languageServer/types'; import { LanguageServerWatcher } from '../../client/languageServer/watcher'; import * as Logging from '../../client/logging'; import { PythonEnvironment } from '../../client/pythonEnvironments/info'; +function makeMockServiceContainer(outputChannel?: ILogOutputChannel): IServiceContainer { + const mockOutputChannel = + outputChannel || + ({ + dispose: () => { + /* do nothing */ + }, + } as ILogOutputChannel); + + const mockApplicationShell = ({ + createOutputChannel: () => mockOutputChannel, + } as unknown) as IApplicationShell; + + // Only handles IApplicationShell for these tests; extend if needed. + const mockServiceContainer = ({ + get: (serviceIdentifier: unknown) => { + if (serviceIdentifier === IApplicationShell) { + return mockApplicationShell; + } + if (serviceIdentifier === ILanguageServerOutputChannel) { + return { channel: mockOutputChannel }; + } + return undefined; + }, + } as unknown) as IServiceContainer; + + return mockServiceContainer; +} + suite('Language server watcher', () => { let watcher: LanguageServerWatcher; let disposables: IDisposable[]; @@ -35,9 +66,9 @@ suite('Language server watcher', () => { setup(() => { disposables = []; + watcher = new LanguageServerWatcher( - {} as IServiceContainer, - {} as ILanguageServerOutputChannel, + makeMockServiceContainer(), { getSettings: () => ({ languageServer: LanguageServerType.None }), } as IConfigurationService, @@ -71,7 +102,7 @@ suite('Language server watcher', () => { /* do nothing */ }, } as unknown) as ICommandManager, - {} as IFileSystem, + ({ getExtension: () => undefined, onDidChange: () => { @@ -91,8 +122,8 @@ suite('Language server watcher', () => { test('The constructor should add a listener to onDidChange to the list of disposables if it is a trusted workspace', () => { watcher = new LanguageServerWatcher( - {} as IServiceContainer, - {} as ILanguageServerOutputChannel, + makeMockServiceContainer(), + { getSettings: () => ({ languageServer: LanguageServerType.None }), } as IConfigurationService, @@ -120,7 +151,7 @@ suite('Language server watcher', () => { }, } as unknown) as IWorkspaceService, {} as ICommandManager, - {} as IFileSystem, + ({ getExtension: () => undefined, onDidChange: () => { @@ -136,8 +167,7 @@ suite('Language server watcher', () => { test('The constructor should not add a listener to onDidChange to the list of disposables if it is not a trusted workspace', () => { watcher = new LanguageServerWatcher( - {} as IServiceContainer, - {} as ILanguageServerOutputChannel, + makeMockServiceContainer(), { getSettings: () => ({ languageServer: LanguageServerType.None }), } as IConfigurationService, @@ -165,7 +195,7 @@ suite('Language server watcher', () => { }, } as unknown) as IWorkspaceService, {} as ICommandManager, - {} as IFileSystem, + ({ getExtension: () => undefined, onDidChange: () => { @@ -202,12 +232,7 @@ suite('Language server watcher', () => { } as unknown) as IInterpreterService; watcher = new LanguageServerWatcher( - ({ - get: () => { - /* do nothing */ - }, - } as unknown) as IServiceContainer, - {} as ILanguageServerOutputChannel, + makeMockServiceContainer(), { getSettings: () => ({ languageServer: LanguageServerType.None }), } as IConfigurationService, @@ -241,7 +266,7 @@ suite('Language server watcher', () => { /* do nothing */ }, } as unknown) as ICommandManager, - {} as IFileSystem, + ({ getExtension: () => undefined, onDidChange: () => { @@ -282,8 +307,8 @@ suite('Language server watcher', () => { }); watcher = new LanguageServerWatcher( - {} as IServiceContainer, - {} as ILanguageServerOutputChannel, + makeMockServiceContainer(), + { getSettings: () => ({ languageServer: LanguageServerType.None }), } as IConfigurationService, @@ -317,7 +342,7 @@ suite('Language server watcher', () => { /* do nothing */ }, } as unknown) as ICommandManager, - {} as IFileSystem, + ({ getExtension: () => undefined, onDidChange: () => { @@ -369,8 +394,8 @@ suite('Language server watcher', () => { } as unknown) as IWorkspaceService; watcher = new LanguageServerWatcher( - {} as IServiceContainer, - {} as ILanguageServerOutputChannel, + makeMockServiceContainer(), + { getSettings: () => ({ languageServer: LanguageServerType.None }), } as IConfigurationService, @@ -396,7 +421,7 @@ suite('Language server watcher', () => { /* do nothing */ }, } as unknown) as ICommandManager, - {} as IFileSystem, + ({ getExtension: () => undefined, onDidChange: () => { @@ -440,8 +465,8 @@ suite('Language server watcher', () => { } as unknown) as IConfigurationService; watcher = new LanguageServerWatcher( - {} as IServiceContainer, - {} as ILanguageServerOutputChannel, + makeMockServiceContainer(), + configService, {} as IExperimentService, ({ @@ -465,7 +490,7 @@ suite('Language server watcher', () => { /* do nothing */ }, } as unknown) as ICommandManager, - {} as IFileSystem, + ({ getExtension: () => undefined, onDidChange: () => { @@ -493,8 +518,8 @@ suite('Language server watcher', () => { startLanguageServerStub.returns(Promise.resolve()); watcher = new LanguageServerWatcher( - {} as IServiceContainer, - {} as ILanguageServerOutputChannel, + makeMockServiceContainer(), + { getSettings: () => ({ languageServer: LanguageServerType.Jedi }), } as IConfigurationService, @@ -528,7 +553,7 @@ suite('Language server watcher', () => { /* do nothing */ }, } as unknown) as ICommandManager, - {} as IFileSystem, + ({ getExtension: () => undefined, onDidChange: () => { @@ -551,8 +576,7 @@ suite('Language server watcher', () => { sandbox.stub(PylanceLSExtensionManager.prototype, 'canStartLanguageServer').returns(true); watcher = new LanguageServerWatcher( - {} as IServiceContainer, - {} as ILanguageServerOutputChannel, + makeMockServiceContainer(), { getSettings: () => ({ languageServer: LanguageServerType.Jedi, @@ -589,7 +613,6 @@ suite('Language server watcher', () => { /* do nothing */ }, } as unknown) as ICommandManager, - {} as IFileSystem, ({ getExtension: () => undefined, onDidChange: () => { @@ -613,8 +636,8 @@ suite('Language server watcher', () => { startLanguageServerStub.returns(Promise.resolve()); watcher = new LanguageServerWatcher( - {} as IServiceContainer, - {} as ILanguageServerOutputChannel, + makeMockServiceContainer(), + { getSettings: () => ({ languageServer: LanguageServerType.Jedi }), } as IConfigurationService, @@ -649,7 +672,7 @@ suite('Language server watcher', () => { /* do nothing */ }, } as unknown) as ICommandManager, - {} as IFileSystem, + ({ getExtension: () => undefined, onDidChange: () => { @@ -700,8 +723,7 @@ suite('Language server watcher', () => { sandbox.stub(extensionLSCls.prototype, 'canStartLanguageServer').returns(true); watcher = new LanguageServerWatcher( - {} as IServiceContainer, - {} as ILanguageServerOutputChannel, + makeMockServiceContainer(), { getSettings: () => ({ languageServer }), } as IConfigurationService, @@ -736,7 +758,7 @@ suite('Language server watcher', () => { /* do nothing */ }, } as unknown) as ICommandManager, - {} as IFileSystem, + ({ getExtension: () => undefined, onDidChange: () => { @@ -765,6 +787,7 @@ suite('Language server watcher', () => { multiLS ? '' : 'not' } be stopped if a workspace gets removed from the current project`, async () => { sandbox.stub(extensionLSCls.prototype, 'startLanguageServer').returns(Promise.resolve()); + sandbox.stub(extensionLSCls.prototype, 'canStartLanguageServer').returns(true); if (lsManagerCls) { sandbox.stub(lsManagerCls.prototype, 'dispose').returns(); } @@ -788,8 +811,7 @@ suite('Language server watcher', () => { } as unknown) as IWorkspaceService; watcher = new LanguageServerWatcher( - {} as IServiceContainer, - {} as ILanguageServerOutputChannel, + makeMockServiceContainer(), { getSettings: () => ({ languageServer }), } as IConfigurationService, @@ -815,7 +837,7 @@ suite('Language server watcher', () => { /* do nothing */ }, } as unknown) as ICommandManager, - {} as IFileSystem, + ({ getExtension: () => undefined, onDidChange: () => { @@ -866,12 +888,7 @@ suite('Language server watcher', () => { } as unknown) as IInterpreterService; watcher = new LanguageServerWatcher( - ({ - get: () => { - /* do nothing */ - }, - } as unknown) as IServiceContainer, - {} as ILanguageServerOutputChannel, + makeMockServiceContainer(), { getSettings: () => ({ languageServer: LanguageServerType.None }), } as IConfigurationService, @@ -905,7 +922,7 @@ suite('Language server watcher', () => { /* do nothing */ }, } as unknown) as ICommandManager, - {} as IFileSystem, + ({ getExtension: () => undefined, onDidChange: () => { @@ -946,12 +963,7 @@ suite('Language server watcher', () => { } as unknown) as IInterpreterService; watcher = new LanguageServerWatcher( - ({ - get: () => { - /* do nothing */ - }, - } as unknown) as IServiceContainer, - {} as ILanguageServerOutputChannel, + makeMockServiceContainer(), { getSettings: () => ({ languageServer: LanguageServerType.None }), } as IConfigurationService, @@ -985,7 +997,7 @@ suite('Language server watcher', () => { /* do nothing */ }, } as unknown) as ICommandManager, - {} as IFileSystem, + ({ getExtension: () => undefined, onDidChange: () => { @@ -1029,12 +1041,7 @@ suite('Language server watcher', () => { } as unknown) as IInterpreterService; watcher = new LanguageServerWatcher( - ({ - get: () => { - /* do nothing */ - }, - } as unknown) as IServiceContainer, - {} as ILanguageServerOutputChannel, + makeMockServiceContainer(), { getSettings: () => ({ languageServer: LanguageServerType.None }), } as IConfigurationService, @@ -1068,7 +1075,7 @@ suite('Language server watcher', () => { /* do nothing */ }, } as unknown) as ICommandManager, - {} as IFileSystem, + ({ getExtension: () => undefined, onDidChange: () => { @@ -1112,12 +1119,7 @@ suite('Language server watcher', () => { } as unknown) as IInterpreterService; watcher = new LanguageServerWatcher( - ({ - get: () => { - /* do nothing */ - }, - } as unknown) as IServiceContainer, - {} as ILanguageServerOutputChannel, + makeMockServiceContainer(), { getSettings: () => ({ languageServer: LanguageServerType.None }), } as IConfigurationService, @@ -1151,7 +1153,7 @@ suite('Language server watcher', () => { /* do nothing */ }, } as unknown) as ICommandManager, - {} as IFileSystem, + ({ getExtension: () => undefined, onDidChange: () => {