Skip to content

Commit f234d38

Browse files
authored
Add extraPaths support to JediLSP (microsoft#15365)
* Add extraPaths support * Remove duplicate opt option * Eslint cleanup * Fix tests
1 parent e41513b commit f234d38

5 files changed

Lines changed: 198 additions & 28 deletions

File tree

.eslintignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,6 @@ src/client/providers/docStringFoldingProvider.ts
382382
src/client/providers/linterProvider.ts
383383
src/client/providers/simpleRefactorProvider.ts
384384
src/client/providers/completionProvider.ts
385-
src/client/providers/jediProxy.ts
386385
src/client/providers/definitionProvider.ts
387386
src/client/providers/referenceProvider.ts
388387
src/client/providers/terminalProvider.ts

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,7 +1044,6 @@
10441044
"DeprecatePythonPath - experiment",
10451045
"RunByLine - experiment",
10461046
"tryPylance",
1047-
"jediLSP",
10481047
"debuggerDataViewer",
10491048
"pythonSendEntireLineToREPL",
10501049
"pythonTensorboardExperiment",
@@ -1074,7 +1073,6 @@
10741073
"DeprecatePythonPath - experiment",
10751074
"RunByLine - experiment",
10761075
"tryPylance",
1077-
"jediLSP",
10781076
"debuggerDataViewer",
10791077
"pythonSendEntireLineToREPL",
10801078
"pythonTensorboardExperiment",

src/client/activation/jedi/analysisOptions.ts

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,61 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33
import { inject, injectable } from 'inversify';
4+
import * as path from 'path';
5+
import { WorkspaceFolder } from 'vscode';
6+
import { IWorkspaceService } from '../../common/application/types';
7+
import { IConfigurationService, Resource } from '../../common/types';
48

59
import { IEnvironmentVariablesProvider } from '../../common/variables/types';
10+
import { PythonEnvironment } from '../../pythonEnvironments/info';
611
import { LanguageServerAnalysisOptionsWithEnv } from '../common/analysisOptions';
712
import { ILanguageServerOutputChannel } from '../types';
813

914
/* eslint-disable @typescript-eslint/explicit-module-boundary-types, class-methods-use-this */
1015

1116
@injectable()
1217
export class JediLanguageServerAnalysisOptions extends LanguageServerAnalysisOptionsWithEnv {
13-
// eslint-disable-next-line @typescript-eslint/no-useless-constructor
18+
private resource: Resource | undefined;
19+
1420
constructor(
1521
@inject(IEnvironmentVariablesProvider) envVarsProvider: IEnvironmentVariablesProvider,
1622
@inject(ILanguageServerOutputChannel) lsOutputChannel: ILanguageServerOutputChannel,
23+
@inject(IConfigurationService) private readonly configurationService: IConfigurationService,
24+
@inject(IWorkspaceService) private readonly workspace: IWorkspaceService,
1725
) {
1826
super(envVarsProvider, lsOutputChannel);
27+
this.resource = undefined;
28+
}
29+
30+
public async initialize(resource: Resource, interpreter: PythonEnvironment | undefined) {
31+
this.resource = resource;
32+
return super.initialize(resource, interpreter);
33+
}
34+
35+
protected getWorkspaceFolder(): WorkspaceFolder | undefined {
36+
return this.workspace.getWorkspaceFolder(this.resource);
1937
}
2038

2139
protected async getInitializationOptions() {
40+
const pythonSettings = this.configurationService.getSettings(this.resource);
41+
const workspacePath = this.getWorkspaceFolder()?.uri.fsPath;
42+
const extraPaths = pythonSettings.autoComplete
43+
? pythonSettings.autoComplete.extraPaths.map((extraPath) => {
44+
if (path.isAbsolute(extraPath)) {
45+
return extraPath;
46+
}
47+
return workspacePath ? path.join(workspacePath, extraPath) : '';
48+
})
49+
: [];
50+
51+
if (workspacePath) {
52+
extraPaths.unshift(workspacePath);
53+
}
54+
55+
const distinctExtraPaths = extraPaths
56+
.filter((value) => value.length > 0)
57+
.filter((value, index, self) => self.indexOf(value) === index);
58+
2259
return {
2360
markupKindPreferred: 'markdown',
2461
completion: {
@@ -31,6 +68,9 @@ export class JediLanguageServerAnalysisOptions extends LanguageServerAnalysisOpt
3168
didSave: true,
3269
didChange: true,
3370
},
71+
workspace: {
72+
extraPaths: distinctExtraPaths,
73+
},
3474
};
3575
}
3676
}

0 commit comments

Comments
 (0)