Skip to content

Commit

Permalink
Improve interpreter selection on different platforms (#517)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Mikhail Arkhipov authored Jan 4, 2018
1 parent 9853956 commit 4372809
Show file tree
Hide file tree
Showing 25 changed files with 788 additions and 51 deletions.
8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,12 @@
},
"scope": "resource"
},
"python.disableInstallationCheck": {
"type": "boolean",
"default": false,
"description": "Whether to check if Python is installed.",
"scope": "resource"
},
"python.linting.enabled": {
"type": "boolean",
"default": true,
Expand Down Expand Up @@ -1537,6 +1543,7 @@
"lodash": "^4.17.4",
"minimatch": "^3.0.3",
"named-js-regexp": "^1.3.1",
"opn": "^5.1.0",
"reflect-metadata": "^0.1.10",
"rxjs": "^5.5.2",
"semver": "^5.4.1",
Expand Down Expand Up @@ -1600,6 +1607,7 @@
"tslint": "^5.7.0",
"tslint-eslint-rules": "^4.1.1",
"tslint-microsoft-contrib": "^5.0.1",
"typemoq": "^2.1.0",
"typescript": "^2.6.2",
"typescript-formatter": "^6.0.0",
"vscode": "^1.1.5",
Expand Down
60 changes: 60 additions & 0 deletions src/client/common/application/applicationShell.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';

// tslint:disable-next-line:no-require-imports no-var-requires
const opn = require('opn');

import { injectable } from 'inversify';
import * as vscode from 'vscode';
import { IApplicationShell } from './types';

@injectable()
export class ApplicationShell implements IApplicationShell {
public showInformationMessage(message: string, ...items: string[]): Thenable<string> ;
public showInformationMessage(message: string, options: vscode.MessageOptions, ...items: string[]): Thenable<string> ;
public showInformationMessage<T extends vscode.MessageItem>(message: string, ...items: T[]): Thenable<T> ;
public showInformationMessage<T extends vscode.MessageItem>(message: string, options: vscode.MessageOptions, ...items: T[]): Thenable<T> ;
// tslint:disable-next-line:no-any
public showInformationMessage(message: string, options?: any, ...items: any[]): Thenable<any> {
return vscode.window.showInformationMessage(message, options, ...items);
}

public showWarningMessage(message: string, ...items: string[]): Thenable<string>;
public showWarningMessage(message: string, options: vscode.MessageOptions, ...items: string[]): Thenable<string>;
public showWarningMessage<T extends vscode.MessageItem>(message: string, ...items: T[]): Thenable<T>;
public showWarningMessage<T extends vscode.MessageItem>(message: string, options: vscode.MessageOptions, ...items: T[]): Thenable<T>;
// tslint:disable-next-line:no-any
public showWarningMessage(message: any, options?: any, ...items: any[]) {
return vscode.window.showWarningMessage(message, options, ...items);
}

public showErrorMessage(message: string, ...items: string[]): Thenable<string>;
public showErrorMessage(message: string, options: vscode.MessageOptions, ...items: string[]): Thenable<string>;
public showErrorMessage<T extends vscode.MessageItem>(message: string, ...items: T[]): Thenable<T>;
public showErrorMessage<T extends vscode.MessageItem>(message: string, options: vscode.MessageOptions, ...items: T[]): Thenable<T>;
// tslint:disable-next-line:no-any
public showErrorMessage(message: any, options?: any, ...items: any[]) {
return vscode.window.showErrorMessage(message, options, ...items);
}

public showQuickPick(items: string[] | Thenable<string[]>, options?: vscode.QuickPickOptions, token?: vscode.CancellationToken): Thenable<string>;
public showQuickPick<T extends vscode.QuickPickItem>(items: T[] | Thenable<T[]>, options?: vscode.QuickPickOptions, token?: vscode.CancellationToken): Thenable<T>;
// tslint:disable-next-line:no-any
public showQuickPick(items: any, options?: any, token?: any) {
return vscode.window.showQuickPick(items, options, token);
}

public showOpenDialog(options: vscode.OpenDialogOptions): Thenable<vscode.Uri[]> {
return vscode.window.showOpenDialog(options);
}
public showSaveDialog(options: vscode.SaveDialogOptions): Thenable<vscode.Uri> {
return vscode.window.showSaveDialog(options);
}
public showInputBox(options?: vscode.InputBoxOptions, token?: vscode.CancellationToken): Thenable<string> {
return vscode.window.showInputBox(options, token);
}
public openUrl(url: string): void {
opn(url);
}
}
194 changes: 194 additions & 0 deletions src/client/common/application/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';

import * as vscode from 'vscode';

export const IApplicationShell = Symbol('IApplicationShell');
export interface IApplicationShell {
showInformationMessage(message: string, ...items: string[]): Thenable<string | undefined>;

/**
* Show an information message to users. Optionally provide an array of items which will be presented as
* clickable buttons.
*
* @param message The message to show.
* @param options Configures the behaviour of the message.
* @param items A set of items that will be rendered as actions in the message.
* @return A thenable that resolves to the selected item or `undefined` when being dismissed.
*/
showInformationMessage(message: string, options: vscode.MessageOptions, ...items: string[]): Thenable<string | undefined>;

/**
* Show an information message.
*
* @see [showInformationMessage](#window.showInformationMessage)
*
* @param message The message to show.
* @param items A set of items that will be rendered as actions in the message.
* @return A thenable that resolves to the selected item or `undefined` when being dismissed.
*/
showInformationMessage<T extends vscode.MessageItem>(message: string, ...items: T[]): Thenable<T | undefined>;

/**
* Show an information message.
*
* @see [showInformationMessage](#window.showInformationMessage)
*
* @param message The message to show.
* @param options Configures the behaviour of the message.
* @param items A set of items that will be rendered as actions in the message.
* @return A thenable that resolves to the selected item or `undefined` when being dismissed.
*/
showInformationMessage<T extends vscode.MessageItem>(message: string, options: vscode.MessageOptions, ...items: T[]): Thenable<T | undefined>;

/**
* Show a warning message.
*
* @see [showInformationMessage](#window.showInformationMessage)
*
* @param message The message to show.
* @param items A set of items that will be rendered as actions in the message.
* @return A thenable that resolves to the selected item or `undefined` when being dismissed.
*/
showWarningMessage(message: string, ...items: string[]): Thenable<string | undefined>;

/**
* Show a warning message.
*
* @see [showInformationMessage](#window.showInformationMessage)
*
* @param message The message to show.
* @param options Configures the behaviour of the message.
* @param items A set of items that will be rendered as actions in the message.
* @return A thenable that resolves to the selected item or `undefined` when being dismissed.
*/
showWarningMessage(message: string, options: vscode.MessageOptions, ...items: string[]): Thenable<string | undefined>;

/**
* Show a warning message.
*
* @see [showInformationMessage](#window.showInformationMessage)
*
* @param message The message to show.
* @param items A set of items that will be rendered as actions in the message.
* @return A thenable that resolves to the selected item or `undefined` when being dismissed.
*/
showWarningMessage<T extends vscode.MessageItem>(message: string, ...items: T[]): Thenable<T | undefined>;

/**
* Show a warning message.
*
* @see [showInformationMessage](#window.showInformationMessage)
*
* @param message The message to show.
* @param options Configures the behaviour of the message.
* @param items A set of items that will be rendered as actions in the message.
* @return A thenable that resolves to the selected item or `undefined` when being dismissed.
*/
showWarningMessage<T extends vscode.MessageItem>(message: string, options: vscode.MessageOptions, ...items: T[]): Thenable<T | undefined>;

/**
* Show an error message.
*
* @see [showInformationMessage](#window.showInformationMessage)
*
* @param message The message to show.
* @param items A set of items that will be rendered as actions in the message.
* @return A thenable that resolves to the selected item or `undefined` when being dismissed.
*/
showErrorMessage(message: string, ...items: string[]): Thenable<string | undefined>;

/**
* Show an error message.
*
* @see [showInformationMessage](#window.showInformationMessage)
*
* @param message The message to show.
* @param options Configures the behaviour of the message.
* @param items A set of items that will be rendered as actions in the message.
* @return A thenable that resolves to the selected item or `undefined` when being dismissed.
*/
showErrorMessage(message: string, options: vscode.MessageOptions, ...items: string[]): Thenable<string | undefined>;

/**
* Show an error message.
*
* @see [showInformationMessage](#window.showInformationMessage)
*
* @param message The message to show.
* @param items A set of items that will be rendered as actions in the message.
* @return A thenable that resolves to the selected item or `undefined` when being dismissed.
*/
showErrorMessage<T extends vscode.MessageItem>(message: string, ...items: T[]): Thenable<T | undefined>;

/**
* Show an error message.
*
* @see [showInformationMessage](#window.showInformationMessage)
*
* @param message The message to show.
* @param options Configures the behaviour of the message.
* @param items A set of items that will be rendered as actions in the message.
* @return A thenable that resolves to the selected item or `undefined` when being dismissed.
*/
showErrorMessage<T extends vscode.MessageItem>(message: string, options: vscode.MessageOptions, ...items: T[]): Thenable<T | undefined>;

/**
* Shows a selection list.
*
* @param items An array of strings, or a promise that resolves to an array of strings.
* @param options Configures the behavior of the selection list.
* @param token A token that can be used to signal cancellation.
* @return A promise that resolves to the selection or `undefined`.
*/
showQuickPick(items: string[] | Thenable<string[]>, options?: vscode.QuickPickOptions, token?: vscode.CancellationToken): Thenable<string | undefined>;

/**
* Shows a selection list.
*
* @param items An array of items, or a promise that resolves to an array of items.
* @param options Configures the behavior of the selection list.
* @param token A token that can be used to signal cancellation.
* @return A promise that resolves to the selected item or `undefined`.
*/
showQuickPick<T extends vscode.QuickPickItem>(items: T[] | Thenable<T[]>, options?: vscode.QuickPickOptions, token?: vscode.CancellationToken): Thenable<T | undefined>;

/**
* Shows a file open dialog to the user which allows to select a file
* for opening-purposes.
*
* @param options Options that control the dialog.
* @returns A promise that resolves to the selected resources or `undefined`.
*/
showOpenDialog(options: vscode.OpenDialogOptions): Thenable<vscode.Uri[] | undefined>;

/**
* Shows a file save dialog to the user which allows to select a file
* for saving-purposes.
*
* @param options Options that control the dialog.
* @returns A promise that resolves to the selected resource or `undefined`.
*/
showSaveDialog(options: vscode.SaveDialogOptions): Thenable<vscode.Uri | undefined>;

/**
* Opens an input box to ask the user for input.
*
* The returned value will be `undefined` if the input box was canceled (e.g. pressing ESC). Otherwise the
* returned value will be the string typed by the user or an empty string if the user did not type
* anything but dismissed the input box with OK.
*
* @param options Configures the behavior of the input box.
* @param token A token that can be used to signal cancellation.
* @return A promise that resolves to a string the user provided or to `undefined` in case of dismissal.
*/
showInputBox(options?: vscode.InputBoxOptions, token?: vscode.CancellationToken): Thenable<string | undefined>;

/**
* Opens URL in a default browser.
*
* @param url Url to open.
*/
openUrl(url: string): void;
}
3 changes: 3 additions & 0 deletions src/client/common/configSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface IPythonSettings {
workspaceSymbols: IWorkspaceSymbolSettings;
envFile: string;
disablePromptForFeatures: string[];
disableInstallationChecks: boolean;
}
export interface ISortImportSettings {
path: string;
Expand Down Expand Up @@ -145,6 +146,7 @@ export class PythonSettings extends EventEmitter implements IPythonSettings {
public terminal: ITerminalSettings;
public sortImports: ISortImportSettings;
public workspaceSymbols: IWorkspaceSymbolSettings;
public disableInstallationChecks: boolean;

private workspaceRoot: vscode.Uri;
private disposables: vscode.Disposable[] = [];
Expand Down Expand Up @@ -222,6 +224,7 @@ export class PythonSettings extends EventEmitter implements IPythonSettings {
} else {
this.linting = lintingSettings;
}
this.disableInstallationChecks = pythonSettings.get<boolean>('disableInstallationCheck') === true;
// tslint:disable-next-line:no-backbone-get-set-outside-model no-non-null-assertion
const sortImportSettings = systemVariables.resolveAny(pythonSettings.get<ISortImportSettings>('sortImports'))!;
if (this.sortImports) {
Expand Down
6 changes: 3 additions & 3 deletions src/client/common/installer/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { ILinterHelper } from '../../linters/types';
import { ITestsHelper } from '../../unittests/common/types';
import { PythonSettings } from '../configSettings';
import { STANDARD_OUTPUT_CHANNEL } from '../constants';
import { IPlatformService } from '../platform/types';
import { IProcessService, IPythonExecutionFactory } from '../process/types';
import { ITerminalService } from '../terminal/types';
import { IInstaller, ILogger, InstallerResponse, IOutputChannel, IsWindows, ModuleNamePurpose, Product } from '../types';
Expand Down Expand Up @@ -82,8 +83,7 @@ ProductTypes.set(Product.rope, ProductType.RefactoringLibrary);
@injectable()
export class Installer implements IInstaller {
constructor( @inject(IServiceContainer) private serviceContainer: IServiceContainer,
@inject(IOutputChannel) @named(STANDARD_OUTPUT_CHANNEL) private outputChannel: vscode.OutputChannel,
@inject(IsWindows) private isWindows: boolean) {
@inject(IOutputChannel) @named(STANDARD_OUTPUT_CHANNEL) private outputChannel: vscode.OutputChannel) {
}
// tslint:disable-next-line:no-empty
public dispose() { }
Expand Down Expand Up @@ -229,7 +229,7 @@ export class Installer implements IInstaller {
return disablePromptForFeatures.indexOf(productName) === -1;
}
private installCTags() {
if (this.isWindows) {
if (this.serviceContainer.get<IPlatformService>(IPlatformService).isWindows) {
this.outputChannel.appendLine('Install Universal Ctags Win32 to enable support for Workspace Symbols');
this.outputChannel.appendLine('Download the CTags binary from the Universal CTags site.');
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.');
Expand Down
Loading

0 comments on commit 4372809

Please sign in to comment.