Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvement: Pass along python interpreter to jedi-language-server #22466

Merged
merged 4 commits into from
Nov 28, 2023
Merged
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
4 changes: 4 additions & 0 deletions src/client/activation/jedi/analysisOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
}

Expand Down Expand Up @@ -76,6 +79,7 @@ export class JediLanguageServerAnalysisOptions extends LanguageServerAnalysisOpt
},
workspace: {
extraPaths: distinctExtraPaths,
environmentPath: this.interpreter?.envPath,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@karrtikr is this the right value to pass here ?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean to pass the path to the environment folder here? For eg. this carries the path to .venv folder. If that's the case this looks good, but I'm not clear on what this is supposed to carry.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's indeed supposed to be the path to the environment. From briefly digging into the Jedi codebase, it seems to either expect the environment folder, or the bin/python executable within it.

symbols: {
// 0 means remove limit on number of workspace symbols returned
maxSymbols: 0,
Expand Down
21 changes: 21 additions & 0 deletions src/test/activation/jedi/jediAnalysisOptions.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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
Expand Down
Loading