Skip to content

Commit 7b7576e

Browse files
authored
feat: Add a Python language server (#220)
1 parent 08a78a4 commit 7b7576e

30 files changed

+9181
-618
lines changed

LSP.md

Lines changed: 533 additions & 0 deletions
Large diffs are not rendered by default.

build/esbuild/build.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const deskTopNodeModulesToExternalize = [
4343
// Lazy loaded modules.
4444
'vscode-languageclient/node',
4545
'@jupyterlab/nbformat',
46-
'vscode-jsonrpc' // Used by a few modules, might as well pull this out, instead of duplicating it in separate bundles.
46+
'vscode-jsonrpc'
4747
];
4848
const commonExternals = [
4949
'log4js',
@@ -226,10 +226,15 @@ function createConfig(
226226
inject.push(path.join(__dirname, 'jquery.js'));
227227
}
228228
// Create a copy to avoid mutating the original arrays
229-
const external = [...(target === 'web' ? webExternals : commonExternals)];
229+
let external = [...(target === 'web' ? webExternals : commonExternals)];
230230
if (source.toLowerCase().endsWith('extension.node.ts')) {
231231
external.push(...desktopExternals);
232232
}
233+
// When building vscode-languageclient, bundle vscode-jsonrpc into it
234+
// to avoid ESM/CommonJS interop issues at runtime
235+
if (source.includes('vscode-languageclient')) {
236+
external = external.filter((e) => e !== 'vscode-jsonrpc');
237+
}
233238
const isPreRelease = isDevbuild || process.env.IS_PRE_RELEASE_VERSION_OF_JUPYTER_EXTENSION === 'true';
234239
const releaseVersionScriptFile = isPreRelease ? 'release.pre-release.js' : 'release.stable.js';
235240
const alias = {
@@ -534,20 +539,18 @@ async function copyNodeGypBuild() {
534539
await fs.ensureDir(target);
535540
await fs.copy(source, target, { recursive: true });
536541
}
542+
537543
async function buildVSCodeJsonRPC() {
538544
const source = path.join(extensionFolder, 'node_modules', 'vscode-jsonrpc');
539545
const target = path.join(extensionFolder, 'dist', 'node_modules', 'vscode-jsonrpc', 'index.js');
540546
await fs.ensureDir(path.dirname(target));
541547
const fullPath = require.resolve(source);
542-
const contents = `
543-
/* --------------------------------------------------------------------------------------------
544-
* Copyright (c) Microsoft Corporation. All rights reserved.
545-
* Licensed under the MIT License. See License.txt in the project root for license information.
546-
* ----------------------------------------------------------------------------------------- */
547-
'use strict';
548-
549-
module.exports = require('./index');`;
548+
// ESM re-export for node.js entry point
549+
const contents = `export * from './index.js';`;
550550
await fs.writeFile(path.join(path.dirname(target), 'node.js'), contents);
551+
// Add package.json for ESM module resolution
552+
const packageJson = JSON.stringify({ type: 'module', main: './index.js' }, null, 2);
553+
await fs.writeFile(path.join(path.dirname(target), 'package.json'), packageJson);
551554
return build(fullPath, target, {
552555
target: 'desktop',
553556
watch: false

cspell.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"pids",
5858
"Pids",
5959
"plotly",
60+
"pylsp",
6061
"PYTHONHOME",
6162
"Reselecting",
6263
"scipy",

package-lock.json

Lines changed: 85 additions & 38 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2547,7 +2547,7 @@
25472547
"vega-embed": "^7.1.0",
25482548
"vega-lite": "^6.4.1",
25492549
"vscode-debugprotocol": "^1.41.0",
2550-
"vscode-languageclient": "8.0.2-next.5",
2550+
"vscode-languageclient": "^9.0.1",
25512551
"vscode-tas-client": "^0.1.84",
25522552
"ws": "^6.2.3",
25532553
"zeromq": "^6.5.0",

src/commands.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,6 @@ export interface ICommandNameArgumentTypeMapping {
181181
[DSCommands.RunAndDebugCell]: [NotebookCell];
182182
[DSCommands.RunByLineNext]: [NotebookCell];
183183
[DSCommands.RunByLineStop]: [NotebookCell];
184-
[DSCommands.ReplayPylanceLog]: [Uri];
185-
[DSCommands.ReplayPylanceLogStep]: [];
186184
[DSCommands.InstallPythonExtensionViaKernelPicker]: [];
187185
[DSCommands.InstallPythonViaKernelPicker]: [];
188186
[DSCommands.ContinueEditSessionInCodespace]: [];

src/extension.common.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import {
1818
import {
1919
STANDARD_OUTPUT_CHANNEL,
2020
JUPYTER_OUTPUT_CHANNEL,
21-
PylanceExtension,
2221
PythonExtension,
2322
Telemetry,
2423
PythonEnvironmentExtension
@@ -39,7 +38,6 @@ import { IServiceContainer, IServiceManager } from './platform/ioc/types';
3938
import { initializeLoggers as init, logger } from './platform/logging';
4039
import { ILogger } from './platform/logging/types';
4140
import { getJupyterOutputChannel } from './standalone/devTools/jupyterOutputChannel';
42-
import { isUsingPylance } from './standalone/intellisense/notebookPythonPathService';
4341
import { noop } from './platform/common/utils/misc';
4442
import { sendErrorTelemetry } from './platform/telemetry/startupTelemetry';
4543
import { StopWatch } from './platform/common/utils/stopWatch';
@@ -77,16 +75,6 @@ export async function initializeLoggers(
7775
} else {
7876
standardOutputChannel.appendLine('Python Environment Extension not installed.');
7977
}
80-
const pylanceExtension = extensions.getExtension(PylanceExtension);
81-
if (pylanceExtension) {
82-
standardOutputChannel.appendLine(
83-
`Pylance Extension Version${isUsingPylance() ? '' : ' (Not Used) '}: ${
84-
pylanceExtension.packageJSON['version']
85-
}.`
86-
);
87-
} else {
88-
standardOutputChannel.appendLine('Pylance Extension not installed.');
89-
}
9078
if (options?.platform) {
9179
standardOutputChannel.appendLine(`Platform: ${options.platform} (${options.arch}).`);
9280
}

0 commit comments

Comments
 (0)