Skip to content

Commit 261ae66

Browse files
authored
Improvement: Pass along python interpreter to jedi-language-server (#22466)
Fixes #22495 ## Before this PR Overriding the Python interpreter to a different environment that isn't the current globally-activated base environment would yield no completions when Jedi is used as the underlying language server. Example [stackoverflow question](https://stackoverflow.com/questions/62018436/vscode-intellisense-code-completion-doesnt-work-when-i-am-not-in-base-conda-e) hitting the same issue. ## After this PR We now pass along the interpreter path to jedi-language-server as part of the initial options under `workspace.environmentPath` ([ref](https://github.com/pappasam/jedi-language-server/#workspaceenvironmentpath))
1 parent 1639753 commit 261ae66

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/client/activation/jedi/analysisOptions.ts

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import { ILanguageServerOutputChannel } from '../types';
1616
export class JediLanguageServerAnalysisOptions extends LanguageServerAnalysisOptionsWithEnv {
1717
private resource: Resource | undefined;
1818

19+
private interpreter: PythonEnvironment | undefined;
20+
1921
constructor(
2022
envVarsProvider: IEnvironmentVariablesProvider,
2123
lsOutputChannel: ILanguageServerOutputChannel,
@@ -28,6 +30,7 @@ export class JediLanguageServerAnalysisOptions extends LanguageServerAnalysisOpt
2830

2931
public async initialize(resource: Resource, interpreter: PythonEnvironment | undefined) {
3032
this.resource = resource;
33+
this.interpreter = interpreter;
3134
return super.initialize(resource, interpreter);
3235
}
3336

@@ -76,6 +79,7 @@ export class JediLanguageServerAnalysisOptions extends LanguageServerAnalysisOpt
7679
},
7780
workspace: {
7881
extraPaths: distinctExtraPaths,
82+
environmentPath: this.interpreter?.envPath,
7983
symbols: {
8084
// 0 means remove limit on number of workspace symbols returned
8185
maxSymbols: 0,

src/test/activation/jedi/jediAnalysisOptions.unit.test.ts

+21
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import { WorkspaceService } from '../../../client/common/application/workspace';
1212
import { ConfigurationService } from '../../../client/common/configuration/service';
1313
import { IConfigurationService } from '../../../client/common/types';
1414
import { IEnvironmentVariablesProvider } from '../../../client/common/variables/types';
15+
import { EnvironmentType, PythonEnvironment } from '../../../client/pythonEnvironments/info';
16+
import { Architecture } from '../../../client/common/utils/platform';
1517

1618
suite('Jedi LSP - analysis Options', () => {
1719
const workspacePath = path.join('this', 'is', 'fake', 'workspace', 'path');
@@ -74,6 +76,25 @@ suite('Jedi LSP - analysis Options', () => {
7476
expect(result.initializationOptions.workspace.symbols.maxSymbols).to.deep.equal(0);
7577
});
7678

79+
test('With interpreter path', async () => {
80+
when(workspaceService.getWorkspaceFolder(anything())).thenReturn(undefined);
81+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
82+
when(configurationService.getSettings(anything())).thenReturn({} as any);
83+
const pythonEnvironment: PythonEnvironment = {
84+
envPath: '.../.venv',
85+
id: 'base_env',
86+
envType: EnvironmentType.Conda,
87+
path: '.../.venv/bin/python',
88+
architecture: Architecture.x86,
89+
sysPrefix: 'prefix/path',
90+
};
91+
analysisOptions.initialize(undefined, pythonEnvironment);
92+
93+
const result = await analysisOptions.getAnalysisOptions();
94+
95+
expect(result.initializationOptions.workspace.environmentPath).to.deep.equal('.../.venv');
96+
});
97+
7798
test('Without extraPaths provided and no workspace', async () => {
7899
when(workspaceService.getWorkspaceFolder(anything())).thenReturn(undefined);
79100
// eslint-disable-next-line @typescript-eslint/no-explicit-any

0 commit comments

Comments
 (0)