UNPKG

greybel-languageserver-core

Version:
46 lines 2.02 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DocumentURIBuilder = void 0; const vscode_uri_1 = require("vscode-uri"); class DocumentURIBuilder { static async fromTextDocument(textDocument, context) { const textDocumentUri = vscode_uri_1.URI.parse(textDocument.uri); const workspaceFolderUri = await context.fs.getWorkspaceFolderUri(textDocumentUri); return new DocumentURIBuilder(vscode_uri_1.Utils.joinPath(textDocumentUri, '..'), workspaceFolderUri); } constructor(rootPath, workspaceFolderUri = null) { this.workspaceFolderUri = workspaceFolderUri; this.rootPath = rootPath; } getFromWorkspaceFolder(path) { if (this.workspaceFolderUri == null) { console.warn('Workspace folders are not available. Falling back to only relative paths.'); return vscode_uri_1.Utils.joinPath(this.rootPath, path).toString(); } return vscode_uri_1.Utils.joinPath(this.workspaceFolderUri, path).toString(); } getFromRootPath(path) { return vscode_uri_1.Utils.joinPath(this.rootPath, path).toString(); } getAlternativePathsWithContext(path, context) { if (path.startsWith('/')) { return context.getConfiguration().fileExtensions.map((ext) => { return this.getFromWorkspaceFolder(`${path}.${ext}`); }); } return context.getConfiguration().fileExtensions.map((ext) => { return this.getFromRootPath(`${path}.${ext}`); }); } getOriginalPath(path) { if (path.startsWith('/')) { return this.getFromWorkspaceFolder(path); } return this.getFromRootPath(path); } async getPathWithContext(path, context) { return context.fs.findExistingPath(this.getOriginalPath(path), ...this.getAlternativePathsWithContext(path, context)); } } exports.DocumentURIBuilder = DocumentURIBuilder; //# sourceMappingURL=document-uri-builder.js.map