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