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
1 change: 1 addition & 0 deletions news/2 Fixes/3123.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Change interactive window to use the python interpreter associated with the file being run.
2 changes: 1 addition & 1 deletion src/client/common/application/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ interface ICommandNameWithoutArgumentTypeMapping {
[DSCommands.RunCurrentCellAdvance]: [];
[DSCommands.ExecSelectionInInteractiveWindow]: [];
[DSCommands.SelectJupyterURI]: [];
[DSCommands.SelectJupyterCommandLine]: [];
[DSCommands.ShowHistoryPane]: [];
[DSCommands.UndoCells]: [];
[DSCommands.RedoCells]: [];
Expand Down Expand Up @@ -154,4 +153,5 @@ export interface ICommandNameArgumentTypeMapping extends ICommandNameWithoutArgu
[DSCommands.ScrollToCell]: [string, string];
[DSCommands.ViewJupyterOutput]: [];
[DSCommands.SwitchJupyterKernel]: [INotebook | undefined];
[DSCommands.SelectJupyterCommandLine]: [undefined | Uri];
}
12 changes: 10 additions & 2 deletions src/client/datascience/cellFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
import '../common/extensions';

import * as uuid from 'uuid/v4';
import { Range, TextDocument } from 'vscode';
import { Range, TextDocument, Uri } from 'vscode';

import { parseForComments } from '../../datascience-ui/common';
import { createCodeCell, createMarkdownCell } from '../../datascience-ui/common/cellFactory';
import { IDataScienceSettings } from '../common/types';
import { IDataScienceSettings, Resource } from '../common/types';
import { noop } from '../common/utils/misc';
import { CellMatcher } from './cellMatcher';
import { Identifiers } from './constants';
import { CellState, ICell } from './types';

function generateCodeCell(
Expand Down Expand Up @@ -40,6 +41,13 @@ function generateMarkdownCell(code: string[], file: string, line: number, id: st
};
}

export function getCellResource(cell: ICell): Resource {
if (cell.file !== Identifiers.EmptyFileName) {
return Uri.file(cell.file);
}
return undefined;
}

export function generateCells(
settings: IDataScienceSettings | undefined,
code: string,
Expand Down
13 changes: 7 additions & 6 deletions src/client/datascience/codeCssGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import * as path from 'path';
import { IWorkspaceService } from '../common/application/types';
import { traceError, traceInfo, traceWarning } from '../common/logger';
import { IFileSystem } from '../common/platform/types';
import { IConfigurationService } from '../common/types';
import { IConfigurationService, Resource } from '../common/types';
import { DefaultTheme } from './constants';
import { ICodeCssGenerator, IThemeFinder } from './types';

Expand Down Expand Up @@ -102,15 +102,16 @@ export class CodeCssGenerator implements ICodeCssGenerator {
@inject(IFileSystem) private fs: IFileSystem
) {}

public generateThemeCss(isDark: boolean, theme: string): Promise<string> {
return this.applyThemeData(isDark, theme, '', this.generateCss.bind(this));
public generateThemeCss(resource: Resource, isDark: boolean, theme: string): Promise<string> {
return this.applyThemeData(resource, isDark, theme, '', this.generateCss.bind(this));
}

public generateMonacoTheme(isDark: boolean, theme: string): Promise<JSONObject> {
return this.applyThemeData(isDark, theme, {} as any, this.generateMonacoThemeObject.bind(this));
public generateMonacoTheme(resource: Resource, isDark: boolean, theme: string): Promise<JSONObject> {
return this.applyThemeData(resource, isDark, theme, {} as any, this.generateMonacoThemeObject.bind(this));
}

private async applyThemeData<T>(
resource: Resource,
isDark: boolean,
theme: string,
defaultT: T,
Expand All @@ -119,7 +120,7 @@ export class CodeCssGenerator implements ICodeCssGenerator {
let result = defaultT;
try {
// First compute our current theme.
const ignoreTheme = this.configService.getSettings().datascience.ignoreVscodeTheme ? true : false;
const ignoreTheme = this.configService.getSettings(resource).datascience.ignoreVscodeTheme ? true : false;
theme = ignoreTheme ? DefaultTheme : theme;
const editor = this.workspaceService.getConfiguration('editor', undefined);
const fontFamily = editor
Expand Down
3 changes: 2 additions & 1 deletion src/client/datascience/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,8 @@ export enum Telemetry {
KernelEnumeration = 'DS_INTERNAL.KERNEL_ENUMERATION',
JupyterInstallFailed = 'DS_INTERNAL.JUPYTER_INSTALL_FAILED',
UserInstalledModule = 'DATASCIENCE.USER_INSTALLED_MODULE',
JupyterCommandLineNonDefault = 'DS_INTERNAL.JUPYTER_CUSTOM_COMMAND_LINE'
JupyterCommandLineNonDefault = 'DS_INTERNAL.JUPYTER_CUSTOM_COMMAND_LINE',
NewFileForInteractiveWindow = 'DS_INTERNAL.NEW_FILE_USED_IN_INTERACTIVE'
}

export enum NativeKeyboardCommandTelemetry {
Expand Down
6 changes: 5 additions & 1 deletion src/client/datascience/data-viewing/dataViewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { IApplicationShell, IWebPanelProvider, IWorkspaceService } from '../../c
import { EXTENSION_ROOT_DIR } from '../../common/constants';
import { WebHostNotebook } from '../../common/experimentGroups';
import { traceError } from '../../common/logger';
import { IConfigurationService, IDisposable, IExperimentsManager } from '../../common/types';
import { IConfigurationService, IDisposable, IExperimentsManager, Resource } from '../../common/types';
import * as localize from '../../common/utils/localize';
import { noop } from '../../common/utils/misc';
import { StopWatch } from '../../common/utils/stopWatch';
Expand Down Expand Up @@ -84,6 +84,10 @@ export class DataViewer extends WebViewHost<IDataViewerMapping> implements IData
}
}

protected getOwningResource(): Promise<Resource> {
return Promise.resolve(undefined);
}

//tslint:disable-next-line:no-any
protected onMessage(message: string, payload: any) {
switch (message) {
Expand Down
4 changes: 2 additions & 2 deletions src/client/datascience/datascience.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class DataScience implements IDataScience {

// Set our initial settings and sign up for changes
this.onSettingsChanged();
this.changeHandler = this.configuration.getSettings().onDidChange(this.onSettingsChanged.bind(this));
this.changeHandler = this.configuration.getSettings(undefined).onDidChange(this.onSettingsChanged.bind(this));
this.disposableRegistry.push(this);

// Listen for active editor changes so we can detect have code cells or not
Expand All @@ -68,7 +68,7 @@ export class DataScience implements IDataScience {
}

private onSettingsChanged = () => {
const settings = this.configuration.getSettings();
const settings = this.configuration.getSettings(undefined);
const enabled = settings.datascience.enabled;
let editorContext = new ContextKey(EditorContexts.DataScienceEnabled, this.commandManager);
editorContext.set(enabled).catch();
Expand Down
14 changes: 7 additions & 7 deletions src/client/datascience/editor-integration/cellhashprovider.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import { nbformat } from '@jupyterlab/coreutils';
import * as hashjs from 'hash.js';
import { inject, injectable, multiInject, optional } from 'inversify';
import { Event, EventEmitter, Position, Range, TextDocumentChangeEvent, TextDocumentContentChangeEvent } from 'vscode';
Expand All @@ -12,6 +11,7 @@ import { traceError, traceInfo } from '../../common/logger';
import { IFileSystem } from '../../common/platform/types';
import { IConfigurationService } from '../../common/types';
import { noop } from '../../common/utils/misc';
import { getCellResource } from '../cellFactory';
import { CellMatcher } from '../cellMatcher';
import { Identifiers } from '../constants';
import { InteractiveWindowMessages, SysInfoReason } from '../interactive-common/interactiveWindowTypes';
Expand Down Expand Up @@ -106,7 +106,7 @@ export class CellHashProvider implements ICellHashProvider, IInteractiveWindowLi
try {
if (!silent) {
// Don't log empty cells
const stripped = this.extractExecutableLines(cell.data.source);
const stripped = this.extractExecutableLines(cell);
if (stripped.length > 0 && stripped.find(s => s.trim().length > 0)) {
// When the user adds new code, we know the execution count is increasing
this.executionCount += 1;
Expand Down Expand Up @@ -139,9 +139,9 @@ export class CellHashProvider implements ICellHashProvider, IInteractiveWindowLi
}
}

private extractExecutableLines(code: nbformat.MultilineString): string[] {
const cellMatcher = new CellMatcher(this.configService.getSettings().datascience);
const lines = splitMultilineString(code);
private extractExecutableLines(cell: ICell): string[] {
const cellMatcher = new CellMatcher(this.configService.getSettings(getCellResource(cell)).datascience);
const lines = splitMultilineString(cell.data.source);
// Only strip this off the first line. Otherwise we want the markers in the code.
if (lines.length > 0 && (cellMatcher.isCode(lines[0]) || cellMatcher.isMarkdown(lines[0]))) {
return lines.slice(1);
Expand Down Expand Up @@ -193,7 +193,7 @@ export class CellHashProvider implements ICellHashProvider, IInteractiveWindowLi
if (doc) {
// Compute the code that will really be sent to jupyter
const lines = splitMultilineString(cell.data.source);
const stripped = this.extractExecutableLines(cell.data.source);
const stripped = this.extractExecutableLines(cell);

// Figure out our true 'start' line. This is what we need to tell the debugger is
// actually the start of the code as that's what Jupyter will be getting.
Expand Down Expand Up @@ -292,7 +292,7 @@ export class CellHashProvider implements ICellHashProvider, IInteractiveWindowLi
): number {
if (
this.debugService.activeDebugSession &&
this.configService.getSettings().datascience.stopOnFirstLineWhileDebugging
this.configService.getSettings(getCellResource(cell)).datascience.stopOnFirstLineWhileDebugging
) {
// Inject the breakpoint line
source.splice(0, 0, 'breakpoint()\n');
Expand Down
17 changes: 10 additions & 7 deletions src/client/datascience/editor-integration/codeLensFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { CodeLens, Command, Event, EventEmitter, Range, TextDocument } from 'vsc

import { traceWarning } from '../../common/logger';
import { IFileSystem } from '../../common/platform/types';
import { IConfigurationService } from '../../common/types';
import { IConfigurationService, Resource } from '../../common/types';
import * as localize from '../../common/utils/localize';
import { noop } from '../../common/utils/misc';
import { generateCellRangesFromDocument } from '../cellFactory';
Expand Down Expand Up @@ -67,9 +67,12 @@ export class CodeLensFactory implements ICodeLensFactory, IInteractiveWindowList
}

public createCodeLenses(document: TextDocument): CodeLens[] {
const ranges = generateCellRangesFromDocument(document, this.configService.getSettings().datascience);
const commands = this.enumerateCommands();
const hashes = this.configService.getSettings().datascience.addGotoCodeLenses
const ranges = generateCellRangesFromDocument(
document,
this.configService.getSettings(document.uri).datascience
);
const commands = this.enumerateCommands(document.uri);
const hashes = this.configService.getSettings(document.uri).datascience.addGotoCodeLenses
? this.hashProvider.getHashes()
: [];
const codeLenses: CodeLens[] = [];
Expand All @@ -89,18 +92,18 @@ export class CodeLensFactory implements ICodeLensFactory, IInteractiveWindowList
return codeLenses;
}

private enumerateCommands(): string[] {
private enumerateCommands(resource: Resource): string[] {
let fullCommandList: string[];
// Add our non-debug commands
const commands = this.configService.getSettings().datascience.codeLenses;
const commands = this.configService.getSettings(resource).datascience.codeLenses;
if (commands) {
fullCommandList = commands.split(',').map(s => s.trim());
} else {
fullCommandList = CodeLensCommands.DefaultDesignLenses;
}

// Add our debug commands
const debugCommands = this.configService.getSettings().datascience.debugCodeLenses;
const debugCommands = this.configService.getSettings(resource).datascience.debugCodeLenses;
if (debugCommands) {
fullCommandList = fullCommandList.concat(debugCommands.split(',').map(s => s.trim()));
} else {
Expand Down
10 changes: 7 additions & 3 deletions src/client/datascience/editor-integration/codelensprovider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ export class DataScienceCodeLensProvider implements IDataScienceCodeLensProvider

// IDataScienceCodeLensProvider interface
public getCodeWatcher(document: vscode.TextDocument): ICodeWatcher | undefined {
return this.matchWatcher(document.fileName, document.version, this.configuration.getSettings().datascience);
return this.matchWatcher(
document.fileName,
document.version,
this.configuration.getSettings(document.uri).datascience
);
}

private onDebugLocationUpdated() {
Expand Down Expand Up @@ -90,7 +94,7 @@ export class DataScienceCodeLensProvider implements IDataScienceCodeLensProvider
editorContext.set(result && result.length > 0).catch();

// Don't provide any code lenses if we have not enabled data science
const settings = this.configuration.getSettings();
const settings = this.configuration.getSettings(document.uri);
if (!settings.datascience.enabled || !settings.datascience.enableCellCodeLens) {
// Clear out any existing code watchers, providecodelenses is called on settings change
// so we don't need to watch the settings change specifically here
Expand Down Expand Up @@ -143,7 +147,7 @@ export class DataScienceCodeLensProvider implements IDataScienceCodeLensProvider
const codeWatcher: ICodeWatcher | undefined = this.matchWatcher(
document.fileName,
document.version,
this.configuration.getSettings().datascience
this.configuration.getSettings(document.uri).datascience
);
if (codeWatcher) {
return codeWatcher.getCodeLenses();
Expand Down
22 changes: 14 additions & 8 deletions src/client/datascience/editor-integration/codewatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {

import { IDocumentManager } from '../../common/application/types';
import { IFileSystem } from '../../common/platform/types';
import { IConfigurationService, IDataScienceSettings } from '../../common/types';
import { IConfigurationService, IDataScienceSettings, Resource } from '../../common/types';
import * as localize from '../../common/utils/localize';
import { StopWatch } from '../../common/utils/stopWatch';
import { captureTelemetry, sendTelemetryEvent } from '../../telemetry';
Expand Down Expand Up @@ -53,7 +53,7 @@ export class CodeWatcher implements ICodeWatcher {
this.version = document.version;

// Get document cells here. Make a copy of our settings.
this.cachedSettings = JSON.parse(JSON.stringify(this.configService.getSettings().datascience));
this.cachedSettings = JSON.parse(JSON.stringify(this.configService.getSettings(document.uri).datascience));

// Use the factory to generate our new code lenses.
this.codeLenses = this.codeLensFactory.createCodeLenses(document);
Expand Down Expand Up @@ -269,7 +269,8 @@ export class CodeWatcher implements ICodeWatcher {
// Run the cell clicked. Advance if the cursor is inside this cell and we're allowed to
const advance =
range.contains(this.documentManager.activeTextEditor.selection.start) &&
this.configService.getSettings().datascience.enableAutoMoveToNextCell;
this.configService.getSettings(this.documentManager.activeTextEditor.document.uri).datascience
.enableAutoMoveToNextCell;
return this.runMatchingCell(range, advance);
}

Expand Down Expand Up @@ -305,7 +306,7 @@ export class CodeWatcher implements ICodeWatcher {

public async addEmptyCellToBottom(): Promise<void> {
const editor = this.documentManager.activeTextEditor;
const cellDelineator = this.defaultCellMarker;
const cellDelineator = this.getDefaultCellMarker(editor?.document.uri);
if (editor) {
editor.edit(editBuilder => {
editBuilder.insert(new Position(editor.document.lineCount, 0), `\n\n${cellDelineator}\n`);
Expand All @@ -324,7 +325,7 @@ export class CodeWatcher implements ICodeWatcher {
const editor = this.documentManager.activeTextEditor;
const cellMatcher = new CellMatcher();
let index = 0;
const cellDelineator = this.defaultCellMarker;
const cellDelineator = this.getDefaultCellMarker(editor.document.uri);

if (editor) {
editor.edit(editBuilder => {
Expand Down Expand Up @@ -353,8 +354,10 @@ export class CodeWatcher implements ICodeWatcher {
);
}

private get defaultCellMarker(): string {
return this.configService.getSettings().datascience.defaultCellMarker || Identifiers.DefaultCodeCellMarker;
private getDefaultCellMarker(resource: Resource): string {
return (
this.configService.getSettings(resource).datascience.defaultCellMarker || Identifiers.DefaultCodeCellMarker
);
}

private onCodeLensFactoryUpdated(): void {
Expand Down Expand Up @@ -482,7 +485,10 @@ export class CodeWatcher implements ICodeWatcher {

if (editor) {
editor.edit(editBuilder => {
editBuilder.insert(new Position(currentRange.end.line + 1, 0), `\n\n${this.defaultCellMarker}\n`);
editBuilder.insert(
new Position(currentRange.end.line + 1, 0),
`\n\n${this.getDefaultCellMarker(editor.document.uri)}\n`
);
});
}

Expand Down
9 changes: 3 additions & 6 deletions src/client/datascience/editor-integration/decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class Decorator implements IExtensionSingleActivationService, IDisposable
) {
this.computeDecorations();
disposables.push(this);
disposables.push(this.configuration.getSettings().onDidChange(this.settingsChanged, this));
disposables.push(this.configuration.getSettings(undefined).onDidChange(this.settingsChanged, this));
disposables.push(this.documentManager.onDidChangeActiveTextEditor(this.changedEditor, this));
disposables.push(this.documentManager.onDidChangeTextEditorSelection(this.changedSelection, this));
disposables.push(this.documentManager.onDidChangeTextDocument(this.changedDocument, this));
Expand Down Expand Up @@ -104,13 +104,10 @@ export class Decorator implements IExtensionSingleActivationService, IDisposable
this.cellSeparatorType &&
this.activeCellBottom
) {
const settings = this.configuration.getSettings().datascience;
const settings = this.configuration.getSettings(editor.document.uri).datascience;
if (settings.decorateCells && settings.enabled) {
// Find all of the cells
const cells = generateCellRangesFromDocument(
editor.document,
this.configuration.getSettings().datascience
);
const cells = generateCellRangesFromDocument(editor.document, settings);

// Find the range for our active cell.
const currentRange = cells.map(c => c.range).filter(r => r.contains(editor.selection.anchor));
Expand Down
4 changes: 3 additions & 1 deletion src/client/datascience/gather/gather.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ export class GatherExecution implements IGatherExecution {
this._executionSlicer = new ExecutionLogSlicer(this.dataflowAnalyzer);

if (this._enabled) {
this.disposables.push(this.configService.getSettings().onDidChange(e => this.updateEnableGather(e)));
this.disposables.push(
this.configService.getSettings(undefined).onDidChange(e => this.updateEnableGather(e))
);
}

traceInfo('Gathering tools have been activated');
Expand Down
2 changes: 1 addition & 1 deletion src/client/datascience/gather/gatherListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export class GatherListener implements IInteractiveWindowListener {

// First get the active server
const activeServer = await this.jupyterExecution.getServer(
await this.interactiveWindowProvider.getNotebookOptions()
await this.interactiveWindowProvider.getNotebookOptions(this.notebookUri)
);

let nb: INotebook | undefined;
Expand Down
Loading