Skip to content

Commit 890bb90

Browse files
committed
fix handling of file on different drive
1 parent c88c836 commit 890bb90

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

src/test/suite/path-type.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ describe('Path Type Tests', async () => {
5252
await vscode.window.showNotebookDocument(notebook);
5353
await vscode.workspace.getConfiguration('jsonpath-notebook').update('useRelativePaths', true, true);
5454

55-
const contextUri = vscode.Uri.file('C:\\input\\bookstore.json');
55+
const contextUri = vscode.Uri.file('Z:\\input\\bookstore.json');
5656

5757
const expectedPath = contextUri.path;
5858
const actualPath = getPreferredPathFormatFromUri(contextUri);

src/utils.ts

+3-6
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,13 @@ export const getPreferredPathFormatFromUri = (uri: vscode.Uri): string => {
3434
// check if notebook is open
3535
const notebookUri = vscode.window.activeNotebookEditor?.notebook.uri;
3636
if (useRelativePaths && notebookUri) {
37-
const notebookPath = notebookUri.path;
38-
const contextPath = uri.path;
39-
4037
// check if both files are on the same drive
4138
// if not, use absolute path
42-
const notebookRoot = path.parse(notebookPath).root;
43-
const contextRoot = path.parse(contextPath).root;
39+
const notebookRoot = path.parse(notebookUri.fsPath).root;
40+
const contextRoot = path.parse(uri.fsPath).root;
4441
if (notebookRoot === contextRoot) {
4542
// use relative path
46-
filePath = path.relative(path.dirname(notebookPath), contextPath);
43+
filePath = path.relative(path.dirname(notebookUri.path), uri.path);
4744
}
4845
}
4946
return filePath;

0 commit comments

Comments
 (0)