UNPKG

greybel-languageserver-core

Version:
122 lines 4.85 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ActiveDocument = void 0; const vscode_uri_1 = require("vscode-uri"); const types_1 = require("../../types"); const document_uri_builder_1 = require("./document-uri-builder"); class ActiveDocument { constructor(options) { this.context = options.context; this.version = options.version; this.textDocument = options.textDocument; this.typeDocument = options.typeDocument; this.parsedPayload = options.parsedPayload; this.errors = options.errors; } getDirectory() { return vscode_uri_1.Utils.joinPath(vscode_uri_1.URI.parse(this.textDocument.uri), '..'); } async getNativeImportUris(workspaceFolderUri = null) { if (this.parsedPayload == null) { return []; } const rootChunk = this.parsedPayload; if (rootChunk.nativeImports.length === 0) { return []; } const rootPath = this.getDirectory(); const builder = new document_uri_builder_1.DocumentURIBuilder(rootPath, workspaceFolderUri); const context = this.context; const imports = await Promise.all(rootChunk.nativeImports .filter((nativeImport) => nativeImport.directory && nativeImport.eval) .map(async (nativeImport) => { const path = await builder.getPathWithContext(nativeImport.directory, context); if (path == null) { return null; } return (0, types_1.parseDependencyLocation)({ type: types_1.DependencyType.NativeImport, location: path }); })); return imports.filter((path) => path != null); } async getImportUris(workspaceFolderUri = null) { if (this.parsedPayload == null) { return []; } const rootChunk = this.parsedPayload; if (rootChunk.imports.length === 0) { return []; } const rootPath = this.getDirectory(); const context = this.context; const builder = new document_uri_builder_1.DocumentURIBuilder(rootPath, workspaceFolderUri); const paths = await Promise.all([ ...rootChunk.imports .filter((nonNativeImport) => nonNativeImport.path) .map(async (nonNativeImport) => { const path = await builder.getPathWithContext(nonNativeImport.path, context); if (path == null) { return null; } return (0, types_1.parseDependencyLocation)({ type: types_1.DependencyType.Import, location: path, args: [nonNativeImport.name?.name] }); }) ]); return paths.filter((path) => path != null); } async getIncludeUris(workspaceFolderUri = null) { if (this.parsedPayload == null) { return []; } const rootChunk = this.parsedPayload; if (rootChunk.includes.length === 0) { return []; } const rootPath = this.getDirectory(); const context = this.context; const builder = new document_uri_builder_1.DocumentURIBuilder(rootPath, workspaceFolderUri); const paths = await Promise.all([ ...rootChunk.includes .filter((includeImport) => includeImport.path) .map(async (includeImport) => { const path = await builder.getPathWithContext(includeImport.path, context); if (path == null) { return null; } return (0, types_1.parseDependencyLocation)({ type: types_1.DependencyType.Include, location: path }); }) ]); return paths.filter((path) => path != null); } async getDependencies() { if (this.parsedPayload == null) { return []; } if (this.dependencies) { return this.dependencies; } const workspacePathUri = await this.context.fs.getWorkspaceFolderUri(vscode_uri_1.URI.parse(this.textDocument.uri)); const [nativeImports, imports, includes] = await Promise.all([ this.getNativeImportUris(workspacePathUri), this.getImportUris(workspacePathUri), this.getIncludeUris(workspacePathUri) ]); const dependencies = new Set([ ...nativeImports, ...imports, ...includes ]); this.dependencies = Array.from(dependencies).map(types_1.parseDependencyRawLocation); return this.dependencies; } } exports.ActiveDocument = ActiveDocument; //# sourceMappingURL=active-document.js.map