UNPKG

@shopify/theme-language-server-common

Version:

<h1 align="center" style="position: relative;" > <br> <img src="https://github.com/Shopify/theme-check-vscode/blob/main/images/shopify_glyph.png?raw=true" alt="logo" width="141" height="160"> <br> Theme Language Server </h1>

63 lines 2.68 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DocumentManager = void 0; const theme_check_common_1 = require("@shopify/theme-check-common"); const vscode_languageserver_textdocument_1 = require("vscode-languageserver-textdocument"); class DocumentManager { constructor(fs) { this.sourceCodes = new Map(); this.fs = fs; } open(uri, source, version) { return this.set(uri, source, version); } change(uri, source, version) { return this.set(uri, source, version); } close(uri) { return this.sourceCodes.delete(uri); } delete(uri) { return this.sourceCodes.delete(uri); } theme(root, includeFilesFromDisk = false) { return [...this.sourceCodes.values()] .filter((sourceCode) => sourceCode.uri.startsWith(root)) .filter((sourceCode) => includeFilesFromDisk || sourceCode.version !== undefined); } get openDocuments() { return [...this.sourceCodes.values()].filter((sourceCode) => sourceCode.version !== undefined); } get(uri) { return this.sourceCodes.get(theme_check_common_1.path.normalize(uri)); } set(uri, source, version) { var _a; uri = theme_check_common_1.path.normalize(uri); // We only support json and liquid files. if (!/\.(json|liquid)$/.test(uri) || /\.(s?css|js).liquid$/.test(uri)) { return; } const sourceCode = (0, theme_check_common_1.toSourceCode)(uri, source, version); this.sourceCodes.set(uri, { ...sourceCode, textDocument: vscode_languageserver_textdocument_1.TextDocument.create(uri, sourceCode.type, (_a = sourceCode.version) !== null && _a !== void 0 ? _a : 0, // create doesn't let us put undefined here. sourceCode.source), }); } /** * The preload method is used to pre-load and pre-parse all the files in the * theme. It is smart and only will load files that are not already in the * DocumentManager. * * Files that are loaded from the AbstractFileSystem will have a version of `undefined`. */ async preload(rootUri) { if (!this.fs) throw new Error('Cannot call preload without a FileSystem'); const missingFiles = await (0, theme_check_common_1.recursiveReadDirectory)(this.fs, rootUri, ([uri]) => /.(liquid|json)$/.test(uri) && !this.sourceCodes.has(uri)); await Promise.all(missingFiles.map(async (file) => this.set(file, await this.fs.readFile(file), undefined))); } } exports.DocumentManager = DocumentManager; //# sourceMappingURL=DocumentManager.js.map