From b695fafaaf219af5a054572ab09a4977cf66d2df Mon Sep 17 00:00:00 2001 From: Mikhail Bulash Date: Sat, 7 Sep 2019 10:22:53 +0300 Subject: [PATCH] Remove `donjayamanne.jupyter` integration --- news/3 Code Health/6052.md | 2 + src/client/common/constants.ts | 12 ---- src/client/extension.ts | 6 -- src/client/jupyter/provider.ts | 93 ----------------------------- src/client/linters/lintingEngine.ts | 33 +--------- src/client/linters/types.ts | 2 - 6 files changed, 3 insertions(+), 145 deletions(-) create mode 100644 news/3 Code Health/6052.md delete mode 100644 src/client/jupyter/provider.ts diff --git a/news/3 Code Health/6052.md b/news/3 Code Health/6052.md new file mode 100644 index 000000000000..f1b9990e584a --- /dev/null +++ b/news/3 Code Health/6052.md @@ -0,0 +1,2 @@ +Remove `donjamayanne.jupyter` integration +(thanks [Mikhail Bulash](https://github.com/mikeroll/)) diff --git a/src/client/common/constants.ts b/src/client/common/constants.ts index fce024edb363..a7efe37de0e3 100644 --- a/src/client/common/constants.ts +++ b/src/client/common/constants.ts @@ -78,18 +78,6 @@ export namespace Delays { export const MaxUnitTestCodeLensDelay = 5000; } -export namespace LinterErrors { - export namespace pylint { - export const InvalidSyntax = 'E0001'; - } - export namespace prospector { - export const InvalidSyntax = 'F999'; - } - export namespace flake8 { - export const InvalidSyntax = 'E999'; - } -} - export const STANDARD_OUTPUT_CHANNEL = 'STANDARD_OUTPUT_CHANNEL'; export function isTestExecution(): boolean { diff --git a/src/client/extension.ts b/src/client/extension.ts index 72ee0b1f0e7e..cdaac6adf599 100644 --- a/src/client/extension.ts +++ b/src/client/extension.ts @@ -24,7 +24,6 @@ import { DebugConfigurationProvider, Disposable, ExtensionContext, - extensions, languages, Memento, OutputChannel, @@ -88,7 +87,6 @@ import { IServiceContainer, IServiceManager } from './ioc/types'; import { getLanguageConfiguration } from './language/languageConfiguration'; import { LinterCommands } from './linters/linterCommands'; import { registerTypes as lintersRegisterTypes } from './linters/serviceRegistry'; -import { ILintingEngine } from './linters/types'; import { PythonCodeActionProvider } from './providers/codeActionsProvider'; import { PythonFormattingEditProvider } from './providers/formatProvider'; import { LinterProvider } from './providers/linterProvider'; @@ -157,10 +155,6 @@ async function activateUnsafe(context: ExtensionContext): Promise interpreterManager.refresh(workspaceService.hasWorkspaceFolders ? workspaceService.workspaceFolders![0].uri : undefined) .catch(ex => traceError('Python Extension: interpreterManager.refresh', ex)); - const jupyterExtension = extensions.getExtension('donjayamanne.jupyter'); - const lintingEngine = serviceManager.get(ILintingEngine); - lintingEngine.linkJupyterExtension(jupyterExtension).ignoreErrors(); - // Activate debug location tracker serviceManager.get(IDebugLocationTrackerFactory); diff --git a/src/client/jupyter/provider.ts b/src/client/jupyter/provider.ts deleted file mode 100644 index e2408b1a78b3..000000000000 --- a/src/client/jupyter/provider.ts +++ /dev/null @@ -1,93 +0,0 @@ -import { Position, Range, TextDocument, window } from 'vscode'; - -export class JupyterProvider { - private static isCodeBlock(code: string): boolean { - return code.trim().endsWith(':') && code.indexOf('#') === -1; - } - - /** - * Returns a Regular Expression used to determine whether a line is a Cell delimiter or not - * - * @type {RegExp} - * @memberOf LanguageProvider - */ - get cellIdentifier(): RegExp { - return /^(# %%|#%%|# \|# In\[\d*?\]|# In\[ \])(.*)/i; - } - - /** - * Returns the selected code - * If not implemented, then the currently active line or selected code is taken. - * Can be implemented to ensure valid blocks of code are selected. - * E.g if user selects only the If statement, code can be impelemented to ensure all code within the if statement (block) is returned - * @param {string} selectedCode The selected code as identified by this extension. - * @param {Range} [currentCell] Range of the currently active cell - * @returns {Promise} The code selected. If nothing is to be done, return the parameter value. - * - * @memberOf LanguageProvider - */ - // @ts-ignore - public getSelectedCode(selectedCode: string, currentCell?: Range): Promise { - if (!JupyterProvider.isCodeBlock(selectedCode)) { - return Promise.resolve(selectedCode); - } - - // ok we're in a block, look for the end of the block until the last line in the cell (if there are any cells) - return new Promise((resolve, _reject) => { - const activeEditor = window.activeTextEditor; - if (!activeEditor) { - return resolve(''); - } - const endLineNumber = currentCell ? currentCell.end.line : activeEditor.document.lineCount - 1; - const startIndent = selectedCode.indexOf(selectedCode.trim()); - const nextStartLine = activeEditor.selection.start.line + 1; - - for (let lineNumber = nextStartLine; lineNumber <= endLineNumber; lineNumber += 1) { - const line = activeEditor.document.lineAt(lineNumber); - const nextLine = line.text; - const nextLineIndent = nextLine.indexOf(nextLine.trim()); - if (nextLine.trim().indexOf('#') === 0) { - continue; - } - if (nextLineIndent === startIndent) { - // Return code until previous line - const endRange = activeEditor.document.lineAt(lineNumber - 1).range.end; - resolve(activeEditor.document.getText(new Range(activeEditor.selection.start, endRange))); - } - } - - resolve(activeEditor.document.getText(currentCell)); - }); - } - - /** - * Gets the first line (position) of executable code within a range - * - * @param {TextDocument} document - * @param {number} startLine - * @param {number} endLine - * @returns {Promise} - * - * @memberOf LanguageProvider - */ - public getFirstLineOfExecutableCode(document: TextDocument, range: Range): Promise { - for (let lineNumber = range.start.line; lineNumber < range.end.line; lineNumber += 1) { - const line = document.lineAt(lineNumber); - if (line.isEmptyOrWhitespace) { - continue; - } - const lineText = line.text; - const trimmedLine = lineText.trim(); - if (trimmedLine.startsWith('#')) { - continue; - } - // Yay we have a line - // Remember, we need to set the cursor to a character other than white space - // Highlighting doesn't kick in for comments or white space - return Promise.resolve(new Position(lineNumber, lineText.indexOf(trimmedLine))); - } - - // give up - return Promise.resolve(new Position(range.start.line, 0)); - } -} diff --git a/src/client/linters/lintingEngine.ts b/src/client/linters/lintingEngine.ts index fd1aa312147c..6020fe64d977 100644 --- a/src/client/linters/lintingEngine.ts +++ b/src/client/linters/lintingEngine.ts @@ -8,12 +8,11 @@ import { Minimatch } from 'minimatch'; import * as path from 'path'; import * as vscode from 'vscode'; import { IDocumentManager, IWorkspaceService } from '../common/application/types'; -import { LinterErrors, STANDARD_OUTPUT_CHANNEL } from '../common/constants'; +import { STANDARD_OUTPUT_CHANNEL } from '../common/constants'; import { IFileSystem } from '../common/platform/types'; import { IConfigurationService, IOutputChannel } from '../common/types'; import { StopWatch } from '../common/utils/stopWatch'; import { IServiceContainer } from '../ioc/types'; -import { JupyterProvider } from '../jupyter/provider'; import { sendTelemetryWhenDone } from '../telemetry'; import { EventName } from '../telemetry/constants'; import { LinterTrigger, LintingTelemetry } from '../telemetry/types'; @@ -27,15 +26,8 @@ lintSeverityToVSSeverity.set(LintMessageSeverity.Hint, vscode.DiagnosticSeverity lintSeverityToVSSeverity.set(LintMessageSeverity.Information, vscode.DiagnosticSeverity.Information); lintSeverityToVSSeverity.set(LintMessageSeverity.Warning, vscode.DiagnosticSeverity.Warning); -// tslint:disable-next-line:interface-name -interface DocumentHasJupyterCodeCells { - // tslint:disable-next-line:callable-types - (doc: vscode.TextDocument, token: vscode.CancellationToken): Promise; -} - @injectable() export class LintingEngine implements ILintingEngine { - private documentHasJupyterCodeCells: DocumentHasJupyterCodeCells; private workspace: IWorkspaceService; private documents: IDocumentManager; private configurationService: IConfigurationService; @@ -46,7 +38,6 @@ export class LintingEngine implements ILintingEngine { private fileSystem: IFileSystem; constructor(@inject(IServiceContainer) private serviceContainer: IServiceContainer) { - this.documentHasJupyterCodeCells = (_a, _b) => Promise.resolve(false); this.documents = serviceContainer.get(IDocumentManager); this.workspace = serviceContainer.get(IWorkspaceService); this.configurationService = serviceContainer.get(IConfigurationService); @@ -110,7 +101,6 @@ export class LintingEngine implements ILintingEngine { return promise; }); - const hasJupyterCodeCells = await this.documentHasJupyterCodeCells(document, cancelToken.token); // linters will resolve asynchronously - keep a track of all // diagnostics reported as them come in. let diagnostics: vscode.Diagnostic[] = []; @@ -125,13 +115,6 @@ export class LintingEngine implements ILintingEngine { if (this.isDocumentOpen(document.uri)) { // Build the message and suffix the message with the name of the linter used. for (const m of msgs) { - // Ignore magic commands from jupyter. - if (hasJupyterCodeCells && document.lineAt(m.line - 1).text.trim().startsWith('%') && - (m.code === LinterErrors.pylint.InvalidSyntax || - m.code === LinterErrors.prospector.InvalidSyntax || - m.code === LinterErrors.flake8.InvalidSyntax)) { - continue; - } diagnostics.push(this.createDiagnostics(m, document)); } // Limit the number of messages to the max value. @@ -142,20 +125,6 @@ export class LintingEngine implements ILintingEngine { this.diagnosticCollection.set(document.uri, diagnostics); } - // tslint:disable-next-line:no-any - public async linkJupyterExtension(jupyter: vscode.Extension | undefined): Promise { - if (!jupyter) { - return; - } - if (!jupyter.isActive) { - await jupyter.activate(); - } - // tslint:disable-next-line:no-unsafe-any - jupyter.exports.registerLanguageProvider(PYTHON.language, new JupyterProvider()); - // tslint:disable-next-line:no-unsafe-any - this.documentHasJupyterCodeCells = jupyter.exports.hasCodeCells; - } - private sendLinterRunTelemetry(info: ILinterInfo, resource: vscode.Uri, promise: Promise, stopWatch: StopWatch, trigger: LinterTrigger): void { const linterExecutablePathName = info.pathName(resource); const properties: LintingTelemetry = { diff --git a/src/client/linters/types.ts b/src/client/linters/types.ts index 4fa6f7c9c4de..3d9ce85febf5 100644 --- a/src/client/linters/types.ts +++ b/src/client/linters/types.ts @@ -71,7 +71,5 @@ export interface ILintingEngine { readonly diagnostics: vscode.DiagnosticCollection; lintOpenPythonFiles(): Promise; lintDocument(document: vscode.TextDocument, trigger: LinterTrigger): Promise; - // tslint:disable-next-line:no-any - linkJupyterExtension(jupyter: vscode.Extension | undefined): Promise; clearDiagnostics(document: vscode.TextDocument): void; }