Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/css-language-features/client/src/dropOrPaste/shared.ts
3321 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 { Utils } from 'vscode-uri';
8
9
export const Schemes = Object.freeze({
10
file: 'file',
11
notebookCell: 'vscode-notebook-cell',
12
untitled: 'untitled',
13
});
14
15
export const Mimes = Object.freeze({
16
plain: 'text/plain',
17
uriList: 'text/uri-list',
18
});
19
20
21
export function getDocumentDir(uri: vscode.Uri): vscode.Uri | undefined {
22
const docUri = getParentDocumentUri(uri);
23
if (docUri.scheme === Schemes.untitled) {
24
return vscode.workspace.workspaceFolders?.[0]?.uri;
25
}
26
return Utils.dirname(docUri);
27
}
28
29
function getParentDocumentUri(uri: vscode.Uri): vscode.Uri {
30
if (uri.scheme === Schemes.notebookCell) {
31
// is notebook documents necessary?
32
for (const notebook of vscode.workspace.notebookDocuments) {
33
for (const cell of notebook.getCells()) {
34
if (cell.document.uri.toString() === uri.toString()) {
35
return notebook.uri;
36
}
37
}
38
}
39
}
40
41
return uri;
42
}
43
44