Skip to content

Commit d84a11e

Browse files
authored
Expose api to get display list of interpreters (#8868)
* Expose api to get display list of interpreters * Fix imports * Fix tests
1 parent 3b98053 commit d84a11e

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

src/client/interpreter/configuration/interpreterSelector.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
import { inject, injectable } from 'inversify';
2-
import { ConfigurationTarget, Disposable, QuickPickItem, QuickPickOptions, Uri } from 'vscode';
2+
import { ConfigurationTarget, Disposable, QuickPickOptions, Uri } from 'vscode';
33
import { IApplicationShell, ICommandManager, IDocumentManager, IWorkspaceService } from '../../common/application/types';
44
import { Commands } from '../../common/constants';
5-
import { IConfigurationService, IPathUtils } from '../../common/types';
5+
import { IConfigurationService, IPathUtils, Resource } from '../../common/types';
66
import { IInterpreterService, IShebangCodeLensProvider, PythonInterpreter, WorkspacePythonPath } from '../contracts';
7-
import { IInterpreterComparer, IInterpreterSelector, IPythonPathUpdaterServiceManager } from './types';
8-
9-
export interface IInterpreterQuickPickItem extends QuickPickItem {
10-
path: string;
11-
}
7+
import { IInterpreterComparer, IInterpreterQuickPickItem, IInterpreterSelector, IPythonPathUpdaterServiceManager } from './types';
128

139
@injectable()
1410
export class InterpreterSelector implements IInterpreterSelector {
@@ -34,10 +30,10 @@ export class InterpreterSelector implements IInterpreterSelector {
3430
this.disposables.push(this.commandManager.registerCommand(Commands.Set_ShebangInterpreter, this.setShebangInterpreter.bind(this)));
3531
}
3632

37-
public async getSuggestions(resourceUri?: Uri) {
38-
const interpreters = await this.interpreterManager.getInterpreters(resourceUri);
33+
public async getSuggestions(resource: Resource) {
34+
const interpreters = await this.interpreterManager.getInterpreters(resource);
3935
interpreters.sort(this.interpreterComparer.compare.bind(this.interpreterComparer));
40-
return Promise.all(interpreters.map(item => this.suggestionToQuickPickItem(item, resourceUri)));
36+
return Promise.all(interpreters.map(item => this.suggestionToQuickPickItem(item, resource)));
4137
}
4238
protected async suggestionToQuickPickItem(suggestion: PythonInterpreter, workspaceUri?: Uri): Promise<IInterpreterQuickPickItem> {
4339
const detail = this.pathUtils.getDisplayName(suggestion.path, workspaceUri ? workspaceUri.fsPath : undefined);

src/client/interpreter/configuration/types.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { ConfigurationTarget, Disposable, Uri } from 'vscode';
1+
import { ConfigurationTarget, Disposable, QuickPickItem, Uri } from 'vscode';
2+
import { Resource } from '../../common/types';
23
import { PythonInterpreter } from '../contracts';
34

45
export interface IPythonPathUpdaterService {
@@ -20,6 +21,11 @@ export interface IPythonPathUpdaterServiceManager {
2021
export const IInterpreterSelector = Symbol('IInterpreterSelector');
2122
export interface IInterpreterSelector extends Disposable {
2223
initialize(): void;
24+
getSuggestions(resource: Resource): Promise<IInterpreterQuickPickItem[]>;
25+
}
26+
27+
export interface IInterpreterQuickPickItem extends QuickPickItem {
28+
path: string;
2329
}
2430

2531
export const IInterpreterComparer = Symbol('IInterpreterComparer');

src/test/configuration/interpreterSelector.unit.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import { PathUtils } from '../../client/common/platform/pathUtils';
1010
import { IFileSystem } from '../../client/common/platform/types';
1111
import { IConfigurationService, IPythonSettings } from '../../client/common/types';
1212
import { Architecture } from '../../client/common/utils/platform';
13-
import { IInterpreterQuickPickItem, InterpreterSelector } from '../../client/interpreter/configuration/interpreterSelector';
14-
import { IInterpreterComparer, IPythonPathUpdaterServiceManager } from '../../client/interpreter/configuration/types';
13+
import { InterpreterSelector } from '../../client/interpreter/configuration/interpreterSelector';
14+
import { IInterpreterComparer, IInterpreterQuickPickItem, IPythonPathUpdaterServiceManager } from '../../client/interpreter/configuration/types';
1515
import { IInterpreterService, InterpreterType, IShebangCodeLensProvider, PythonInterpreter } from '../../client/interpreter/contracts';
1616

1717
const info: PythonInterpreter = {
@@ -107,7 +107,7 @@ suite('Interpreters - selector', () => {
107107
.setup(x => x.getInterpreters(TypeMoq.It.isAny()))
108108
.returns(() => new Promise((resolve) => resolve(initial)));
109109

110-
const actual = await selector.getSuggestions();
110+
const actual = await selector.getSuggestions(undefined);
111111

112112
const expected: InterpreterQuickPickItem[] = [
113113
new InterpreterQuickPickItem('1', 'c:/path1/path1'),

0 commit comments

Comments
 (0)