Skip to content

Commit

Permalink
Fix unit tests on windows and add some missing bindings for web
Browse files Browse the repository at this point in the history
  • Loading branch information
rchiodo committed Apr 15, 2022
1 parent 49adb87 commit bd0382a
Show file tree
Hide file tree
Showing 20 changed files with 129 additions and 83 deletions.
2 changes: 2 additions & 0 deletions src/extension.web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ import { registerTypes as registerTelemetryTypes } from './telemetry/serviceRegi
import { registerTypes as registerKernelTypes } from './kernels/serviceRegistry.web';
import { registerTypes as registerNotebookTypes } from './notebooks/serviceRegistry.web';
import { registerTypes as registerInteractiveTypes } from './interactive-window/serviceRegistry.web';
import { registerTypes as registerIntellisenseTypes } from './intellisense/serviceRegistry.web';
import { IExtensionActivationManager } from './platform/activation/types';
import { isCI, isTestExecution, STANDARD_OUTPUT_CHANNEL } from './platform/common/constants';
import { getJupyterOutputChannel } from './platform/devTools/jupyterOutputChannel';
Expand Down Expand Up @@ -280,6 +281,7 @@ async function activateLegacy(
registerNotebookTypes(serviceManager);
registerKernelTypes(serviceManager, isDevMode);
registerInteractiveTypes(serviceManager);
registerIntellisenseTypes(serviceManager, isDevMode);

// Load the two data science experiments that we need to register types
// Await here to keep the register method sync
Expand Down
8 changes: 5 additions & 3 deletions src/intellisense/languageServer.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { getInterpreterId } from '../platform/pythonEnvironments/info/interprete
import { noop } from '../platform/common/utils/misc';
import { sleep } from '../platform/common/utils/async';
import { PythonEnvironment } from '../platform/pythonEnvironments/info';
import { getFilePath } from '../platform/common/platform/fs-paths';

// eslint-disable-next-line @typescript-eslint/no-explicit-any
function ensure(target: any, key: string) {
Expand Down Expand Up @@ -134,14 +135,14 @@ export class LanguageServer implements Disposable {
() => languageClient,
() => noop, // Don't trace output. Slows things down too much
NOTEBOOK_SELECTOR,
interpreter.uri.fsPath || interpreter.uri.path,
getFilePath(interpreter.uri),
(uri) => shouldAllowIntellisense(uri, interpreterId, interpreter.uri),
getNotebookHeader
)
: createPylanceMiddleware(
() => languageClient,
NOTEBOOK_SELECTOR,
interpreter.uri.fsPath || interpreter.uri.path,
getFilePath(interpreter.uri),
(uri) => shouldAllowIntellisense(uri, interpreterId, interpreter.uri),
getNotebookHeader
);
Expand Down Expand Up @@ -227,8 +228,9 @@ export class LanguageServer implements Disposable {
if (python) {
const runJediPath = path.join(python.extensionPath, 'pythonFiles', 'run-jedi-language-server.py');
if (await fs.pathExists(runJediPath)) {
const interpreterPath = getFilePath(interpreter.uri);
const serverOptions: ServerOptions = {
command: interpreter.uri.fsPath || 'python',
command: interpreterPath.length > 0 ? interpreterPath : 'python',
args: [runJediPath]
};
return serverOptions;
Expand Down
22 changes: 22 additions & 0 deletions src/intellisense/serviceRegistry.web.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';

import { IExtensionSingleActivationService, IExtensionSyncActivationService } from '../platform/activation/types';
import { IServiceManager } from '../platform/ioc/types';
import { NotebookCellLanguageService } from './cellLanguageService';
import { NotebookCellBangInstallDiagnosticsProvider } from './diagnosticsProvider';
import { EmptyNotebookCellLanguageService } from './emptyNotebookCellLanguageService';

export function registerTypes(serviceManager: IServiceManager, _isDevMode: boolean) {
serviceManager.addSingleton<IExtensionSyncActivationService>(
IExtensionSyncActivationService,
NotebookCellBangInstallDiagnosticsProvider
);
serviceManager.addSingleton<NotebookCellLanguageService>(NotebookCellLanguageService, NotebookCellLanguageService);
serviceManager.addBinding(NotebookCellLanguageService, IExtensionSingleActivationService);
serviceManager.addSingleton<IExtensionSingleActivationService>(
IExtensionSingleActivationService,
EmptyNotebookCellLanguageService
);
}
13 changes: 6 additions & 7 deletions src/interactive-window/editor-integration/cellhashprovider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@ import { CellMatcher } from './cellMatcher';
import { ICellHash, ICellHashProvider, ICellHashListener, IFileHashes } from './types';
import { getAssociatedNotebookDocument } from '../../notebooks/controllers/kernelSelector';
import { getInteractiveCellMetadata } from '../helpers';
import { getDisplayPath } from '../../platform/common/platform/fs-paths';
import { getDisplayPath, getFilePath } from '../../platform/common/platform/fs-paths';
import { IPlatformService } from '../../platform/common/platform/types';
import { untildify } from '../../platform/common/utils/platform';
import { originalFSPath } from '../../platform/vscode-path/resources';

// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
const _escapeRegExp = require('lodash/escapeRegExp') as typeof import('lodash/escapeRegExp'); // NOSONAR
Expand Down Expand Up @@ -247,7 +246,7 @@ export class CellHashProvider implements ICellHashProvider {
// exceptions in output. Track backs only work on local files.
if (!this.traceBackRegexes.has(uristring)) {
const uri = Uri.parse(uristring);
const fileMatchRegex = new RegExp(`\\[.*?;32m${_escapeRegExp(originalFSPath(uri))}`);
const fileMatchRegex = new RegExp(`\\[.*?;32m${_escapeRegExp(getFilePath(uri))}`);
const fileDisplayNameMatchRegex = new RegExp(`\\[.*?;32m${_escapeRegExp(getDisplayPath(uri))}`);
this.traceBackRegexes.set(uristring, [fileMatchRegex, fileDisplayNameMatchRegex]);
}
Expand Down Expand Up @@ -503,7 +502,7 @@ export class CellHashProvider implements ICellHashProvider {
// Then replace the input line with our uri for this cell
return afterLineReplace.replace(
/.*?\n/,
`\u001b[1;32m${originalFSPath(matchUri)}\u001b[0m in \u001b[0;36m${inputMatch[2]}\n`
`\u001b[1;32m${getFilePath(matchUri)}\u001b[0m in \u001b[0;36m${inputMatch[2]}\n`
);
} else if (this.kernel && notebook && notebook.notebookType !== InteractiveWindowView) {
const matchingCellUri = this.executionCounts.get(executionCount);
Expand All @@ -522,7 +521,7 @@ export class CellHashProvider implements ICellHashProvider {
return afterLineReplace.replace(
/.*?\n/,
`\u001b[1;32m${localize.DataScience.cellAtFormat().format(
originalFSPath(matchUri),
getFilePath(matchUri),
(cellIndex + 1).toString()
)}\u001b[0m in \u001b[0;36m${inputMatch[2]}\n`
);
Expand All @@ -533,7 +532,7 @@ export class CellHashProvider implements ICellHashProvider {
const fileMatch = /^File.*?\[\d;32m(.*):\d+.*\u001b.*\n/.exec(traceFrame);
if (fileMatch && fileMatch.length > 1) {
// We need to untilde the file path here for the link to work in VS Code
const detildePath = untildify(fileMatch[1], originalFSPath(this.platformService.homeDir));
const detildePath = untildify(fileMatch[1], getFilePath(this.platformService.homeDir));
const fileUri = Uri.file(detildePath);
// We have a match, replace source lines with hrefs
return traceFrame.replace(LineNumberMatchRegex, (_s, prefix, num, suffix) => {
Expand Down Expand Up @@ -572,7 +571,7 @@ export class CellHashProvider implements ICellHashProvider {
} else {
const matchingFile = regexes.find((e) => {
const uri = Uri.parse(e[0]);
return traceFrame.includes(originalFSPath(uri));
return traceFrame.includes(getFilePath(uri));
});
if (matchingFile) {
const offset = this.findCellOffset(this.hashes.get(matchingFile[0]), traceFrame);
Expand Down
7 changes: 4 additions & 3 deletions src/interactive-window/interactiveWindow.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import { IVSCodeNotebookController } from '../notebooks/controllers/types';
import { DisplayOptions } from '../kernels/displayOptions';
import { getInteractiveCellMetadata, InteractiveCellMetadata } from './helpers';
import { KernelConnector } from '../kernels/kernelConnector';
import { getFilePath } from '../platform/common/platform/fs-paths';

export class InteractiveWindow implements IInteractiveWindowLoadable {
public get onDidChangeViewState(): Event<void> {
Expand Down Expand Up @@ -431,7 +432,7 @@ export class InteractiveWindow implements IInteractiveWindowLoadable {

public async debugCode(code: string, fileUri: Uri, line: number): Promise<boolean> {
let saved = true;
const file = fileUri.fsPath;
const file = getFilePath(fileUri);
// Make sure the file is saved before debugging
const doc = this.documentManager.textDocuments.find((d) => this.fs.areLocalPathsSame(d.fileName, file));
if (doc && doc.isUntitled) {
Expand Down Expand Up @@ -607,7 +608,7 @@ export class InteractiveWindow implements IInteractiveWindowLoadable {
}

// If the file isn't unknown, set the active kernel's __file__ variable to point to that same file.
await this.setFileInKernel(fileUri.fsPath, kernel!);
await this.setFileInKernel(getFilePath(fileUri), kernel!);
traceInfoIfCI('file in kernel set for IW');
}

Expand Down Expand Up @@ -799,7 +800,7 @@ export class InteractiveWindow implements IInteractiveWindowLoadable {
// Bring up the export file dialog box
const uri = await this.exportDialog.showDialog(ExportFormat.ipynb, this.owningResource);
if (uri) {
await this.jupyterExporter.exportToFile(cells, uri.fsPath);
await this.jupyterExporter.exportToFile(cells, getFilePath(uri));
}
}
}
Expand Down
14 changes: 6 additions & 8 deletions src/kernels/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { Uri } from 'vscode';
import { IWorkspaceService } from '../platform/common/application/types';
import { isCI, PYTHON_LANGUAGE, Settings, Telemetry } from '../platform/common/constants';
import { traceError, traceInfo, traceInfoIfCI, traceWarning } from '../platform/logging';
import { getDisplayPath } from '../platform/common/platform/fs-paths';
import { getDisplayPath, getFilePath } from '../platform/common/platform/fs-paths';
import { DataScience } from '../platform/common/utils/localize';
import { SysInfoReason } from '../platform/messageTypes';
import { getNormalizedInterpreterPath, getInterpreterHash } from '../platform/pythonEnvironments/info/interpreter';
Expand Down Expand Up @@ -58,7 +58,7 @@ export function createInterpreterKernelSpec(
): IJupyterKernelSpec {
const interpreterMetadata = interpreter
? {
path: uriPath.originalFSPath(interpreter.uri)
path: getFilePath(interpreter.uri)
}
: {};
// This creates a kernel spec for an interpreter. When launched, 'python' argument will map to using the interpreter
Expand All @@ -83,8 +83,8 @@ export function createInterpreterKernelSpec(

return new JupyterKernelSpec(
defaultSpec,
specFile ? uriPath.originalFSPath(specFile) : undefined,
uriPath.originalFSPath(interpreter?.uri),
specFile ? getFilePath(specFile) : undefined,
getFilePath(interpreter?.uri),
'registeredByNewVersionOfExt'
);
}
Expand Down Expand Up @@ -992,10 +992,8 @@ export function getKernelId(spec: IJupyterKernelSpec, interpreter?: PythonEnviro
argsForGenerationOfId = spec.argv.join('#').toLowerCase();
}
const prefixForRemoteKernels = remoteBaseUrl ? `${remoteBaseUrl}.` : '';
const specPath = uriPath.originalFSPath(
getNormalizedInterpreterPath(fsPathToUri(spec.interpreterPath) || spec.uri)
);
const interpreterPath = uriPath.originalFSPath(getNormalizedInterpreterPath(interpreter?.uri)) || '';
const specPath = getFilePath(getNormalizedInterpreterPath(fsPathToUri(spec.interpreterPath) || spec.uri));
const interpreterPath = getFilePath(getNormalizedInterpreterPath(interpreter?.uri)) || '';
return `${prefixForRemoteKernels}${
spec.id || ''
}.${specName}.${specPath}.${interpreterPath}.${argsForGenerationOfId}`;
Expand Down
5 changes: 3 additions & 2 deletions src/kernels/installer/pipEnvInstaller.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { ModuleInstallerType, ModuleInstallFlags } from './types';
import { isPipenvEnvironmentRelatedToFolder } from './pipenv.node';
import { getInterpreterWorkspaceFolder } from '../helpers';
import { IServiceContainer } from '../../platform/ioc/types';
import { originalFSPath } from '../../platform/vscode-path/resources';
import { getFilePath } from '../../platform/common/platform/fs-paths';

export const pipenvName = 'pipenv';

Expand Down Expand Up @@ -67,10 +67,11 @@ export class PipEnvInstaller extends ModuleInstaller {
flags & ModuleInstallFlags.updateDependencies ||
flags & ModuleInstallFlags.upgrade;
const args = [update ? 'update' : 'install', moduleName, '--dev'];
const workspaceFolder = getInterpreterWorkspaceFolder(interpreter, this.workspaceService);
return {
args,
exe: pipenvName,
cwd: originalFSPath(getInterpreterWorkspaceFolder(interpreter, this.workspaceService))
cwd: workspaceFolder ? getFilePath(workspaceFolder) : undefined
};
}
}
6 changes: 3 additions & 3 deletions src/kernels/jupyter/launcher/serverUriStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import {
IApplicationEnvironment
} from '../../../platform/common/application/types';
import { Settings } from '../../../platform/common/constants';
import { getFilePath } from '../../../platform/common/platform/fs-paths';
import { IConfigurationService, ICryptoUtils, IMemento, GLOBAL_MEMENTO } from '../../../platform/common/types';
import { originalFSPath } from '../../../platform/vscode-path/resources';
import { IJupyterServerUriStorage } from '../types';

/**
Expand Down Expand Up @@ -187,10 +187,10 @@ export class JupyterServerUriStorage implements IJupyterServerUriStorage {
private getUriAccountKey(): string {
if (this.workspaceService.rootFolder) {
// Folder situation
return this.crypto.createHash(originalFSPath(this.workspaceService.rootFolder), 'string', 'SHA512');
return this.crypto.createHash(getFilePath(this.workspaceService.rootFolder), 'string', 'SHA512');
} else if (this.workspaceService.workspaceFile) {
// Workspace situation
return this.crypto.createHash(originalFSPath(this.workspaceService.workspaceFile), 'string', 'SHA512');
return this.crypto.createHash(getFilePath(this.workspaceService.workspaceFile), 'string', 'SHA512');
}
return this.appEnv.machineId; // Global key when no folder or workspace file
}
Expand Down
5 changes: 2 additions & 3 deletions src/kernels/kernel.base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { IApplicationShell, IWorkspaceService } from '../platform/common/applica
import { WrappedError } from '../platform/errors/types';
import { disposeAllDisposables } from '../platform/common/helpers';
import { traceInfo, traceInfoIfCI, traceError, traceVerbose, traceWarning } from '../platform/logging';
import { getDisplayPath } from '../platform/common/platform/fs-paths';
import { getDisplayPath, getFilePath } from '../platform/common/platform/fs-paths';
import {
Resource,
IDisposableRegistry,
Expand Down Expand Up @@ -57,7 +57,6 @@ import { Cancellation } from '../platform/common/cancellation';
import { KernelProgressReporter } from '../platform/progress/kernelProgressReporter';
import { DisplayOptions } from './displayOptions';
import { SilentExecutionErrorOptions } from './helpers';
import { originalFSPath } from '../platform/vscode-path/resources';

export abstract class BaseKernel implements IKernel {
get connection(): INotebookProviderConnection | undefined {
Expand Down Expand Up @@ -453,7 +452,7 @@ export abstract class BaseKernel implements IKernel {
result.push(...changeDirScripts);

// Set the ipynb file
const file = originalFSPath(this.resourceUri);
const file = getFilePath(this.resourceUri);
if (file) {
result.push(`__vsc_ipynb_file__ = "${file.replace(/\\/g, '\\\\')}"`);
}
Expand Down
5 changes: 5 additions & 0 deletions src/kernels/serviceRegistry.web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { LocalKernelFinder } from './raw/finder/localKernelFinder.web';
import { NotebookProvider } from './jupyter/launcher/notebookProvider';
import { IKernelProvider, INotebookProvider } from './types';
import { KernelProvider } from './kernelProvider.web';
import { PreferredRemoteKernelIdProvider } from './raw/finder/preferredRemoteKernelIdProvider';

@injectable()
class RawNotebookSupportedService implements IRawNotebookSupportedService {
Expand Down Expand Up @@ -62,6 +63,10 @@ export function registerTypes(serviceManager: IServiceManager, isDevMode: boolea
serviceManager.addSingleton<IRemoteKernelFinder>(IRemoteKernelFinder, RemoteKernelFinder);
serviceManager.addSingleton<INotebookProvider>(INotebookProvider, NotebookProvider);
serviceManager.addSingleton<IKernelProvider>(IKernelProvider, KernelProvider);
serviceManager.addSingleton<PreferredRemoteKernelIdProvider>(
PreferredRemoteKernelIdProvider,
PreferredRemoteKernelIdProvider
);

// Subdirectories
registerWidgetTypes(serviceManager, isDevMode);
Expand Down
4 changes: 2 additions & 2 deletions src/notebooks/controllers/liveKernelSwitcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { IDisposableRegistry, IMemento, WORKSPACE_MEMENTO } from '../../platform
import { IKernelProvider, LiveRemoteKernelConnectionMetadata } from '../../kernels/types';
import { INotebookControllerManager } from '../types';
import { switchKernel } from './kernelSelector';
import { originalFSPath } from '../../platform/vscode-path/resources';
import { getFilePath } from '../../platform/common/platform/fs-paths';

const MEMENTO_BASE_KEY = 'jupyter-notebook-remote-session-';

Expand Down Expand Up @@ -38,7 +38,7 @@ export class LiveKernelSwitcher implements IExtensionSingleActivationService {
}

private getKey(notebookUri: Uri) {
return `${MEMENTO_BASE_KEY}${originalFSPath(notebookUri)}`;
return `${MEMENTO_BASE_KEY}${getFilePath(notebookUri)}`;
}

private onDidOpenNotebook(n: NotebookDocument) {
Expand Down
3 changes: 1 addition & 2 deletions src/notebooks/serviceRegistry.web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@ import { LiveKernelSwitcher } from './controllers/liveKernelSwitcher';
import { NotebookControllerManager } from './controllers/notebookControllerManager';
import { RemoteSwitcher } from './controllers/remoteSwitcher';
import { CellOutputDisplayIdTracker } from './execution/cellDisplayIdTracker';
import { INotebookLanguageClientProvider, INotebookControllerManager, INotebookEditorProvider } from './types';
import { INotebookControllerManager, INotebookEditorProvider } from './types';
import { NotebookUsageTracker } from './notebookUsageTracker';
import { NotebookEditorProvider } from './notebookEditorProvider';

export function registerTypes(serviceManager: IServiceManager) {
serviceManager.addSingleton<IExtensionSingleActivationService>(IExtensionSingleActivationService, RemoteSwitcher);
serviceManager.addSingleton<CellOutputDisplayIdTracker>(CellOutputDisplayIdTracker, CellOutputDisplayIdTracker);
serviceManager.addBinding(INotebookLanguageClientProvider, IExtensionSingleActivationService);
serviceManager.addSingleton<INotebookControllerManager>(INotebookControllerManager, NotebookControllerManager);
serviceManager.addSingleton<IExtensionSyncActivationService>(IExtensionSyncActivationService, KernelFilterUI);
serviceManager.addBinding(INotebookControllerManager, IExtensionSyncActivationService);
Expand Down
Loading

0 comments on commit bd0382a

Please sign in to comment.