Path: blob/main/src/resources/editor/tools/yaml/yaml.js
12923 views
(() => {1// yaml-intelligence.js2var mainPath = "";3function setMainPath(path) {4mainPath = path;5}6function getLocalPath(filename) {7const result = new URL(mainPath);8result.pathname = [...result.pathname.split("/").slice(0, -1), filename].join(9"/"10);11return result.toString();12}13var InternalError = class extends Error {14constructor(message, printName = true, printStack = true) {15super(message);16this.name = "Internal Error";17this.printName = printName;18this.printStack = printStack;19}20printName;21printStack;22};23function clientStubs(calls, worker) {24let callId = 0;25const nextId = () => callId++;26const result = {};27const promises = {};28for (const callName of calls) {29result[callName] = (...args) => {30const thisId = nextId();31worker.postMessage({32callName,33// The IDE sends some arrays with funky functions in the34// prototype, so the web worker API tries to clone those and35// fails. We strip them in a potentially slow way, so we36// should watch out for performance here.37args: JSON.parse(JSON.stringify(args)),38id: thisId39});40return new Promise((resolve, reject) => {41promises[thisId] = { resolve, reject };42});43};44}45worker.onmessage = function(e) {46const { result: result2, exception, id } = e.data;47if (promises[id] === void 0) {48throw new InternalError(`bad call id ${id} in web worker RPC`);49}50const { resolve, reject } = promises[id];51delete promises[id];52if (result2) {53resolve(result2);54} else if (exception) {55reject(exception);56}57};58return result;59}60var stubs;61function ensureStubs(path) {62if (stubs) {63return;64}65setMainPath(path);66const worker = new Worker(getLocalPath("web-worker.js"));67stubs = clientStubs(["getCompletions", "getLint"], worker);68}69var QuartoYamlEditorTools = {70// helpers to facilitate repro'ing in the browser71// getAutomation: function (72// params: { context: YamlIntelligenceContext; kind: AutomationKind },73// ) {74// const {75// context,76// kind,77// } = params;78// return getAutomation(kind, context);79// },80// exportSmokeTest,81// entry points required by the IDE82getCompletions: async function(context, path) {83ensureStubs(path);84return await stubs["getCompletions"](context, path);85},86getLint: async function(context, path) {87ensureStubs(path);88return await stubs["getLint"](context, path);89}90};9192// automation.js93window.QuartoYamlEditorTools = QuartoYamlEditorTools;94})();959697