Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to latest jupyter lsp and skip intellisense when inside a cell #17734

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2047,7 +2047,7 @@
"webpack": "webpack"
},
"dependencies": {
"@vscode/jupyter-lsp-middleware": "^0.2.5",
"@vscode/jupyter-lsp-middleware": "^0.2.13",
"arch": "^2.1.0",
"azure-storage": "^2.10.4",
"chokidar": "^3.4.3",
Expand Down
7 changes: 1 addition & 6 deletions src/client/activation/jedi/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,7 @@ export class JediLanguageServerManager implements ILanguageServerManager {
this.languageServerProxy = this.serviceContainer.get<ILanguageServerProxy>(ILanguageServerProxy);

const options = await this.analysisOptions.getAnalysisOptions();
this.middleware = new LanguageClientMiddleware(
this.serviceContainer,
LanguageServerType.Jedi,
() => this.languageServerProxy?.languageClient,
this.lsVersion,
);
this.middleware = new LanguageClientMiddleware(this.serviceContainer, LanguageServerType.Jedi, this.lsVersion);
options.middleware = this.middleware;

// Make sure the middleware is connected if we restart and we we're already connected.
Expand Down
35 changes: 5 additions & 30 deletions src/client/activation/languageClientMiddleware.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,18 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import { LanguageClient } from 'vscode-languageclient/node';
import { IJupyterExtensionDependencyManager, IVSCodeNotebook } from '../common/application/types';
import { PYTHON_LANGUAGE } from '../common/constants';
import { traceInfo } from '../common/logger';
import { IFileSystem } from '../common/platform/types';
import { IJupyterExtensionDependencyManager } from '../common/application/types';
import { IDisposableRegistry, IExtensions } from '../common/types';
import { IServiceContainer } from '../ioc/types';
import { sendTelemetryEvent } from '../telemetry';

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

import { createMiddlewareAddon } from '@vscode/jupyter-lsp-middleware';
import { createHidingMiddleware } from '@vscode/jupyter-lsp-middleware';

export class LanguageClientMiddleware extends LanguageClientMiddlewareBase {
public constructor(
serviceContainer: IServiceContainer,
serverType: LanguageServerType,
getClient: () => LanguageClient | undefined,
serverVersion?: string,
) {
public constructor(serviceContainer: IServiceContainer, serverType: LanguageServerType, serverVersion?: string) {
super(serviceContainer, serverType, sendTelemetryEvent, serverVersion);

if (serverType === LanguageServerType.None) {
Expand All @@ -31,36 +22,20 @@ export class LanguageClientMiddleware extends LanguageClientMiddlewareBase {
const jupyterDependencyManager = serviceContainer.get<IJupyterExtensionDependencyManager>(
IJupyterExtensionDependencyManager,
);
const notebookApi = serviceContainer.get<IVSCodeNotebook>(IVSCodeNotebook);
const disposables = serviceContainer.get<IDisposableRegistry>(IDisposableRegistry) || [];
const extensions = serviceContainer.get<IExtensions>(IExtensions);
const fileSystem = serviceContainer.get<IFileSystem>(IFileSystem);

// Enable notebook support if jupyter support is installed
if (jupyterDependencyManager && jupyterDependencyManager.isJupyterExtensionInstalled) {
this.notebookAddon = createMiddlewareAddon(
notebookApi,
getClient,
traceInfo,
fileSystem,
PYTHON_LANGUAGE,
/.*\.(ipynb|interactive)/m,
);
this.notebookAddon = createHidingMiddleware();
}
disposables.push(
extensions?.onDidChange(() => {
if (jupyterDependencyManager) {
if (this.notebookAddon && !jupyterDependencyManager.isJupyterExtensionInstalled) {
this.notebookAddon = undefined;
} else if (!this.notebookAddon && jupyterDependencyManager.isJupyterExtensionInstalled) {
this.notebookAddon = createMiddlewareAddon(
notebookApi,
getClient,
traceInfo,
fileSystem,
PYTHON_LANGUAGE,
/.*\.(ipynb|interactive)/m,
);
this.notebookAddon = createHidingMiddleware();
}
}
}),
Expand Down
6 changes: 3 additions & 3 deletions src/client/activation/languageClientMiddlewareBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
Definition,
DefinitionLink,
Diagnostic,
Disposable,
DocumentHighlight,
DocumentLink,
DocumentSymbol,
Expand All @@ -30,7 +31,6 @@ import {
Middleware,
ResponseError,
} from 'vscode-languageclient';
import type { MiddlewareAddon } from '@vscode/jupyter-lsp-middleware';

import { HiddenFilePrefix } from '../common/constants';
import { IConfigurationService } from '../common/types';
Expand Down Expand Up @@ -111,7 +111,7 @@ export class LanguageClientMiddlewareBase implements Middleware {
},
};

protected notebookAddon: MiddlewareAddon | undefined;
protected notebookAddon: (Middleware & Disposable) | undefined;

private connected = false; // Default to not forwarding to VS code.

Expand Down Expand Up @@ -343,7 +343,7 @@ export class LanguageClientMiddlewareBase implements Middleware {
}
}

private callNext(funcName: keyof MiddlewareAddon, args: IArguments) {
private callNext(funcName: keyof Middleware, args: IArguments) {
// This function uses the last argument to call the 'next' item. If we're allowing notebook
// middleware, it calls into the notebook middleware first.
if (this.notebookAddon) {
Expand Down
1 change: 0 additions & 1 deletion src/client/activation/languageServer/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ export class DotNetLanguageServerManager implements ILanguageServerManager {
options.middleware = this.middleware = new LanguageClientMiddleware(
this.serviceContainer,
LanguageServerType.Microsoft,
() => this.languageServerProxy?.languageClient,
this.lsVersion,
);

Expand Down
1 change: 0 additions & 1 deletion src/client/activation/node/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ export class NodeLanguageServerManager implements ILanguageServerManager {
options.middleware = this.middleware = new LanguageClientMiddleware(
this.serviceContainer,
LanguageServerType.Node,
() => this.languageServerProxy?.languageClient,
this.lsVersion,
);

Expand Down
6 changes: 6 additions & 0 deletions src/client/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ export const PYTHON = [
{ scheme: InteractiveInputScheme, language: PYTHON_LANGUAGE },
];

export const PYTHON_NOTEBOOKS = [
{ scheme: 'vscode-notebook', language: PYTHON_LANGUAGE },
{ scheme: NotebookCellScheme, language: PYTHON_LANGUAGE },
{ scheme: InteractiveInputScheme, language: PYTHON_LANGUAGE },
];

export const PVSC_EXTENSION_ID = 'ms-python.python';
export const CODE_RUNNER_EXTENSION_ID = 'formulahendry.code-runner';
export const PYLANCE_EXTENSION_ID = 'ms-python.vscode-pylance';
Expand Down