From 8cafebc46137be1fa6d4cb447d9b448510b02e23 Mon Sep 17 00:00:00 2001 From: Rich Chiodo Date: Fri, 19 Apr 2019 15:07:30 -0700 Subject: [PATCH 1/5] Make a box instead of a background --- .../editor-integration/decorator.ts | 60 ++++++++++++++----- 1 file changed, 44 insertions(+), 16 deletions(-) diff --git a/src/client/datascience/editor-integration/decorator.ts b/src/client/datascience/editor-integration/decorator.ts index 63520e4814b9..6cddec738096 100644 --- a/src/client/datascience/editor-integration/decorator.ts +++ b/src/client/datascience/editor-integration/decorator.ts @@ -13,24 +13,17 @@ import { generateCellRanges } from '../cellFactory'; @injectable() export class Decorator implements IExtensionActivationService, IDisposable { - private activeCellType: vscode.TextEditorDecorationType; - private cellSeparatorType: vscode.TextEditorDecorationType; + private activeCellTop: vscode.TextEditorDecorationType | undefined; + private activeCellMiddle: vscode.TextEditorDecorationType | undefined; + private activeCellBottom: vscode.TextEditorDecorationType | undefined; + private cellSeparatorType: vscode.TextEditorDecorationType | undefined; private timer: NodeJS.Timer | undefined; constructor(@inject(IDocumentManager) private documentManager: IDocumentManager, @inject(IDisposableRegistry) disposables: IDisposableRegistry, @inject(IConfigurationService) private configuration: IConfigurationService) { - this.activeCellType = this.documentManager.createTextEditorDecorationType({ - backgroundColor: new vscode.ThemeColor('peekViewEditor.background'), - isWholeLine: true - }); - this.cellSeparatorType = this.documentManager.createTextEditorDecorationType({ - borderColor: new vscode.ThemeColor('peekViewEditor.background'), - borderWidth: '1px 0px 0px 0px', - borderStyle: 'solid', - isWholeLine: true - }); + this.computeDecorations(); disposables.push(this); disposables.push(this.configuration.getSettings().onDidChange(this.settingsChanged, this)); disposables.push(this.documentManager.onDidChangeActiveTextEditor(this.changedEditor, this)); @@ -80,22 +73,57 @@ export class Decorator implements IExtensionActivationService, IDisposable { this.timer = setTimeout(() => this.update(editor), 100); } + private computeDecorations() { + this.activeCellTop = this.documentManager.createTextEditorDecorationType({ + borderColor: new vscode.ThemeColor('peekView.border'), + borderWidth: '1px 1px 0px 1px', + borderStyle: 'solid', + isWholeLine: true + }); + this.activeCellMiddle = this.documentManager.createTextEditorDecorationType({ + borderColor: new vscode.ThemeColor('peekView.border'), + borderWidth: '0px 1px 0px 1px', + borderStyle: 'solid', + isWholeLine: true + }); + this.activeCellBottom = this.documentManager.createTextEditorDecorationType({ + borderColor: new vscode.ThemeColor('peekView.border'), + borderWidth: '0px 1px 1px 1px', + borderStyle: 'solid', + isWholeLine: true + }); + this.cellSeparatorType = this.documentManager.createTextEditorDecorationType({ + borderColor: new vscode.ThemeColor('sideBarSectionHeader.background'), + borderWidth: '1px 0px 0px 0px', + borderStyle: 'solid', + isWholeLine: true + }); + } + private update(editor: vscode.TextEditor | undefined) { - if (editor && editor.document && editor.document.languageId === PYTHON_LANGUAGE) { + if (editor && editor.document && editor.document.languageId === PYTHON_LANGUAGE && + this.activeCellTop && this.cellSeparatorType && this.activeCellBottom && this.activeCellMiddle) { const settings = this.configuration.getSettings().datascience; if (settings.decorateCells && settings.enabled) { // Find all of the cells const cells = generateCellRanges(editor.document, this.configuration.getSettings().datascience); // Find the range for our active cell. - const activeRanges = cells.map(c => c.range).filter(r => r.contains(editor.selection.anchor)); - editor.setDecorations(this.activeCellType, activeRanges); + const currentRange = cells.map(c => c.range).filter(r => r.contains(editor.selection.anchor)); + const rangeTop = currentRange.length > 0 ? [new vscode.Range(currentRange[0].start, currentRange[0].start)] : []; + const rangeBottom = currentRange.length > 0 ? [new vscode.Range(currentRange[0].end, currentRange[0].end)] : []; + const rangeMiddle = currentRange.length > 0 && currentRange[0].start !== currentRange[0].end ? [new vscode.Range(currentRange[0].start.line + 1, 0, currentRange[0].end.line - 1, 0)] : []; + editor.setDecorations(this.activeCellTop, rangeTop); + editor.setDecorations(this.activeCellMiddle, rangeMiddle); + editor.setDecorations(this.activeCellBottom, rangeBottom); // Find the start range for the rest const startRanges = cells.map(c => new vscode.Range(c.range.start, c.range.start)); editor.setDecorations(this.cellSeparatorType, startRanges); } else { - editor.setDecorations(this.activeCellType, []); + editor.setDecorations(this.activeCellTop, []); + editor.setDecorations(this.activeCellMiddle, []); + editor.setDecorations(this.activeCellBottom, []); editor.setDecorations(this.cellSeparatorType, []); } } From 07cde8ed279219242c171d8e948a665bebe681b5 Mon Sep 17 00:00:00 2001 From: Rich Chiodo Date: Fri, 19 Apr 2019 16:05:39 -0700 Subject: [PATCH 2/5] Fix casing on IPython --- package.nls.json | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/package.nls.json b/package.nls.json index 8b0ea1bccfc7..1dd8214b00e3 100644 --- a/package.nls.json +++ b/package.nls.json @@ -49,8 +49,8 @@ "python.command.python.datascience.undocells.title": "Undo last Python Interactive action", "python.command.python.datascience.redocells.title": "Redo last Python Interactive action", "python.command.python.datascience.removeallcells.title": "Delete all Python Interactive cells", - "python.command.python.datascience.interruptkernel.title": "Interrupt iPython Kernel", - "python.command.python.datascience.restartkernel.title": "Restart iPython Kernel", + "python.command.python.datascience.interruptkernel.title": "Interrupt IPython Kernel", + "python.command.python.datascience.restartkernel.title": "Restart IPython Kernel", "python.command.python.datascience.expandallcells.title": "Expand all Python Interactive cells", "python.command.python.datascience.collapseallcells.title": "Collapse all Python Interactive cells", "python.snippet.launch.standard.label": "Python: Current File", @@ -100,7 +100,7 @@ "Interpreters.LoadingInterpreters": "Loading Python Interpreters", "Common.doNotShowAgain": "Do not show again", "Interpreters.environmentPromptMessage": "We noticed a new virtual environment has been created. Do you want to select it for the workspace folder?", - "DataScience.restartKernelMessage": "Do you want to restart the iPython kernel? All variables will be lost.", + "DataScience.restartKernelMessage": "Do you want to restart the IPython kernel? All variables will be lost.", "DataScience.restartKernelMessageYes": "Restart", "DataScience.restartKernelMessageNo": "Cancel", "DataScience.restartingKernelFailed": "Kernel restart failed. Jupyter server is hung. Please reload VS Code.", @@ -111,12 +111,12 @@ "InteractiveShiftEnterBanner.bannerMessage": "Would you like to run code in the 'Python Interactive' window (an IPython console) for 'shift-enter'? Select 'No' to continue to run code in the Python Terminal. This can be changed later in settings.", "InteractiveShiftEnterBanner.bannerLabelYes": "Yes", "InteractiveShiftEnterBanner.bannerLabelNo": "No", - "DataScience.restartingKernelStatus": "Restarting iPython Kernel", + "DataScience.restartingKernelStatus": "Restarting IPython Kernel", "DataScience.executingCode": "Executing Cell", "DataScience.collapseAll": "Collapse all cell inputs", "DataScience.expandAll": "Expand all cell inputs", "DataScience.export": "Export as Jupyter Notebook", - "DataScience.restartServer": "Restart iPython Kernel", + "DataScience.restartServer": "Restart IPython Kernel", "DataScience.undo": "Undo", "DataScience.redo": "Redo", "DataScience.clearAll": "Remove All Cells", @@ -161,13 +161,13 @@ "diagnostics.yesUpdateLaunch": "Yes, update launch.json", "diagnostics.bannerLabelNo": "No, I will do it later", "diagnostics.invalidTestSettings": "Your settings needs to be updated to change the setting \"python.unitTest.\" to \"python.testing.\", otherwise testing Python code using the extension may not work. Would you like to automatically update your settings now?", - "DataScience.interruptKernel": "Interrupt iPython Kernel", + "DataScience.interruptKernel": "Interrupt IPython Kernel", "DataScience.exportingFormat": "Exporting {0}", "DataScience.exportCancel": "Cancel", "Common.canceled": "Canceled", "DataScience.importChangeDirectoryComment": "#%% Change working directory from the workspace root to the ipynb file location. Turn this addition off with the DataScience.changeDirOnImportExport setting", "DataScience.exportChangeDirectoryComment": "# Change directory to VSCode workspace root so that relative path loads work correctly. Turn this addition off with the DataScience.changeDirOnImportExport setting", - "DataScience.interruptKernelStatus": "Interrupting iPython Kernel", + "DataScience.interruptKernelStatus": "Interrupting IPython Kernel", "DataScience.restartKernelAfterInterruptMessage": "Interrupting the kernel timed out. Do you want to restart the kernel instead? All variables will be lost.", "DataScience.pythonInterruptFailedHeader": "Keyboard interrupt crashed the kernel. Kernel restarted.", "DataScience.sysInfoURILabel": "Jupyter Server URI: ", From 8a071da1b3d34c43215263bf635f36b5dbc03144 Mon Sep 17 00:00:00 2001 From: Rich Chiodo Date: Mon, 22 Apr 2019 11:03:16 -0700 Subject: [PATCH 3/5] Final decision on decorator --- src/client/datascience/editor-integration/decorator.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/client/datascience/editor-integration/decorator.ts b/src/client/datascience/editor-integration/decorator.ts index 6cddec738096..f8e201003ad2 100644 --- a/src/client/datascience/editor-integration/decorator.ts +++ b/src/client/datascience/editor-integration/decorator.ts @@ -76,7 +76,7 @@ export class Decorator implements IExtensionActivationService, IDisposable { private computeDecorations() { this.activeCellTop = this.documentManager.createTextEditorDecorationType({ borderColor: new vscode.ThemeColor('peekView.border'), - borderWidth: '1px 1px 0px 1px', + borderWidth: '2px 0px 0px 0px', borderStyle: 'solid', isWholeLine: true }); @@ -88,7 +88,7 @@ export class Decorator implements IExtensionActivationService, IDisposable { }); this.activeCellBottom = this.documentManager.createTextEditorDecorationType({ borderColor: new vscode.ThemeColor('peekView.border'), - borderWidth: '0px 1px 1px 1px', + borderWidth: '0px 0px 1px 0px', borderStyle: 'solid', isWholeLine: true }); @@ -114,7 +114,7 @@ export class Decorator implements IExtensionActivationService, IDisposable { const rangeBottom = currentRange.length > 0 ? [new vscode.Range(currentRange[0].end, currentRange[0].end)] : []; const rangeMiddle = currentRange.length > 0 && currentRange[0].start !== currentRange[0].end ? [new vscode.Range(currentRange[0].start.line + 1, 0, currentRange[0].end.line - 1, 0)] : []; editor.setDecorations(this.activeCellTop, rangeTop); - editor.setDecorations(this.activeCellMiddle, rangeMiddle); + //editor.setDecorations(this.activeCellMiddle, rangeMiddle); editor.setDecorations(this.activeCellBottom, rangeBottom); // Find the start range for the rest From 4a6ddd292aee28dd61879106b5654489e5c0e3bc Mon Sep 17 00:00:00 2001 From: Rich Chiodo Date: Mon, 22 Apr 2019 11:03:55 -0700 Subject: [PATCH 4/5] Code cleanup --- .../datascience/editor-integration/decorator.ts | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/src/client/datascience/editor-integration/decorator.ts b/src/client/datascience/editor-integration/decorator.ts index f8e201003ad2..5c3e78e18b6f 100644 --- a/src/client/datascience/editor-integration/decorator.ts +++ b/src/client/datascience/editor-integration/decorator.ts @@ -14,7 +14,6 @@ import { generateCellRanges } from '../cellFactory'; export class Decorator implements IExtensionActivationService, IDisposable { private activeCellTop: vscode.TextEditorDecorationType | undefined; - private activeCellMiddle: vscode.TextEditorDecorationType | undefined; private activeCellBottom: vscode.TextEditorDecorationType | undefined; private cellSeparatorType: vscode.TextEditorDecorationType | undefined; private timer: NodeJS.Timer | undefined; @@ -80,12 +79,6 @@ export class Decorator implements IExtensionActivationService, IDisposable { borderStyle: 'solid', isWholeLine: true }); - this.activeCellMiddle = this.documentManager.createTextEditorDecorationType({ - borderColor: new vscode.ThemeColor('peekView.border'), - borderWidth: '0px 1px 0px 1px', - borderStyle: 'solid', - isWholeLine: true - }); this.activeCellBottom = this.documentManager.createTextEditorDecorationType({ borderColor: new vscode.ThemeColor('peekView.border'), borderWidth: '0px 0px 1px 0px', @@ -102,7 +95,7 @@ export class Decorator implements IExtensionActivationService, IDisposable { private update(editor: vscode.TextEditor | undefined) { if (editor && editor.document && editor.document.languageId === PYTHON_LANGUAGE && - this.activeCellTop && this.cellSeparatorType && this.activeCellBottom && this.activeCellMiddle) { + this.activeCellTop && this.cellSeparatorType && this.activeCellBottom) { const settings = this.configuration.getSettings().datascience; if (settings.decorateCells && settings.enabled) { // Find all of the cells @@ -112,9 +105,7 @@ export class Decorator implements IExtensionActivationService, IDisposable { const currentRange = cells.map(c => c.range).filter(r => r.contains(editor.selection.anchor)); const rangeTop = currentRange.length > 0 ? [new vscode.Range(currentRange[0].start, currentRange[0].start)] : []; const rangeBottom = currentRange.length > 0 ? [new vscode.Range(currentRange[0].end, currentRange[0].end)] : []; - const rangeMiddle = currentRange.length > 0 && currentRange[0].start !== currentRange[0].end ? [new vscode.Range(currentRange[0].start.line + 1, 0, currentRange[0].end.line - 1, 0)] : []; editor.setDecorations(this.activeCellTop, rangeTop); - //editor.setDecorations(this.activeCellMiddle, rangeMiddle); editor.setDecorations(this.activeCellBottom, rangeBottom); // Find the start range for the rest @@ -122,7 +113,6 @@ export class Decorator implements IExtensionActivationService, IDisposable { editor.setDecorations(this.cellSeparatorType, startRanges); } else { editor.setDecorations(this.activeCellTop, []); - editor.setDecorations(this.activeCellMiddle, []); editor.setDecorations(this.activeCellBottom, []); editor.setDecorations(this.cellSeparatorType, []); } From d564c0f6535b332463bfaf5c22e9c24325f6c119 Mon Sep 17 00:00:00 2001 From: Rich Chiodo Date: Mon, 22 Apr 2019 11:22:15 -0700 Subject: [PATCH 5/5] Update in between color to be an editor color --- src/client/datascience/editor-integration/decorator.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/datascience/editor-integration/decorator.ts b/src/client/datascience/editor-integration/decorator.ts index 5c3e78e18b6f..651bb510a5c3 100644 --- a/src/client/datascience/editor-integration/decorator.ts +++ b/src/client/datascience/editor-integration/decorator.ts @@ -86,7 +86,7 @@ export class Decorator implements IExtensionActivationService, IDisposable { isWholeLine: true }); this.cellSeparatorType = this.documentManager.createTextEditorDecorationType({ - borderColor: new vscode.ThemeColor('sideBarSectionHeader.background'), + borderColor: new vscode.ThemeColor('editor.lineHighlightBorder'), borderWidth: '1px 0px 0px 0px', borderStyle: 'solid', isWholeLine: true