UNPKG

@prisma/language-server

Version:
38 lines 1.78 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = textDocumentCompletion; const _1 = require("."); const internals_1 = require("./internals"); /* eslint-disable @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-return */ // This can't panic / throw exceptions. Any panic here should be considered a // bug to be fixed. prisma-schema-wasm will return an empty CompletionList on error. function textDocumentCompletion(schema, params, onError) { // CompletionParams.textDocument doesn't match the Language Server JSON-RPC protocol // as defined by the spec. In the spec, it is an object with one property: // uri, which is a string. The above `params` are a structured object with // methods, and `__uri` and `__contents` properties. // // prisma-schema-wasm expects something spec-compliant, so we enforce this here. const correctParams = params; correctParams['textDocument'] = { uri: params.textDocument.uri }; const stringifiedParams = JSON.stringify(correctParams); try { if (process.env.FORCE_PANIC_PRISMA_SCHEMA) { (0, internals_1.handleFormatPanic)(() => { console.debug('Triggering a Rust panic...'); _1.prismaSchemaWasm.debug_panic(); }); } const response = _1.prismaSchemaWasm.text_document_completion(JSON.stringify(schema), stringifiedParams); return JSON.parse(response); } catch (e) { const err = e; (0, internals_1.handleWasmError)(err, 'text_document_completion', onError); return { isIncomplete: true, items: [], }; } } //# sourceMappingURL=textDocumentCompletion.js.map