Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/markdown-language-features/src/util/document.ts
3292 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import * as vscode from 'vscode';
7
import { Schemes } from './schemes';
8
import { Utils } from 'vscode-uri';
9
10
export function getDocumentDir(uri: vscode.Uri): vscode.Uri | undefined {
11
const docUri = getParentDocumentUri(uri);
12
if (docUri.scheme === Schemes.untitled) {
13
return vscode.workspace.workspaceFolders?.[0]?.uri;
14
}
15
return Utils.dirname(docUri);
16
}
17
18
export function getParentDocumentUri(uri: vscode.Uri): vscode.Uri {
19
if (uri.scheme === Schemes.notebookCell) {
20
for (const notebook of vscode.workspace.notebookDocuments) {
21
for (const cell of notebook.getCells()) {
22
if (cell.document.uri.toString() === uri.toString()) {
23
return notebook.uri;
24
}
25
}
26
}
27
}
28
29
return uri;
30
}
31
32