UNPKG

zenstack

Version:

FullStack enhancement for Prisma ORM: seamless integration from database to UI

62 lines 3.2 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const langium_1 = require("langium"); const node_1 = require("langium/node"); const node_2 = require("vscode-languageserver/node"); const vscode_uri_1 = require("vscode-uri"); const zmodel_module_1 = require("./zmodel-module"); const cli_util_1 = require("../cli/cli-util"); // Create a connection to the client const connection = (0, node_2.createConnection)(node_2.ProposedFeatures.all); // Inject the shared services and language-specific services const { shared } = (0, zmodel_module_1.createZModelServices)(Object.assign({ connection }, node_1.NodeFileSystem)); // Add custom LSP request handlers connection.onRequest('zenstack/getAllImportedZModelURIs', (params) => __awaiter(void 0, void 0, void 0, function* () { try { const uri = vscode_uri_1.URI.parse(params.textDocument.uri); const document = shared.workspace.LangiumDocuments.getOrCreateDocument(uri); // Ensure the document is parsed and built if (!document.parseResult) { yield shared.workspace.DocumentBuilder.build([document]); } // #region merge imported documents const langiumDocuments = shared.workspace.LangiumDocuments; // load all imports const importedURIs = (0, cli_util_1.eagerLoadAllImports)(document, langiumDocuments); const importedDocuments = importedURIs.map((uri) => langiumDocuments.getOrCreateDocument(uri)); // build the document together with standard library, plugin modules, and imported documents yield shared.workspace.DocumentBuilder.build([document, ...importedDocuments], { validationChecks: 'all', }); const hasSyntaxErrors = [uri, ...importedURIs].some((uri) => { var _a; const doc = langiumDocuments.getOrCreateDocument(uri); return (doc.parseResult.lexerErrors.length > 0 || doc.parseResult.parserErrors.length > 0 || ((_a = doc.diagnostics) === null || _a === void 0 ? void 0 : _a.some((e) => e.severity === 1))); }); return { hasSyntaxErrors, importedURIs, }; } catch (error) { console.error('Error getting imported ZModel file:', error); return { hasSyntaxErrors: true, importedURIs: [], }; } })); // Start the language server with the shared services (0, langium_1.startLanguageServer)(shared); //# sourceMappingURL=main.js.map