diff --git a/src/client/activation/jedi/analysisOptions.ts b/src/client/activation/jedi/analysisOptions.ts index 4778c4e1523f..d05267f041b3 100644 --- a/src/client/activation/jedi/analysisOptions.ts +++ b/src/client/activation/jedi/analysisOptions.ts @@ -16,6 +16,8 @@ import { ILanguageServerOutputChannel } from '../types'; export class JediLanguageServerAnalysisOptions extends LanguageServerAnalysisOptionsWithEnv { private resource: Resource | undefined; + private interpreter: PythonEnvironment | undefined; + constructor( envVarsProvider: IEnvironmentVariablesProvider, lsOutputChannel: ILanguageServerOutputChannel, @@ -28,6 +30,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 +79,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, diff --git a/src/test/activation/jedi/jediAnalysisOptions.unit.test.ts b/src/test/activation/jedi/jediAnalysisOptions.unit.test.ts index 8104ed2730b0..39ae0cfb21a9 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: '.../.venv', + id: 'base_env', + envType: EnvironmentType.Conda, + path: '.../.venv/bin/python', + architecture: Architecture.x86, + sysPrefix: 'prefix/path', + }; + analysisOptions.initialize(undefined, pythonEnvironment); + + const result = await analysisOptions.getAnalysisOptions(); + + expect(result.initializationOptions.workspace.environmentPath).to.deep.equal('.../.venv'); + }); + test('Without extraPaths provided and no workspace', async () => { when(workspaceService.getWorkspaceFolder(anything())).thenReturn(undefined); // eslint-disable-next-line @typescript-eslint/no-explicit-any