Skip to content

Commit

Permalink
Improves linting behavior per #722 (#792)
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

* #385 Auto-Indentation doesn't work after comment

* #141 Auto indentation broken when return keyword involved

* Undo changes

* #627 Docstrings for builtin methods are not parsed correctly

* reStructuredText converter

* Fix: period is not an operator

* Minor fixes

* Restructure

* Tests

* Tests

* Code heuristics

* Baselines

* HTML handling

* Lists

* State machine

* Baselines

* Squash

* no message

* Whitespace difference

* Update Jedi to 0.11.1

* Enable Travis

* Test fixes

* Undo change

* Jedi 0.11 with parser

* Undo changes

* Undo changes

* Test fixes

* Re-lint when interpreter changes

* Re-lint on linter config change

* Run linting command

* Encapsulate jupiter

* Handle promise

* More tests

* Tests

* Use service

* Linter provider tests

* Move methods to documents manager
  • Loading branch information
Mikhail Arkhipov authored Feb 16, 2018
1 parent 5a1452e commit 18be595
Show file tree
Hide file tree
Showing 21 changed files with 570 additions and 279 deletions.
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,11 @@
"command": "python.enableLinting",
"title": "%python.command.python.enableLinting.title%",
"category": "Python"
},
{
"command": "python.runLinting",
"title": "%python.command.python.runLinting.title%",
"category": "Python"
}
],
"menus": {
Expand Down Expand Up @@ -1836,4 +1841,4 @@
"publisherDisplayName": "Microsoft",
"publisherId": "998b010b-e2af-44a5-a6cd-0b5fd3b9b6f8"
}
}
}
51 changes: 26 additions & 25 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,29 @@
"python.command.python.goToPythonObject.title": "Go to Python Object",
"python.command.python.setLinter.title": "Select Linter",
"python.command.python.enableLinting.title": "Enable Linting",
"python.snippet.launch.standard.label": "Python",
"python.snippet.launch.standard.description": "Debug a Python program with standard output",
"python.snippet.launch.pyspark.label": "Python: PySpark",
"python.snippet.launch.pyspark.description": "Debug PySpark",
"python.snippet.launch.module.label": "Python: Module",
"python.snippet.launch.module.description": "Debug a Python Module",
"python.snippet.launch.terminal.label": "Python: Terminal (integrated)",
"python.snippet.launch.terminal.description": "Debug a Python program with Integrated Terminal/Console",
"python.snippet.launch.externalTerminal.label": "Python: Terminal (external)",
"python.snippet.launch.externalTerminal.description": "Debug a Python program with External Terminal/Console",
"python.snippet.launch.django.label": "Python: Django",
"python.snippet.launch.django.description": "Debug a Django Application",
"python.snippet.launch.flask.label": "Python: Flask (0.11.x or later)",
"python.snippet.launch.flask.description": "Debug a Flask Application",
"python.snippet.launch.flaskOld.label": "Python: Flask (0.10.x or earlier)",
"python.snippet.launch.flaskOld.description": "Debug an older styled Flask Application",
"python.snippet.launch.pyramid.label": "Python: Pyramid Application",
"python.snippet.launch.pyramid.description": "Debug a Pyramid Application",
"python.snippet.launch.watson.label": "Python: Watson Application",
"python.snippet.launch.watson.description": "Debug a Watson Application",
"python.snippet.launch.attach.label": "Python: Attach",
"python.snippet.launch.attach.description": "Attach the debugger for remote debugging",
"python.snippet.launch.scrapy.label": "Python: Scrapy",
"python.snippet.launch.scrapy.description": "Scrapy with Integrated Terminal/Console"
}
"python.command.python.runLinting.title": "Run Linting",
"python.snippet.launch.standard.label": "Python",
"python.snippet.launch.standard.description": "Debug a Python program with standard output",
"python.snippet.launch.pyspark.label": "Python: PySpark",
"python.snippet.launch.pyspark.description": "Debug PySpark",
"python.snippet.launch.module.label": "Python: Module",
"python.snippet.launch.module.description": "Debug a Python Module",
"python.snippet.launch.terminal.label": "Python: Terminal (integrated)",
"python.snippet.launch.terminal.description": "Debug a Python program with Integrated Terminal/Console",
"python.snippet.launch.externalTerminal.label": "Python: Terminal (external)",
"python.snippet.launch.externalTerminal.description": "Debug a Python program with External Terminal/Console",
"python.snippet.launch.django.label": "Python: Django",
"python.snippet.launch.django.description": "Debug a Django Application",
"python.snippet.launch.flask.label": "Python: Flask (0.11.x or later)",
"python.snippet.launch.flask.description": "Debug a Flask Application",
"python.snippet.launch.flaskOld.label": "Python: Flask (0.10.x or earlier)",
"python.snippet.launch.flaskOld.description": "Debug an older styled Flask Application",
"python.snippet.launch.pyramid.label": "Python: Pyramid Application",
"python.snippet.launch.pyramid.description": "Debug a Pyramid Application",
"python.snippet.launch.watson.label": "Python: Watson Application",
"python.snippet.launch.watson.description": "Debug a Watson Application",
"python.snippet.launch.attach.label": "Python: Attach",
"python.snippet.launch.attach.description": "Attach the debugger for remote debugging",
"python.snippet.launch.scrapy.label": "Python: Scrapy",
"python.snippet.launch.scrapy.description": "Scrapy with Integrated Terminal/Console"
}
51 changes: 26 additions & 25 deletions package.nls.ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,29 @@
"python.command.python.goToPythonObject.title": "Перейти к объекту Python",
"python.command.python.setLinter.title": "Выбрать анализатор кода",
"python.command.python.enableLinting.title": "Включить анализатор кода",
"python.snippet.launch.standard.label": "Python",
"python.snippet.launch.standard.description": "Отладить программу Python со стандартным выводом",
"python.snippet.launch.pyspark.label": "Python: PySpark",
"python.snippet.launch.pyspark.description": "Отладка PySpark",
"python.snippet.launch.module.label": "Python: Модуль",
"python.snippet.launch.module.description": "Отладка модуля",
"python.snippet.launch.terminal.label": "Python: Интегрированная консоль",
"python.snippet.launch.terminal.description": "Отладка программы Python в интегрированной консоли",
"python.snippet.launch.externalTerminal.label": "Python: Внешний терминал",
"python.snippet.launch.externalTerminal.description": "Отладка программы Python во внешней консоли",
"python.snippet.launch.django.label": "Python: Django",
"python.snippet.launch.django.description": "Отладка приложения Django",
"python.snippet.launch.flask.label": "Python: Flask (0.11.x или новее)",
"python.snippet.launch.flask.description": "Отладка приложения Flask",
"python.snippet.launch.flaskOld.label": "Python: Flask (0.10.x или старее)",
"python.snippet.launch.flaskOld.description": "Отладка приложения Flask (старый стиль)",
"python.snippet.launch.pyramid.label": "Python: Приложение Pyramid",
"python.snippet.launch.pyramid.description": "Отладка приложения Pyramid",
"python.snippet.launch.watson.label": "Python: Приложение Watson",
"python.snippet.launch.watson.description": "Отладка приложения Watson",
"python.snippet.launch.attach.label": "Python: Подключить отладчик",
"python.snippet.launch.attach.description": "Подключить отладчик для удаленной отладки",
"python.snippet.launch.scrapy.label": "Python: Scrapy",
"python.snippet.launch.scrapy.description": "Scrapy в интегрированной консоли"
}
"python.command.python.runLinting.title": "Выполнить анализ кода",
"python.snippet.launch.standard.label": "Python",
"python.snippet.launch.standard.description": "Отладить программу Python со стандартным выводом",
"python.snippet.launch.pyspark.label": "Python: PySpark",
"python.snippet.launch.pyspark.description": "Отладка PySpark",
"python.snippet.launch.module.label": "Python: Модуль",
"python.snippet.launch.module.description": "Отладка модуля",
"python.snippet.launch.terminal.label": "Python: Интегрированная консоль",
"python.snippet.launch.terminal.description": "Отладка программы Python в интегрированной консоли",
"python.snippet.launch.externalTerminal.label": "Python: Внешний терминал",
"python.snippet.launch.externalTerminal.description": "Отладка программы Python во внешней консоли",
"python.snippet.launch.django.label": "Python: Django",
"python.snippet.launch.django.description": "Отладка приложения Django",
"python.snippet.launch.flask.label": "Python: Flask (0.11.x или новее)",
"python.snippet.launch.flask.description": "Отладка приложения Flask",
"python.snippet.launch.flaskOld.label": "Python: Flask (0.10.x или старее)",
"python.snippet.launch.flaskOld.description": "Отладка приложения Flask (старый стиль)",
"python.snippet.launch.pyramid.label": "Python: Приложение Pyramid",
"python.snippet.launch.pyramid.description": "Отладка приложения Pyramid",
"python.snippet.launch.watson.label": "Python: Приложение Watson",
"python.snippet.launch.watson.description": "Отладка приложения Watson",
"python.snippet.launch.attach.label": "Python: Подключить отладчик",
"python.snippet.launch.attach.description": "Подключить отладчик для удаленной отладки",
"python.snippet.launch.scrapy.label": "Python: Scrapy",
"python.snippet.launch.scrapy.description": "Scrapy в интегрированной консоли"
}
9 changes: 9 additions & 0 deletions src/client/common/application/documentManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import { IDocumentManager } from './types';

@injectable()
export class DocumentManager implements IDocumentManager {
public get textDocuments(): TextDocument[] {
return workspace.textDocuments;
}
public get activeTextEditor(): TextEditor | undefined {
return window.activeTextEditor;
}
Expand All @@ -30,6 +33,12 @@ export class DocumentManager implements IDocumentManager {
public get onDidChangeTextEditorViewColumn(): Event<TextEditorViewColumnChangeEvent> {
return window.onDidChangeTextEditorViewColumn;
}
public get onDidOpenTextDocument(): Event<TextDocument> {
return workspace.onDidOpenTextDocument;
}
public get onDidCloseTextDocument(): Event<TextDocument> {
return workspace.onDidCloseTextDocument;
}
public get onDidSaveTextDocument(): Event<TextDocument> {
return workspace.onDidSaveTextDocument;
}
Expand Down
14 changes: 14 additions & 0 deletions src/client/common/application/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,12 @@ export interface ICommandManager {
export const IDocumentManager = Symbol('IDocumentManager');

export interface IDocumentManager {
/**
* All text documents currently known to the system.
*
* @readonly
*/
readonly textDocuments: TextDocument[];
/**
* The currently active editor or `undefined`. The active editor is the one
* that currently has focus or, when none has focus, the one that has changed
Expand Down Expand Up @@ -352,6 +358,14 @@ export interface IDocumentManager {
*/
readonly onDidChangeTextEditorViewColumn: Event<TextEditorViewColumnChangeEvent>;

/**
* An event that is emitted when a [text document](#TextDocument) is opened.
*/
readonly onDidOpenTextDocument: Event<TextDocument>;
/**
* An event that is emitted when a [text document](#TextDocument) is disposed.
*/
readonly onDidCloseTextDocument: Event<TextDocument>;
/**
* An event that is emitted when a [text document](#TextDocument) is saved to disk.
*/
Expand Down
3 changes: 3 additions & 0 deletions src/client/common/application/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,7 @@ export class WorkspaceService implements IWorkspaceService {
public findFiles(include: vscode.GlobPattern, exclude?: vscode.GlobPattern, maxResults?: number, token?: vscode.CancellationToken): Thenable<vscode.Uri[]> {
return vscode.workspace.findFiles(include, exclude, maxResults, token);
}
public get onDidSaveTextDocument(): vscode.Event<vscode.TextDocument> {
return vscode.workspace.onDidSaveTextDocument;
}
}
1 change: 1 addition & 0 deletions src/client/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export namespace Commands {
export const Create_Terminal = 'python.createTerminal';
export const Set_Linter = 'python.setLinter';
export const Enable_Linter = 'python.enableLinting';
export const Run_Linter = 'python.runLinting';
}
export namespace Octicons {
export const Test_Pass = '$(check)';
Expand Down
31 changes: 9 additions & 22 deletions src/client/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ import { registerTypes as interpretersRegisterTypes } from './interpreter/servic
import { ServiceContainer } from './ioc/container';
import { ServiceManager } from './ioc/serviceManager';
import { IServiceContainer } from './ioc/types';
import { JupyterProvider } from './jupyter/provider';
import { JediFactory } from './languageServices/jediProxyFactory';
import { LinterCommands } from './linters/linterCommands';
import { registerTypes as lintersRegisterTypes } from './linters/serviceRegistry';
import { ILintingEngine } from './linters/types';
import { PythonCompletionItemProvider } from './providers/completionProvider';
import { PythonDefinitionProvider } from './providers/definitionProvider';
import { PythonFormattingEditProvider } from './providers/formatProvider';
Expand Down Expand Up @@ -165,29 +165,16 @@ export async function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(vscode.languages.registerDocumentRangeFormattingEditProvider(PYTHON, formatProvider));
}

// tslint:disable-next-line:promise-function-async
const linterProvider = new LinterProvider(context, standardOutputChannel, (a, b) => Promise.resolve(false), serviceContainer);
const linterProvider = new LinterProvider(context, serviceContainer);
context.subscriptions.push(linterProvider);
const jupyterExtInstalled = vscode.extensions.getExtension('donjayamanne.jupyter');
if (jupyterExtInstalled) {
if (jupyterExtInstalled.isActive) {
// tslint:disable-next-line:no-unsafe-any
jupyterExtInstalled.exports.registerLanguageProvider(PYTHON.language, new JupyterProvider());
// tslint:disable-next-line:no-unsafe-any
linterProvider.documentHasJupyterCodeCells = jupyterExtInstalled.exports.hasCodeCells;
}

jupyterExtInstalled.activate().then(() => {
// tslint:disable-next-line:no-unsafe-any
jupyterExtInstalled.exports.registerLanguageProvider(PYTHON.language, new JupyterProvider());
// tslint:disable-next-line:no-unsafe-any
linterProvider.documentHasJupyterCodeCells = jupyterExtInstalled.exports.hasCodeCells;
});
}

const jupyterExtension = vscode.extensions.getExtension('donjayamanne.jupyter');
const lintingEngine = serviceContainer.get<ILintingEngine>(ILintingEngine);
lintingEngine.linkJupiterExtension(jupyterExtension).ignoreErrors();

tests.activate(context, unitTestOutChannel, symbolProvider, serviceContainer);

context.subscriptions.push(new WorkspaceSymbols(serviceContainer));

context.subscriptions.push(vscode.languages.registerOnTypeFormattingEditProvider(PYTHON, new BlockFormatProviders(), ':'));
context.subscriptions.push(vscode.languages.registerOnTypeFormattingEditProvider(PYTHON, new OnEnterFormatter(), '\n'));

Expand All @@ -199,9 +186,9 @@ export async function activate(context: vscode.ExtensionContext) {
// tslint:disable-next-line:no-unused-expression
new BannerService(persistentStateFactory);

const deprecationMgr = new FeatureDeprecationManager(persistentStateFactory, !!jupyterExtInstalled);
const deprecationMgr = new FeatureDeprecationManager(persistentStateFactory, !!jupyterExtension);
deprecationMgr.initialize();
context.subscriptions.push(new FeatureDeprecationManager(persistentStateFactory, !!jupyterExtInstalled));
context.subscriptions.push(new FeatureDeprecationManager(persistentStateFactory, !!jupyterExtension));
}

async function sendStartupTelemetry(activatedPromise: Promise<void>, serviceContainer: IServiceContainer) {
Expand Down
4 changes: 2 additions & 2 deletions src/client/interpreter/contracts.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CodeLensProvider, ConfigurationTarget, Disposable, TextDocument, Uri } from 'vscode';
import { CodeLensProvider, ConfigurationTarget, Disposable, Event, TextDocument, Uri } from 'vscode';
import { Architecture } from '../common/platform/types';

export const INTERPRETER_LOCATOR_SERVICE = 'IInterpreterLocatorService';
Expand Down Expand Up @@ -75,8 +75,8 @@ export type WorkspacePythonPath = {
};

export const IInterpreterService = Symbol('IInterpreterService');

export interface IInterpreterService {
onDidChangeInterpreter: Event<void>;
getInterpreters(resource?: Uri): Promise<PythonInterpreter[]>;
autoSetInterpreter(): Promise<void>;
getActiveInterpreter(resource?: Uri): Promise<PythonInterpreter | undefined>;
Expand Down
9 changes: 1 addition & 8 deletions src/client/interpreter/display/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class InterpreterDisplay implements IInterpreterDisplay {
private readonly configurationService: IConfigurationService;
private readonly helper: IInterpreterHelper;
private readonly workspaceService: IWorkspaceService;
private currentWorkspaceInterpreter?: Uri;

constructor(@inject(IServiceContainer) serviceContainer: IServiceContainer) {
this.interpreterService = serviceContainer.get<IInterpreterService>(IInterpreterService);
this.virtualEnvMgr = serviceContainer.get<IVirtualEnvironmentManager>(IVirtualEnvironmentManager);
Expand Down Expand Up @@ -48,14 +48,7 @@ export class InterpreterDisplay implements IInterpreterDisplay {
}
await this.updateDisplay(resource);
}
private shouldRefresh(workspaceFolder?: Uri) {
if (!workspaceFolder || !this.currentWorkspaceInterpreter) {
return true;
}
return !this.fileSystem.arePathsSame(workspaceFolder.fsPath, this.currentWorkspaceInterpreter.fsPath);
}
private async updateDisplay(workspaceFolder?: Uri) {
this.currentWorkspaceInterpreter = workspaceFolder;
const interpreters = await this.interpreterService.getInterpreters(workspaceFolder);
const interpreter = await this.interpreterService.getActiveInterpreter(workspaceFolder);
const pythonPath = interpreter ? interpreter.path : this.configurationService.getSettings(workspaceFolder).pythonPath;
Expand Down
Loading

0 comments on commit 18be595

Please sign in to comment.