Skip to content

Commit 4372809

Browse files
author
Mikhail Arkhipov
authored
Improve interpreter selection on different platforms (#517)
* Basic tokenizer * Fixed property names * Tests, round I * Tests, round II * tokenizer test * Remove temorary change * Fix merge issue * Merge conflict * Merge conflict * Completion test * Fix last line * Fix javascript math * Make test await for results * Add license headers * Rename definitions to types * License headers * Fix typo in completion details (typo) * Fix hover test * Russian translations * Update to better translation * Fix typo * #70 How to get all parameter info when filling in a function param list * Fix #70 How to get all parameter info when filling in a function param list * Clean up * Clean imports * CR feedback * Trim whitespace for test stability * More tests * Better handle no-parameters documentation * Better handle ellipsis and Python3 * Basic services * Install check * Output installer messages * Warn default Mac OS interpreter * Remove test change * Add tests * PR feedback * CR feedback * Mock process instead * Fix Brew detection * Update test * Add check suppression option & suppress vor VE by default * Fix most linter tests * Merge conflict
1 parent 9853956 commit 4372809

25 files changed

+788
-51
lines changed

package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -919,6 +919,12 @@
919919
},
920920
"scope": "resource"
921921
},
922+
"python.disableInstallationCheck": {
923+
"type": "boolean",
924+
"default": false,
925+
"description": "Whether to check if Python is installed.",
926+
"scope": "resource"
927+
},
922928
"python.linting.enabled": {
923929
"type": "boolean",
924930
"default": true,
@@ -1537,6 +1543,7 @@
15371543
"lodash": "^4.17.4",
15381544
"minimatch": "^3.0.3",
15391545
"named-js-regexp": "^1.3.1",
1546+
"opn": "^5.1.0",
15401547
"reflect-metadata": "^0.1.10",
15411548
"rxjs": "^5.5.2",
15421549
"semver": "^5.4.1",
@@ -1600,6 +1607,7 @@
16001607
"tslint": "^5.7.0",
16011608
"tslint-eslint-rules": "^4.1.1",
16021609
"tslint-microsoft-contrib": "^5.0.1",
1610+
"typemoq": "^2.1.0",
16031611
"typescript": "^2.6.2",
16041612
"typescript-formatter": "^6.0.0",
16051613
"vscode": "^1.1.5",
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
'use strict';
4+
5+
// tslint:disable-next-line:no-require-imports no-var-requires
6+
const opn = require('opn');
7+
8+
import { injectable } from 'inversify';
9+
import * as vscode from 'vscode';
10+
import { IApplicationShell } from './types';
11+
12+
@injectable()
13+
export class ApplicationShell implements IApplicationShell {
14+
public showInformationMessage(message: string, ...items: string[]): Thenable<string> ;
15+
public showInformationMessage(message: string, options: vscode.MessageOptions, ...items: string[]): Thenable<string> ;
16+
public showInformationMessage<T extends vscode.MessageItem>(message: string, ...items: T[]): Thenable<T> ;
17+
public showInformationMessage<T extends vscode.MessageItem>(message: string, options: vscode.MessageOptions, ...items: T[]): Thenable<T> ;
18+
// tslint:disable-next-line:no-any
19+
public showInformationMessage(message: string, options?: any, ...items: any[]): Thenable<any> {
20+
return vscode.window.showInformationMessage(message, options, ...items);
21+
}
22+
23+
public showWarningMessage(message: string, ...items: string[]): Thenable<string>;
24+
public showWarningMessage(message: string, options: vscode.MessageOptions, ...items: string[]): Thenable<string>;
25+
public showWarningMessage<T extends vscode.MessageItem>(message: string, ...items: T[]): Thenable<T>;
26+
public showWarningMessage<T extends vscode.MessageItem>(message: string, options: vscode.MessageOptions, ...items: T[]): Thenable<T>;
27+
// tslint:disable-next-line:no-any
28+
public showWarningMessage(message: any, options?: any, ...items: any[]) {
29+
return vscode.window.showWarningMessage(message, options, ...items);
30+
}
31+
32+
public showErrorMessage(message: string, ...items: string[]): Thenable<string>;
33+
public showErrorMessage(message: string, options: vscode.MessageOptions, ...items: string[]): Thenable<string>;
34+
public showErrorMessage<T extends vscode.MessageItem>(message: string, ...items: T[]): Thenable<T>;
35+
public showErrorMessage<T extends vscode.MessageItem>(message: string, options: vscode.MessageOptions, ...items: T[]): Thenable<T>;
36+
// tslint:disable-next-line:no-any
37+
public showErrorMessage(message: any, options?: any, ...items: any[]) {
38+
return vscode.window.showErrorMessage(message, options, ...items);
39+
}
40+
41+
public showQuickPick(items: string[] | Thenable<string[]>, options?: vscode.QuickPickOptions, token?: vscode.CancellationToken): Thenable<string>;
42+
public showQuickPick<T extends vscode.QuickPickItem>(items: T[] | Thenable<T[]>, options?: vscode.QuickPickOptions, token?: vscode.CancellationToken): Thenable<T>;
43+
// tslint:disable-next-line:no-any
44+
public showQuickPick(items: any, options?: any, token?: any) {
45+
return vscode.window.showQuickPick(items, options, token);
46+
}
47+
48+
public showOpenDialog(options: vscode.OpenDialogOptions): Thenable<vscode.Uri[]> {
49+
return vscode.window.showOpenDialog(options);
50+
}
51+
public showSaveDialog(options: vscode.SaveDialogOptions): Thenable<vscode.Uri> {
52+
return vscode.window.showSaveDialog(options);
53+
}
54+
public showInputBox(options?: vscode.InputBoxOptions, token?: vscode.CancellationToken): Thenable<string> {
55+
return vscode.window.showInputBox(options, token);
56+
}
57+
public openUrl(url: string): void {
58+
opn(url);
59+
}
60+
}
Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
'use strict';
4+
5+
import * as vscode from 'vscode';
6+
7+
export const IApplicationShell = Symbol('IApplicationShell');
8+
export interface IApplicationShell {
9+
showInformationMessage(message: string, ...items: string[]): Thenable<string | undefined>;
10+
11+
/**
12+
* Show an information message to users. Optionally provide an array of items which will be presented as
13+
* clickable buttons.
14+
*
15+
* @param message The message to show.
16+
* @param options Configures the behaviour of the message.
17+
* @param items A set of items that will be rendered as actions in the message.
18+
* @return A thenable that resolves to the selected item or `undefined` when being dismissed.
19+
*/
20+
showInformationMessage(message: string, options: vscode.MessageOptions, ...items: string[]): Thenable<string | undefined>;
21+
22+
/**
23+
* Show an information message.
24+
*
25+
* @see [showInformationMessage](#window.showInformationMessage)
26+
*
27+
* @param message The message to show.
28+
* @param items A set of items that will be rendered as actions in the message.
29+
* @return A thenable that resolves to the selected item or `undefined` when being dismissed.
30+
*/
31+
showInformationMessage<T extends vscode.MessageItem>(message: string, ...items: T[]): Thenable<T | undefined>;
32+
33+
/**
34+
* Show an information message.
35+
*
36+
* @see [showInformationMessage](#window.showInformationMessage)
37+
*
38+
* @param message The message to show.
39+
* @param options Configures the behaviour of the message.
40+
* @param items A set of items that will be rendered as actions in the message.
41+
* @return A thenable that resolves to the selected item or `undefined` when being dismissed.
42+
*/
43+
showInformationMessage<T extends vscode.MessageItem>(message: string, options: vscode.MessageOptions, ...items: T[]): Thenable<T | undefined>;
44+
45+
/**
46+
* Show a warning message.
47+
*
48+
* @see [showInformationMessage](#window.showInformationMessage)
49+
*
50+
* @param message The message to show.
51+
* @param items A set of items that will be rendered as actions in the message.
52+
* @return A thenable that resolves to the selected item or `undefined` when being dismissed.
53+
*/
54+
showWarningMessage(message: string, ...items: string[]): Thenable<string | undefined>;
55+
56+
/**
57+
* Show a warning message.
58+
*
59+
* @see [showInformationMessage](#window.showInformationMessage)
60+
*
61+
* @param message The message to show.
62+
* @param options Configures the behaviour of the message.
63+
* @param items A set of items that will be rendered as actions in the message.
64+
* @return A thenable that resolves to the selected item or `undefined` when being dismissed.
65+
*/
66+
showWarningMessage(message: string, options: vscode.MessageOptions, ...items: string[]): Thenable<string | undefined>;
67+
68+
/**
69+
* Show a warning message.
70+
*
71+
* @see [showInformationMessage](#window.showInformationMessage)
72+
*
73+
* @param message The message to show.
74+
* @param items A set of items that will be rendered as actions in the message.
75+
* @return A thenable that resolves to the selected item or `undefined` when being dismissed.
76+
*/
77+
showWarningMessage<T extends vscode.MessageItem>(message: string, ...items: T[]): Thenable<T | undefined>;
78+
79+
/**
80+
* Show a warning message.
81+
*
82+
* @see [showInformationMessage](#window.showInformationMessage)
83+
*
84+
* @param message The message to show.
85+
* @param options Configures the behaviour of the message.
86+
* @param items A set of items that will be rendered as actions in the message.
87+
* @return A thenable that resolves to the selected item or `undefined` when being dismissed.
88+
*/
89+
showWarningMessage<T extends vscode.MessageItem>(message: string, options: vscode.MessageOptions, ...items: T[]): Thenable<T | undefined>;
90+
91+
/**
92+
* Show an error message.
93+
*
94+
* @see [showInformationMessage](#window.showInformationMessage)
95+
*
96+
* @param message The message to show.
97+
* @param items A set of items that will be rendered as actions in the message.
98+
* @return A thenable that resolves to the selected item or `undefined` when being dismissed.
99+
*/
100+
showErrorMessage(message: string, ...items: string[]): Thenable<string | undefined>;
101+
102+
/**
103+
* Show an error message.
104+
*
105+
* @see [showInformationMessage](#window.showInformationMessage)
106+
*
107+
* @param message The message to show.
108+
* @param options Configures the behaviour of the message.
109+
* @param items A set of items that will be rendered as actions in the message.
110+
* @return A thenable that resolves to the selected item or `undefined` when being dismissed.
111+
*/
112+
showErrorMessage(message: string, options: vscode.MessageOptions, ...items: string[]): Thenable<string | undefined>;
113+
114+
/**
115+
* Show an error message.
116+
*
117+
* @see [showInformationMessage](#window.showInformationMessage)
118+
*
119+
* @param message The message to show.
120+
* @param items A set of items that will be rendered as actions in the message.
121+
* @return A thenable that resolves to the selected item or `undefined` when being dismissed.
122+
*/
123+
showErrorMessage<T extends vscode.MessageItem>(message: string, ...items: T[]): Thenable<T | undefined>;
124+
125+
/**
126+
* Show an error message.
127+
*
128+
* @see [showInformationMessage](#window.showInformationMessage)
129+
*
130+
* @param message The message to show.
131+
* @param options Configures the behaviour of the message.
132+
* @param items A set of items that will be rendered as actions in the message.
133+
* @return A thenable that resolves to the selected item or `undefined` when being dismissed.
134+
*/
135+
showErrorMessage<T extends vscode.MessageItem>(message: string, options: vscode.MessageOptions, ...items: T[]): Thenable<T | undefined>;
136+
137+
/**
138+
* Shows a selection list.
139+
*
140+
* @param items An array of strings, or a promise that resolves to an array of strings.
141+
* @param options Configures the behavior of the selection list.
142+
* @param token A token that can be used to signal cancellation.
143+
* @return A promise that resolves to the selection or `undefined`.
144+
*/
145+
showQuickPick(items: string[] | Thenable<string[]>, options?: vscode.QuickPickOptions, token?: vscode.CancellationToken): Thenable<string | undefined>;
146+
147+
/**
148+
* Shows a selection list.
149+
*
150+
* @param items An array of items, or a promise that resolves to an array of items.
151+
* @param options Configures the behavior of the selection list.
152+
* @param token A token that can be used to signal cancellation.
153+
* @return A promise that resolves to the selected item or `undefined`.
154+
*/
155+
showQuickPick<T extends vscode.QuickPickItem>(items: T[] | Thenable<T[]>, options?: vscode.QuickPickOptions, token?: vscode.CancellationToken): Thenable<T | undefined>;
156+
157+
/**
158+
* Shows a file open dialog to the user which allows to select a file
159+
* for opening-purposes.
160+
*
161+
* @param options Options that control the dialog.
162+
* @returns A promise that resolves to the selected resources or `undefined`.
163+
*/
164+
showOpenDialog(options: vscode.OpenDialogOptions): Thenable<vscode.Uri[] | undefined>;
165+
166+
/**
167+
* Shows a file save dialog to the user which allows to select a file
168+
* for saving-purposes.
169+
*
170+
* @param options Options that control the dialog.
171+
* @returns A promise that resolves to the selected resource or `undefined`.
172+
*/
173+
showSaveDialog(options: vscode.SaveDialogOptions): Thenable<vscode.Uri | undefined>;
174+
175+
/**
176+
* Opens an input box to ask the user for input.
177+
*
178+
* The returned value will be `undefined` if the input box was canceled (e.g. pressing ESC). Otherwise the
179+
* returned value will be the string typed by the user or an empty string if the user did not type
180+
* anything but dismissed the input box with OK.
181+
*
182+
* @param options Configures the behavior of the input box.
183+
* @param token A token that can be used to signal cancellation.
184+
* @return A promise that resolves to a string the user provided or to `undefined` in case of dismissal.
185+
*/
186+
showInputBox(options?: vscode.InputBoxOptions, token?: vscode.CancellationToken): Thenable<string | undefined>;
187+
188+
/**
189+
* Opens URL in a default browser.
190+
*
191+
* @param url Url to open.
192+
*/
193+
openUrl(url: string): void;
194+
}

src/client/common/configSettings.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export interface IPythonSettings {
2626
workspaceSymbols: IWorkspaceSymbolSettings;
2727
envFile: string;
2828
disablePromptForFeatures: string[];
29+
disableInstallationChecks: boolean;
2930
}
3031
export interface ISortImportSettings {
3132
path: string;
@@ -145,6 +146,7 @@ export class PythonSettings extends EventEmitter implements IPythonSettings {
145146
public terminal: ITerminalSettings;
146147
public sortImports: ISortImportSettings;
147148
public workspaceSymbols: IWorkspaceSymbolSettings;
149+
public disableInstallationChecks: boolean;
148150

149151
private workspaceRoot: vscode.Uri;
150152
private disposables: vscode.Disposable[] = [];
@@ -222,6 +224,7 @@ export class PythonSettings extends EventEmitter implements IPythonSettings {
222224
} else {
223225
this.linting = lintingSettings;
224226
}
227+
this.disableInstallationChecks = pythonSettings.get<boolean>('disableInstallationCheck') === true;
225228
// tslint:disable-next-line:no-backbone-get-set-outside-model no-non-null-assertion
226229
const sortImportSettings = systemVariables.resolveAny(pythonSettings.get<ISortImportSettings>('sortImports'))!;
227230
if (this.sortImports) {

src/client/common/installer/installer.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { ILinterHelper } from '../../linters/types';
99
import { ITestsHelper } from '../../unittests/common/types';
1010
import { PythonSettings } from '../configSettings';
1111
import { STANDARD_OUTPUT_CHANNEL } from '../constants';
12+
import { IPlatformService } from '../platform/types';
1213
import { IProcessService, IPythonExecutionFactory } from '../process/types';
1314
import { ITerminalService } from '../terminal/types';
1415
import { IInstaller, ILogger, InstallerResponse, IOutputChannel, IsWindows, ModuleNamePurpose, Product } from '../types';
@@ -82,8 +83,7 @@ ProductTypes.set(Product.rope, ProductType.RefactoringLibrary);
8283
@injectable()
8384
export class Installer implements IInstaller {
8485
constructor( @inject(IServiceContainer) private serviceContainer: IServiceContainer,
85-
@inject(IOutputChannel) @named(STANDARD_OUTPUT_CHANNEL) private outputChannel: vscode.OutputChannel,
86-
@inject(IsWindows) private isWindows: boolean) {
86+
@inject(IOutputChannel) @named(STANDARD_OUTPUT_CHANNEL) private outputChannel: vscode.OutputChannel) {
8787
}
8888
// tslint:disable-next-line:no-empty
8989
public dispose() { }
@@ -229,7 +229,7 @@ export class Installer implements IInstaller {
229229
return disablePromptForFeatures.indexOf(productName) === -1;
230230
}
231231
private installCTags() {
232-
if (this.isWindows) {
232+
if (this.serviceContainer.get<IPlatformService>(IPlatformService).isWindows) {
233233
this.outputChannel.appendLine('Install Universal Ctags Win32 to enable support for Workspace Symbols');
234234
this.outputChannel.appendLine('Download the CTags binary from the Universal CTags site.');
235235
this.outputChannel.appendLine('Option 1: Extract ctags.exe from the downloaded zip to any folder within your PATH so that Visual Studio Code can run it.');

0 commit comments

Comments
 (0)