Skip to content
Open
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
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,12 @@
"scope": "window",
"type": "string"
},
"python.languageServer.useJediInEnvPath": {
"default": false,
"description": "%python.languageServer.useJediInEnvPath.description%",
"scope": "window",
"type": "boolean"
},
"python.interpreter.infoVisibility": {
"default": "onPythonRelated",
"description": "%python.interpreter.infoVisibility.description%",
Expand Down
1 change: 1 addition & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"python.languageServer.jediDescription": "Use Jedi behind the Language Server Protocol (LSP) as a language server.",
"python.languageServer.pylanceDescription": "Use Pylance as a language server.",
"python.languageServer.noneDescription": "Disable language server capabilities.",
"python.languageServer.useJediInEnvPath.description": "Use Jedi in system environment or virtual environments.",
"python.interpreter.infoVisibility.description": "Controls when to display information of selected interpreter in the status bar.",
"python.interpreter.infoVisibility.never.description": "Never display information.",
"python.interpreter.infoVisibility.onPythonRelated.description": "Only display information if Python-related files are opened.",
Expand Down
20 changes: 15 additions & 5 deletions python_files/run-jedi-language-server.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,21 @@
import pathlib
import sys

# Add the lib path to our sys path so jedi_language_server can find its references
extension_dir = pathlib.Path(__file__).parent.parent
EXTENSION_ROOT = os.fsdecode(extension_dir)
sys.path.insert(0, os.fsdecode(extension_dir / "python_files" / "lib" / "jedilsp"))
del extension_dir
use_external_jedi = sys.argv[-1] == "external"
sys.argv = sys.argv[:-1]

if use_external_jedi:
try:
import jedi_language_server
except Exception:
use_external_jedi = False

if not use_external_jedi:
# Add the lib path to our sys path so jedi_language_server can find its references
extension_dir = pathlib.Path(__file__).parent.parent
EXTENSION_ROOT = os.fsdecode(extension_dir)
sys.path.insert(0, os.fsdecode(extension_dir / "python_files" / "lib" / "jedilsp"))
del extension_dir


from jedi_language_server.cli import cli # noqa: E402
Expand Down
6 changes: 4 additions & 2 deletions src/client/activation/jedi/languageClientFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License.

import * as path from 'path';
import { WorkspaceConfiguration } from 'vscode';
import { LanguageClient, LanguageClientOptions, ServerOptions } from 'vscode-languageclient/node';

import { EXTENSION_ROOT_DIR, PYTHON_LANGUAGE } from '../../common/constants';
Expand All @@ -13,7 +14,7 @@ import { ILanguageClientFactory } from '../types';
const languageClientName = 'Python Jedi';

export class JediLanguageClientFactory implements ILanguageClientFactory {
constructor(private interpreterService: IInterpreterService) {}
constructor(private interpreterService: IInterpreterService, private readonly workspaceConfiguration: WorkspaceConfiguration) {}

public async createLanguageClient(
resource: Resource,
Expand All @@ -23,9 +24,10 @@ export class JediLanguageClientFactory implements ILanguageClientFactory {
// Just run the language server using a module
const lsScriptPath = path.join(EXTENSION_ROOT_DIR, 'python_files', 'run-jedi-language-server.py');
const interpreter = await this.interpreterService.getActiveInterpreter(resource);
const useJediInEnv = this.workspaceConfiguration.get<boolean>("languageServer.useJediInEnvPath") === true
const serverOptions: ServerOptions = {
command: interpreter ? interpreter.path : 'python',
args: [lsScriptPath],
args: [lsScriptPath, useJediInEnv ? "external": "internal"],
};

return new LanguageClient(PYTHON_LANGUAGE, languageClientName, serverOptions, clientOptions);
Expand Down
2 changes: 1 addition & 1 deletion src/client/languageServer/jediLSExtensionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class JediLSExtensionManager implements IDisposable, ILanguageServerExten
configurationService,
workspaceService,
);
this.clientFactory = new JediLanguageClientFactory(interpreterService);
this.clientFactory = new JediLanguageClientFactory(interpreterService, workspaceService.getConfiguration("python"));
this.serverProxy = new JediLanguageServerProxy(this.clientFactory);
this.serverManager = new JediLanguageServerManager(
serviceContainer,
Expand Down