Skip to content

Commit

Permalink
Upgrade to latest jupyter lsp and skip intellisense when inside a cell (
Browse files Browse the repository at this point in the history
microsoft/vscode-python#17734)

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

* Update package-lock.json
  • Loading branch information
rchiodo authored and wesm committed Mar 28, 2024
1 parent 2c2ab03 commit 1ee84ac
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 46 deletions.
7 changes: 3 additions & 4 deletions extensions/positron-python/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 extensions/positron-python/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
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
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
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
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
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 extensions/positron-python/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

0 comments on commit 1ee84ac

Please sign in to comment.