Skip to content

Commit

Permalink
Share output channel with pylance (#20833)
Browse files Browse the repository at this point in the history
Make sure `pylance` and `jedi` share the same output channel.
  • Loading branch information
heejaechang authored Mar 13, 2023
1 parent 2cd2092 commit 0735876
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/client/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@

import { noop } from 'lodash';
import { Uri, Event } from 'vscode';
import { BaseLanguageClient } from 'vscode-languageclient';
import { BaseLanguageClient, LanguageClientOptions } from 'vscode-languageclient';
import { LanguageClient } from 'vscode-languageclient/node';
import { PYLANCE_NAME } from './activation/node/languageClientFactory';
import { ILanguageServerOutputChannel } from './activation/types';
import { IExtensionApi } from './apiTypes';
import { isTestExecution, PYTHON_LANGUAGE } from './common/constants';
import { IConfigurationService, Resource } from './common/types';
Expand All @@ -28,6 +29,8 @@ export function buildApi(
serviceManager.addSingleton<JupyterExtensionIntegration>(JupyterExtensionIntegration, JupyterExtensionIntegration);
const jupyterIntegration = serviceContainer.get<JupyterExtensionIntegration>(JupyterExtensionIntegration);
const envService = serviceContainer.get<IEnvironmentVariablesProvider>(IEnvironmentVariablesProvider);
const outputChannel = serviceContainer.get<ILanguageServerOutputChannel>(ILanguageServerOutputChannel);

const api: IExtensionApi & {
/**
* @deprecated Temporarily exposed for Pylance until we expose this API generally. Will be removed in an
Expand Down Expand Up @@ -89,8 +92,14 @@ export function buildApi(
return envs.PYTHONPATH;
},
onDidEnvironmentVariablesChange: envService.onDidEnvironmentVariablesChange,
createClient: (...args: any[]): BaseLanguageClient =>
new LanguageClient(PYTHON_LANGUAGE, PYLANCE_NAME, args[0], args[1]),
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<void> => client.start(),
stop: (client: BaseLanguageClient): Promise<void> => client.stop(),
},
Expand Down

0 comments on commit 0735876

Please sign in to comment.