Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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.",
Expand All @@ -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",
Expand Down Expand Up @@ -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: ",
Expand Down
50 changes: 34 additions & 16 deletions src/client/datascience/editor-integration/decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,16 @@ 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 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));
Expand Down Expand Up @@ -80,22 +72,48 @@ 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: '2px 0px 0px 0px',
borderStyle: 'solid',
isWholeLine: true
});
this.activeCellBottom = this.documentManager.createTextEditorDecorationType({
borderColor: new vscode.ThemeColor('peekView.border'),
borderWidth: '0px 0px 1px 0px',
borderStyle: 'solid',
isWholeLine: true
});
this.cellSeparatorType = this.documentManager.createTextEditorDecorationType({
borderColor: new vscode.ThemeColor('editor.lineHighlightBorder'),
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) {
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)] : [];
editor.setDecorations(this.activeCellTop, rangeTop);
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.activeCellBottom, []);
editor.setDecorations(this.cellSeparatorType, []);
}
}
Expand Down