Skip to content

Commit 0735876

Browse files
authored
Share output channel with pylance (#20833)
Make sure `pylance` and `jedi` share the same output channel.
1 parent 2cd2092 commit 0735876

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/client/api.ts

+12-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55

66
import { noop } from 'lodash';
77
import { Uri, Event } from 'vscode';
8-
import { BaseLanguageClient } from 'vscode-languageclient';
8+
import { BaseLanguageClient, LanguageClientOptions } from 'vscode-languageclient';
99
import { LanguageClient } from 'vscode-languageclient/node';
1010
import { PYLANCE_NAME } from './activation/node/languageClientFactory';
11+
import { ILanguageServerOutputChannel } from './activation/types';
1112
import { IExtensionApi } from './apiTypes';
1213
import { isTestExecution, PYTHON_LANGUAGE } from './common/constants';
1314
import { IConfigurationService, Resource } from './common/types';
@@ -28,6 +29,8 @@ export function buildApi(
2829
serviceManager.addSingleton<JupyterExtensionIntegration>(JupyterExtensionIntegration, JupyterExtensionIntegration);
2930
const jupyterIntegration = serviceContainer.get<JupyterExtensionIntegration>(JupyterExtensionIntegration);
3031
const envService = serviceContainer.get<IEnvironmentVariablesProvider>(IEnvironmentVariablesProvider);
32+
const outputChannel = serviceContainer.get<ILanguageServerOutputChannel>(ILanguageServerOutputChannel);
33+
3134
const api: IExtensionApi & {
3235
/**
3336
* @deprecated Temporarily exposed for Pylance until we expose this API generally. Will be removed in an
@@ -89,8 +92,14 @@ export function buildApi(
8992
return envs.PYTHONPATH;
9093
},
9194
onDidEnvironmentVariablesChange: envService.onDidEnvironmentVariablesChange,
92-
createClient: (...args: any[]): BaseLanguageClient =>
93-
new LanguageClient(PYTHON_LANGUAGE, PYLANCE_NAME, args[0], args[1]),
95+
createClient: (...args: any[]): BaseLanguageClient => {
96+
// Make sure we share output channel so that we can share one with
97+
// Jedi as well.
98+
const clientOptions = args[1] as LanguageClientOptions;
99+
clientOptions.outputChannel = clientOptions.outputChannel ?? outputChannel.channel;
100+
101+
return new LanguageClient(PYTHON_LANGUAGE, PYLANCE_NAME, args[0], clientOptions);
102+
},
94103
start: (client: BaseLanguageClient): Promise<void> => client.start(),
95104
stop: (client: BaseLanguageClient): Promise<void> => client.stop(),
96105
},

0 commit comments

Comments
 (0)