Path: blob/main/extensions/css-language-features/client/src/dropOrPaste/shared.ts
3321 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import * as vscode from 'vscode';6import { Utils } from 'vscode-uri';78export const Schemes = Object.freeze({9file: 'file',10notebookCell: 'vscode-notebook-cell',11untitled: 'untitled',12});1314export const Mimes = Object.freeze({15plain: 'text/plain',16uriList: 'text/uri-list',17});181920export function getDocumentDir(uri: vscode.Uri): vscode.Uri | undefined {21const docUri = getParentDocumentUri(uri);22if (docUri.scheme === Schemes.untitled) {23return vscode.workspace.workspaceFolders?.[0]?.uri;24}25return Utils.dirname(docUri);26}2728function getParentDocumentUri(uri: vscode.Uri): vscode.Uri {29if (uri.scheme === Schemes.notebookCell) {30// is notebook documents necessary?31for (const notebook of vscode.workspace.notebookDocuments) {32for (const cell of notebook.getCells()) {33if (cell.document.uri.toString() === uri.toString()) {34return notebook.uri;35}36}37}38}3940return uri;41}424344