Path: blob/main/src/resources/editor/tools/yaml/yaml-intelligence.js
12923 views
// paths.ts1var mainPath = "";2function setMainPath(path) {3mainPath = path;4}5function getLocalPath(filename) {6const result = new URL(mainPath);7result.pathname = [...result.pathname.split("/").slice(0, -1), filename].join(8"/"9);10return result.toString();11}1213// ../error.ts14var InternalError = class extends Error {15constructor(message, printName = true, printStack = true) {16super(message);17this.name = "Internal Error";18this.printName = printName;19this.printStack = printStack;20}21printName;22printStack;23};2425// web-worker-manager.ts26function clientStubs(calls, worker) {27let callId = 0;28const nextId = () => callId++;29const result = {};30const promises = {};31for (const callName of calls) {32result[callName] = (...args) => {33const thisId = nextId();34worker.postMessage({35callName,36// The IDE sends some arrays with funky functions in the37// prototype, so the web worker API tries to clone those and38// fails. We strip them in a potentially slow way, so we39// should watch out for performance here.40args: JSON.parse(JSON.stringify(args)),41id: thisId42});43return new Promise((resolve, reject) => {44promises[thisId] = { resolve, reject };45});46};47}48worker.onmessage = function(e) {49const { result: result2, exception, id } = e.data;50if (promises[id] === void 0) {51throw new InternalError(`bad call id ${id} in web worker RPC`);52}53const { resolve, reject } = promises[id];54delete promises[id];55if (result2) {56resolve(result2);57} else if (exception) {58reject(exception);59}60};61return result;62}6364// ide-main.ts65var stubs;66function ensureStubs(path) {67if (stubs) {68return;69}70setMainPath(path);71const worker = new Worker(getLocalPath("web-worker.js"));72stubs = clientStubs(["getCompletions", "getLint"], worker);73}74var QuartoYamlEditorTools = {75// helpers to facilitate repro'ing in the browser76// getAutomation: function (77// params: { context: YamlIntelligenceContext; kind: AutomationKind },78// ) {79// const {80// context,81// kind,82// } = params;83// return getAutomation(kind, context);84// },85// exportSmokeTest,86// entry points required by the IDE87getCompletions: async function(context, path) {88ensureStubs(path);89return await stubs["getCompletions"](context, path);90},91getLint: async function(context, path) {92ensureStubs(path);93return await stubs["getLint"](context, path);94}95};96export {97QuartoYamlEditorTools98};99100101