Skip to content

Commit

Permalink
Use path.sep instead of \\ when translating IW input box URI to n…
Browse files Browse the repository at this point in the history
…otebook URI (#13269)
  • Loading branch information
debonte authored Apr 6, 2023
1 parent 7e214aa commit cdc9c72
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/standalone/intellisense/notebookPythonPathService.node.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import * as path from '../../platform/vscode-path/path';
import { inject, injectable } from 'inversify';
import { Disposable, extensions, Uri, workspace, window } from 'vscode';
import { INotebookEditorProvider } from '../../notebooks/types';
Expand Down Expand Up @@ -123,12 +124,11 @@ export class NotebookPythonPathService implements IExtensionSingleActivationServ
}

private _getNotebookUriForTextDocumentUri(textDocumentUri: Uri): Uri | undefined {
if (textDocumentUri.scheme !== 'vscode-interactive-input') {
const notebookUri = getNotebookUriFromInputBoxUri(textDocumentUri);
if (!notebookUri) {
return undefined;
}

const notebookPath = `${textDocumentUri.fsPath.replace('\\InteractiveInput-', 'Interactive-')}.interactive`;
const notebookUri = textDocumentUri.with({ scheme: 'vscode-interactive', path: notebookPath });
let result: string | undefined = undefined;
window.tabGroups.all.find((group) => {
group.tabs.find((tab) => {
Expand All @@ -144,3 +144,13 @@ export class NotebookPythonPathService implements IExtensionSingleActivationServ
return result;
}
}

export function getNotebookUriFromInputBoxUri(textDocumentUri: Uri): Uri | undefined {
if (textDocumentUri.scheme !== 'vscode-interactive-input') {
return undefined;
}

const inputBoxPrefix = path.sep + 'InteractiveInput-';
const notebookPath = `${textDocumentUri.fsPath.replace(inputBoxPrefix, 'Interactive-')}.interactive`;
return textDocumentUri.with({ scheme: 'vscode-interactive', path: notebookPath });
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { assert } from 'chai';
import { getNotebookUriFromInputBoxUri } from '../../../../standalone/intellisense/notebookPythonPathService.node';
import { Uri } from 'vscode';

suite(`DataScience - VSCode Intellisense Notebook - PythonPath service @lsp`, function () {
test('Not an input box', async () => {
const notebookUri = getNotebookUriFromInputBoxUri(Uri.file('/foo/bar.py'));
assert.notOk(notebookUri);
});
test('Input box', async () => {
const notebookUri = getNotebookUriFromInputBoxUri(Uri.parse('vscode-interactive-input:/InteractiveInput-3'));
assert.ok(notebookUri);
assert.strictEqual(
notebookUri!.toString(),
Uri.from({ scheme: 'vscode-interactive', path: 'Interactive-3.interactive' }).toString()
);
});
});

0 comments on commit cdc9c72

Please sign in to comment.