Skip to content

Commit

Permalink
Remove old Pylance-related code (microsoft/vscode-python#22985)
Browse files Browse the repository at this point in the history
Part of microsoft/vscode-jupyter#14977

Removes some effectively dead code that would only be used by very old
(year+) versions of Pylance. This logic has all been moved into
vscode-pylance:

- Middleware to make the interactive window input box look like a
notebook cell
- Call to Jupyter to get pythonpath for notebooks.
- Configuration hook to get `[python]` value of `editor.formatOnType`.
- LSP notebook experiment
  • Loading branch information
debonte authored Feb 29, 2024
1 parent f99f42f commit 7713a1c
Show file tree
Hide file tree
Showing 9 changed files with 4 additions and 558 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,7 @@ export class LanguageClientMiddlewareBase implements Middleware {
const settingDict: LSPObject & { pythonPath: string; _envPYTHONPATH: string } = settings[
i
] as LSPObject & { pythonPath: string; _envPYTHONPATH: string };
settingDict.pythonPath =
(await this.getPythonPathOverride(uri)) ??
(await interpreterService.getActiveInterpreter(uri))?.path ??
'python';
settingDict.pythonPath = (await interpreterService.getActiveInterpreter(uri))?.path ?? 'python';

const env = await envService.getEnvironmentVariables(uri);
const envPYTHONPATH = env.PYTHONPATH;
Expand All @@ -106,11 +103,6 @@ export class LanguageClientMiddlewareBase implements Middleware {
},
};

// eslint-disable-next-line class-methods-use-this
protected async getPythonPathOverride(_uri: Uri | undefined): Promise<string | undefined> {
return undefined;
}

// eslint-disable-next-line class-methods-use-this, @typescript-eslint/no-empty-function
protected configurationHook(_item: ConfigurationItem, _settings: LSPObject): void {}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,104 +1,21 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import { Uri } from 'vscode';
import { ConfigurationItem, LanguageClient, LSPObject } from 'vscode-languageclient/node';
import { IJupyterExtensionDependencyManager, IWorkspaceService } from '../../common/application/types';
import { IJupyterExtensionDependencyManager } from '../../common/application/types';
import { IServiceContainer } from '../../ioc/types';
import { JupyterExtensionIntegration } from '../../jupyter/jupyterIntegration';
import { traceLog } from '../../logging';
import { LanguageClientMiddleware } from '../languageClientMiddleware';
import { LspInteractiveWindowMiddlewareAddon } from './lspInteractiveWindowMiddlewareAddon';

import { LanguageServerType } from '../types';

import { LspNotebooksExperiment } from './lspNotebooksExperiment';

export class NodeLanguageClientMiddleware extends LanguageClientMiddleware {
private readonly lspNotebooksExperiment: LspNotebooksExperiment;

private readonly jupyterExtensionIntegration: JupyterExtensionIntegration;

private readonly workspaceService: IWorkspaceService;

public constructor(
serviceContainer: IServiceContainer,
private getClient: () => LanguageClient | undefined,
serverVersion?: string,
) {
public constructor(serviceContainer: IServiceContainer, serverVersion?: string) {
super(serviceContainer, LanguageServerType.Node, serverVersion);

this.workspaceService = serviceContainer.get<IWorkspaceService>(IWorkspaceService);

this.lspNotebooksExperiment = serviceContainer.get<LspNotebooksExperiment>(LspNotebooksExperiment);
this.setupHidingMiddleware(serviceContainer);

this.jupyterExtensionIntegration = serviceContainer.get<JupyterExtensionIntegration>(
JupyterExtensionIntegration,
);
if (!this.notebookAddon) {
this.notebookAddon = new LspInteractiveWindowMiddlewareAddon(
this.getClient,
this.jupyterExtensionIntegration,
);
}
}

// eslint-disable-next-line class-methods-use-this
protected shouldCreateHidingMiddleware(_: IJupyterExtensionDependencyManager): boolean {
return false;
}

protected async onExtensionChange(jupyterDependencyManager: IJupyterExtensionDependencyManager): Promise<void> {
if (jupyterDependencyManager && jupyterDependencyManager.isJupyterExtensionInstalled) {
await this.lspNotebooksExperiment.onJupyterInstalled();
}

if (!this.notebookAddon) {
this.notebookAddon = new LspInteractiveWindowMiddlewareAddon(
this.getClient,
this.jupyterExtensionIntegration,
);
}
}

protected async getPythonPathOverride(uri: Uri | undefined): Promise<string | undefined> {
if (!uri) {
return undefined;
}

const jupyterPythonPathFunction = this.jupyterExtensionIntegration.getJupyterPythonPathFunction();
if (!jupyterPythonPathFunction) {
return undefined;
}

const result = await jupyterPythonPathFunction(uri);

if (result) {
traceLog(`Jupyter provided interpreter path override: ${result}`);
}

return result;
}

// eslint-disable-next-line class-methods-use-this
protected configurationHook(item: ConfigurationItem, settings: LSPObject): void {
if (item.section === 'editor') {
if (this.workspaceService) {
// Get editor.formatOnType using Python language id so [python] setting
// will be honored if present.
const editorConfig = this.workspaceService.getConfiguration(
item.section,
undefined,
/* languageSpecific */ true,
);

const settingDict: LSPObject & { formatOnType?: boolean } = settings as LSPObject & {
formatOnType: boolean;
};

settingDict.formatOnType = editorConfig.get('formatOnType');
}
}
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,7 @@ export class NodeLanguageServerManager implements ILanguageServerManager {
@traceDecoratorVerbose('Starting language server')
protected async startLanguageServer(): Promise<void> {
const options = await this.analysisOptions.getAnalysisOptions();
this.middleware = new NodeLanguageClientMiddleware(
this.serviceContainer,
() => this.languageServerProxy.languageClient,
this.lsVersion,
);
this.middleware = new NodeLanguageClientMiddleware(this.serviceContainer, this.lsVersion);
options.middleware = this.middleware;

// Make sure the middleware is connected if we restart and we we're already connected.
Expand Down
Loading

0 comments on commit 7713a1c

Please sign in to comment.