From 1fdd5f24fbecf846ddd1c375b05a8cb5b3bedf95 Mon Sep 17 00:00:00 2001 From: John Ayad Date: Mon, 13 Nov 2023 16:03:26 +0000 Subject: [PATCH 1/3] Improvement: Pass along python interpreter to jedi-language-server --- src/client/activation/jedi/analysisOptions.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/client/activation/jedi/analysisOptions.ts b/src/client/activation/jedi/analysisOptions.ts index 4778c4e1523f..e5d84d8aaa3f 100644 --- a/src/client/activation/jedi/analysisOptions.ts +++ b/src/client/activation/jedi/analysisOptions.ts @@ -15,6 +15,7 @@ import { ILanguageServerOutputChannel } from '../types'; export class JediLanguageServerAnalysisOptions extends LanguageServerAnalysisOptionsWithEnv { private resource: Resource | undefined; + private interpreter: PythonEnvironment | undefined; constructor( envVarsProvider: IEnvironmentVariablesProvider, @@ -28,6 +29,7 @@ export class JediLanguageServerAnalysisOptions extends LanguageServerAnalysisOpt public async initialize(resource: Resource, interpreter: PythonEnvironment | undefined) { this.resource = resource; + this.interpreter = interpreter; return super.initialize(resource, interpreter); } @@ -76,6 +78,7 @@ export class JediLanguageServerAnalysisOptions extends LanguageServerAnalysisOpt }, workspace: { extraPaths: distinctExtraPaths, + environmentPath: this.interpreter?.envPath, symbols: { // 0 means remove limit on number of workspace symbols returned maxSymbols: 0, From 243eeba66ee36e4cfd76930872a9772de800e8f2 Mon Sep 17 00:00:00 2001 From: John Ayad Date: Mon, 13 Nov 2023 16:18:37 +0000 Subject: [PATCH 2/3] Test & format --- src/client/activation/jedi/analysisOptions.ts | 1 + .../jedi/jediAnalysisOptions.unit.test.ts | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/client/activation/jedi/analysisOptions.ts b/src/client/activation/jedi/analysisOptions.ts index e5d84d8aaa3f..d05267f041b3 100644 --- a/src/client/activation/jedi/analysisOptions.ts +++ b/src/client/activation/jedi/analysisOptions.ts @@ -15,6 +15,7 @@ import { ILanguageServerOutputChannel } from '../types'; export class JediLanguageServerAnalysisOptions extends LanguageServerAnalysisOptionsWithEnv { private resource: Resource | undefined; + private interpreter: PythonEnvironment | undefined; constructor( diff --git a/src/test/activation/jedi/jediAnalysisOptions.unit.test.ts b/src/test/activation/jedi/jediAnalysisOptions.unit.test.ts index 8104ed2730b0..c7411179b118 100644 --- a/src/test/activation/jedi/jediAnalysisOptions.unit.test.ts +++ b/src/test/activation/jedi/jediAnalysisOptions.unit.test.ts @@ -12,6 +12,8 @@ import { WorkspaceService } from '../../../client/common/application/workspace'; import { ConfigurationService } from '../../../client/common/configuration/service'; import { IConfigurationService } from '../../../client/common/types'; import { IEnvironmentVariablesProvider } from '../../../client/common/variables/types'; +import { EnvironmentType, PythonEnvironment } from '../../../client/pythonEnvironments/info'; +import { Architecture } from '../../../client/common/utils/platform'; suite('Jedi LSP - analysis Options', () => { const workspacePath = path.join('this', 'is', 'fake', 'workspace', 'path'); @@ -74,6 +76,25 @@ suite('Jedi LSP - analysis Options', () => { expect(result.initializationOptions.workspace.symbols.maxSymbols).to.deep.equal(0); }); + test('With interpreter path', async () => { + when(workspaceService.getWorkspaceFolder(anything())).thenReturn(undefined); + // eslint-disable-next-line @typescript-eslint/no-explicit-any + when(configurationService.getSettings(anything())).thenReturn({} as any); + const pythonEnvironment: PythonEnvironment = { + envPath: 'interpreterPath', + id: 'base_env', + envType: EnvironmentType.Conda, + path: 'interpreterPath', + architecture: Architecture.x86, + sysPrefix: 'prefix/path', + }; + analysisOptions.initialize(undefined, pythonEnvironment); + + const result = await analysisOptions.getAnalysisOptions(); + + expect(result.initializationOptions.workspace.environmentPath).to.deep.equal('interpreterPath'); + }); + test('Without extraPaths provided and no workspace', async () => { when(workspaceService.getWorkspaceFolder(anything())).thenReturn(undefined); // eslint-disable-next-line @typescript-eslint/no-explicit-any From 091ff29a9118098f137e835f73d5594e00030d7d Mon Sep 17 00:00:00 2001 From: "John H. Ayad" Date: Thu, 23 Nov 2023 17:44:57 +0000 Subject: [PATCH 3/3] Reflect actual values from feedback --- src/test/activation/jedi/jediAnalysisOptions.unit.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/activation/jedi/jediAnalysisOptions.unit.test.ts b/src/test/activation/jedi/jediAnalysisOptions.unit.test.ts index c7411179b118..39ae0cfb21a9 100644 --- a/src/test/activation/jedi/jediAnalysisOptions.unit.test.ts +++ b/src/test/activation/jedi/jediAnalysisOptions.unit.test.ts @@ -81,10 +81,10 @@ suite('Jedi LSP - analysis Options', () => { // eslint-disable-next-line @typescript-eslint/no-explicit-any when(configurationService.getSettings(anything())).thenReturn({} as any); const pythonEnvironment: PythonEnvironment = { - envPath: 'interpreterPath', + envPath: '.../.venv', id: 'base_env', envType: EnvironmentType.Conda, - path: 'interpreterPath', + path: '.../.venv/bin/python', architecture: Architecture.x86, sysPrefix: 'prefix/path', }; @@ -92,7 +92,7 @@ suite('Jedi LSP - analysis Options', () => { const result = await analysisOptions.getAnalysisOptions(); - expect(result.initializationOptions.workspace.environmentPath).to.deep.equal('interpreterPath'); + expect(result.initializationOptions.workspace.environmentPath).to.deep.equal('.../.venv'); }); test('Without extraPaths provided and no workspace', async () => {