pdl-editor 0.30.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -0
- package/assets/language-configuration.json +48 -0
- package/assets/pdl.tmLanguage.json +191 -0
- package/dist/index.cjs +863 -0
- package/dist/index.d.cts +117 -0
- package/dist/index.d.ts +117 -0
- package/dist/index.mjs +832 -0
- package/package.json +62 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,832 @@
|
|
|
1
|
+
// src/index.tsx
|
|
2
|
+
import React from "react";
|
|
3
|
+
import * as monaco from "monaco-editor/esm/vs/editor/editor.api";
|
|
4
|
+
import "monaco-editor/min/vs/editor/editor.main.css";
|
|
5
|
+
import "monaco-editor/esm/vs/editor/contrib/hover/browser/hoverContribution";
|
|
6
|
+
import EditorWorker from "monaco-editor/esm/vs/editor/editor.worker?worker";
|
|
7
|
+
import { wireTmGrammars } from "monaco-editor-textmate";
|
|
8
|
+
import { Registry } from "monaco-textmate";
|
|
9
|
+
import { loadWASM as loadOnigasm } from "onigasm";
|
|
10
|
+
import onigasmWasmUrl from "onigasm/lib/onigasm.wasm?url";
|
|
11
|
+
|
|
12
|
+
// assets/language-configuration.json
|
|
13
|
+
var language_configuration_default = {
|
|
14
|
+
comments: {
|
|
15
|
+
lineComment: "//",
|
|
16
|
+
blockComment: [
|
|
17
|
+
"/*",
|
|
18
|
+
"*/"
|
|
19
|
+
]
|
|
20
|
+
},
|
|
21
|
+
brackets: [
|
|
22
|
+
[
|
|
23
|
+
"(",
|
|
24
|
+
")"
|
|
25
|
+
]
|
|
26
|
+
],
|
|
27
|
+
autoClosingPairs: [
|
|
28
|
+
{
|
|
29
|
+
open: '"',
|
|
30
|
+
close: '"'
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
open: "`",
|
|
34
|
+
close: "`"
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
open: "(",
|
|
38
|
+
close: ")"
|
|
39
|
+
}
|
|
40
|
+
],
|
|
41
|
+
surroundingPairs: [
|
|
42
|
+
{
|
|
43
|
+
open: '"',
|
|
44
|
+
close: '"'
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
open: "`",
|
|
48
|
+
close: "`"
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
open: "(",
|
|
52
|
+
close: ")"
|
|
53
|
+
}
|
|
54
|
+
],
|
|
55
|
+
wordPattern: "(-?\\d*\\.\\d\\w*)|([^`~!@#$%^&*()+={}\\[\\]\\\\|;:'\",.<>/?\\s]+)",
|
|
56
|
+
indentationRules: {
|
|
57
|
+
increaseIndentPattern: "^\\s*let\\s+[A-Za-z_][A-Za-z0-9_]*\\s*=\\s*$",
|
|
58
|
+
decreaseIndentPattern: "^\\s*$"
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
// assets/pdl.tmLanguage.json
|
|
63
|
+
var pdl_tmLanguage_default = {
|
|
64
|
+
$schema: "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
|
|
65
|
+
name: "PDL",
|
|
66
|
+
scopeName: "source.pdl",
|
|
67
|
+
patterns: [
|
|
68
|
+
{
|
|
69
|
+
include: "#comments"
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
include: "#strings"
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
include: "#backtickColumns"
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
include: "#numbers"
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
include: "#contextReferences"
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
include: "#operators"
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
include: "#declarations"
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
include: "#keywords"
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
include: "#functions"
|
|
94
|
+
}
|
|
95
|
+
],
|
|
96
|
+
repository: {
|
|
97
|
+
comments: {
|
|
98
|
+
patterns: [
|
|
99
|
+
{
|
|
100
|
+
name: "comment.line.double-slash.pdl",
|
|
101
|
+
match: "//.*$"
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
name: "comment.block.pdl",
|
|
105
|
+
begin: "/\\*",
|
|
106
|
+
end: "\\*/"
|
|
107
|
+
}
|
|
108
|
+
]
|
|
109
|
+
},
|
|
110
|
+
strings: {
|
|
111
|
+
patterns: [
|
|
112
|
+
{
|
|
113
|
+
name: "string.quoted.double.pdl",
|
|
114
|
+
begin: '"',
|
|
115
|
+
end: '"',
|
|
116
|
+
patterns: [
|
|
117
|
+
{
|
|
118
|
+
name: "constant.character.escape.pdl",
|
|
119
|
+
match: '\\\\(?:["\\\\nrt]|u\\{[0-9A-Fa-f]+\\})'
|
|
120
|
+
}
|
|
121
|
+
]
|
|
122
|
+
}
|
|
123
|
+
]
|
|
124
|
+
},
|
|
125
|
+
backtickColumns: {
|
|
126
|
+
patterns: [
|
|
127
|
+
{
|
|
128
|
+
name: "variable.other.column.pdl",
|
|
129
|
+
begin: "`",
|
|
130
|
+
end: "`",
|
|
131
|
+
patterns: [
|
|
132
|
+
{
|
|
133
|
+
name: "constant.character.escape.pdl",
|
|
134
|
+
match: "\\\\(?:[`\\\\])"
|
|
135
|
+
}
|
|
136
|
+
]
|
|
137
|
+
}
|
|
138
|
+
]
|
|
139
|
+
},
|
|
140
|
+
numbers: {
|
|
141
|
+
patterns: [
|
|
142
|
+
{
|
|
143
|
+
name: "constant.numeric.pdl",
|
|
144
|
+
match: "\\b[0-9]+(?:\\.[0-9]+)?(?:[eE][+-]?[0-9]+)?\\b"
|
|
145
|
+
}
|
|
146
|
+
]
|
|
147
|
+
},
|
|
148
|
+
operators: {
|
|
149
|
+
patterns: [
|
|
150
|
+
{
|
|
151
|
+
name: "keyword.operator.pdl",
|
|
152
|
+
match: "\\|"
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
name: "keyword.operator.comparison.pdl",
|
|
156
|
+
match: "==|!=|<=|>=|<|>"
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
name: "keyword.operator.arithmetic.pdl",
|
|
160
|
+
match: "[+\\-*/%]"
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
name: "keyword.operator.context.pdl",
|
|
164
|
+
match: "[$@]"
|
|
165
|
+
}
|
|
166
|
+
]
|
|
167
|
+
},
|
|
168
|
+
contextReferences: {
|
|
169
|
+
patterns: [
|
|
170
|
+
{
|
|
171
|
+
name: "variable.parameter.context.pdl",
|
|
172
|
+
match: "[$@][A-Za-z_][A-Za-z0-9_]*\\b"
|
|
173
|
+
}
|
|
174
|
+
]
|
|
175
|
+
},
|
|
176
|
+
declarations: {
|
|
177
|
+
patterns: [
|
|
178
|
+
{
|
|
179
|
+
name: "meta.context.declaration.pdl",
|
|
180
|
+
match: "\\b(param|state)\\s+([A-Za-z_][A-Za-z0-9_]*)\\b",
|
|
181
|
+
captures: {
|
|
182
|
+
"1": {
|
|
183
|
+
name: "keyword.declaration.pdl"
|
|
184
|
+
},
|
|
185
|
+
"2": {
|
|
186
|
+
name: "variable.parameter.declaration.pdl"
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
name: "meta.binding.declaration.pdl",
|
|
192
|
+
match: "\\b(let)\\s+([A-Za-z_][A-Za-z0-9_]*)\\b",
|
|
193
|
+
captures: {
|
|
194
|
+
"1": {
|
|
195
|
+
name: "keyword.declaration.pdl"
|
|
196
|
+
},
|
|
197
|
+
"2": {
|
|
198
|
+
name: "variable.other.declaration.pdl"
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
name: "meta.output.declaration.pdl",
|
|
204
|
+
match: "\\b(output)\\s+([A-Za-z_][A-Za-z0-9_]*)\\b",
|
|
205
|
+
captures: {
|
|
206
|
+
"1": {
|
|
207
|
+
name: "keyword.declaration.pdl"
|
|
208
|
+
},
|
|
209
|
+
"2": {
|
|
210
|
+
name: "entity.name.function.output.pdl"
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
name: "variable.parameter.pdl",
|
|
216
|
+
match: "\\b[A-Za-z_][A-Za-z0-9_]*\\b(?=\\s*=(?!=))"
|
|
217
|
+
}
|
|
218
|
+
]
|
|
219
|
+
},
|
|
220
|
+
keywords: {
|
|
221
|
+
patterns: [
|
|
222
|
+
{
|
|
223
|
+
name: "keyword.control.pdl",
|
|
224
|
+
match: "\\b(?:let|output|param|state|load|filter|select|drop|rename|mutate|group_by|agg|sort|limit|join|union|distinct|pivot_longer|complete|save|on|kind|by_name|names_to|values_to|fill|format|over|partition_by|order_by|rows|between|unbounded_preceding|current_row|unbounded_following|preceding|following|stdin|stdout|and|or|not|asc|desc|inner|left|right|full|semi|anti|nulls_first|nulls_last)\\b"
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
name: "constant.language.pdl",
|
|
228
|
+
match: "\\b(?:true|false|null)\\b"
|
|
229
|
+
}
|
|
230
|
+
]
|
|
231
|
+
},
|
|
232
|
+
functions: {
|
|
233
|
+
patterns: [
|
|
234
|
+
{
|
|
235
|
+
name: "support.function.window.pdl",
|
|
236
|
+
match: "\\b(?:count|count_distinct|sum|mean|min|max)\\b(?=\\s*\\([^)]*\\)\\s*over\\b)"
|
|
237
|
+
},
|
|
238
|
+
{
|
|
239
|
+
name: "support.function.aggregate.pdl",
|
|
240
|
+
match: "\\b(?:count|count_distinct|sum|mean|min|max)\\b(?=\\s*\\()"
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
name: "support.function.scalar.pdl",
|
|
244
|
+
match: "\\b(?:is_null|not_null|coalesce|concat|lower|upper|trim|to_number|abs|round|if_else|col)\\b(?=\\s*\\()"
|
|
245
|
+
},
|
|
246
|
+
{
|
|
247
|
+
name: "support.function.window.pdl",
|
|
248
|
+
match: "\\b(?:row_number|rank|dense_rank|percent_rank|cume_dist|lag|lead|first_value|last_value)\\b(?=\\s*\\()"
|
|
249
|
+
}
|
|
250
|
+
]
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
// src/index.tsx
|
|
256
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
257
|
+
var PDL_LANGUAGE_ID = "pdl";
|
|
258
|
+
var PDL_SCOPE_NAME = "source.pdl";
|
|
259
|
+
var PDL_THEME_NAME = "pdl-playground";
|
|
260
|
+
var PDL_MARKER_OWNER = "pdl-wasm";
|
|
261
|
+
var PDL_DEFAULT_MODEL_URI = "inmemory://pdl/main.pdl";
|
|
262
|
+
var SEMANTIC_TOKEN_TYPES = [
|
|
263
|
+
"keyword",
|
|
264
|
+
"function",
|
|
265
|
+
"variable",
|
|
266
|
+
"string",
|
|
267
|
+
"number",
|
|
268
|
+
"operator",
|
|
269
|
+
"pdlBindingDeclaration",
|
|
270
|
+
"pdlBindingReference",
|
|
271
|
+
"pdlColumnDefinition",
|
|
272
|
+
"pdlColumnReference",
|
|
273
|
+
"pdlContextDeclaration",
|
|
274
|
+
"pdlContextReference"
|
|
275
|
+
];
|
|
276
|
+
var setupPromise = null;
|
|
277
|
+
var onigasmPromise = null;
|
|
278
|
+
var providerDisposable = null;
|
|
279
|
+
var editorContexts = /* @__PURE__ */ new Map();
|
|
280
|
+
function PdlEditor({
|
|
281
|
+
value,
|
|
282
|
+
files,
|
|
283
|
+
diagnostics,
|
|
284
|
+
runtime,
|
|
285
|
+
onChange,
|
|
286
|
+
modelUri,
|
|
287
|
+
languageId = PDL_LANGUAGE_ID,
|
|
288
|
+
themeName = PDL_THEME_NAME,
|
|
289
|
+
theme,
|
|
290
|
+
className = "pdl-editor-shell",
|
|
291
|
+
editorClassName = "pdl-editor",
|
|
292
|
+
options,
|
|
293
|
+
setupOptions
|
|
294
|
+
}) {
|
|
295
|
+
const hostRef = React.useRef(null);
|
|
296
|
+
const editorRef = React.useRef(null);
|
|
297
|
+
const modelRef = React.useRef(null);
|
|
298
|
+
const onChangeRef = React.useRef(onChange);
|
|
299
|
+
const diagnosticsRef = React.useRef(diagnostics);
|
|
300
|
+
const filesRef = React.useRef(files);
|
|
301
|
+
const runtimeRef = React.useRef(runtime);
|
|
302
|
+
const [setupError, setSetupError] = React.useState(null);
|
|
303
|
+
const resolvedModelUri = React.useMemo(() => monaco.Uri.parse(modelUri ?? PDL_DEFAULT_MODEL_URI), [modelUri]);
|
|
304
|
+
React.useEffect(() => {
|
|
305
|
+
onChangeRef.current = onChange;
|
|
306
|
+
}, [onChange]);
|
|
307
|
+
React.useEffect(() => {
|
|
308
|
+
filesRef.current = files;
|
|
309
|
+
}, [files]);
|
|
310
|
+
React.useEffect(() => {
|
|
311
|
+
runtimeRef.current = runtime;
|
|
312
|
+
}, [runtime]);
|
|
313
|
+
React.useEffect(() => {
|
|
314
|
+
diagnosticsRef.current = diagnostics;
|
|
315
|
+
const model = modelRef.current;
|
|
316
|
+
if (model) {
|
|
317
|
+
setPdlMarkers(model, diagnostics);
|
|
318
|
+
}
|
|
319
|
+
}, [diagnostics]);
|
|
320
|
+
React.useEffect(() => {
|
|
321
|
+
const model = modelRef.current;
|
|
322
|
+
if (model && model.getValue() !== value) {
|
|
323
|
+
const selection = editorRef.current?.getSelection() ?? null;
|
|
324
|
+
model.setValue(value);
|
|
325
|
+
if (selection) {
|
|
326
|
+
editorRef.current?.setSelection(selection);
|
|
327
|
+
}
|
|
328
|
+
setPdlMarkers(model, diagnosticsRef.current);
|
|
329
|
+
}
|
|
330
|
+
}, [value]);
|
|
331
|
+
React.useEffect(() => {
|
|
332
|
+
let cancelled = false;
|
|
333
|
+
let editor2 = null;
|
|
334
|
+
let model = null;
|
|
335
|
+
let contentDisposable = null;
|
|
336
|
+
let contextKey = null;
|
|
337
|
+
setupPdlMonaco({ ...setupOptions, languageId, themeName, theme }).then(() => {
|
|
338
|
+
if (cancelled || !hostRef.current) {
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
ensurePdlProviders(languageId);
|
|
342
|
+
model = monaco.editor.createModel(value, languageId, resolvedModelUri);
|
|
343
|
+
contextKey = model.uri.toString();
|
|
344
|
+
editorContexts.set(contextKey, {
|
|
345
|
+
runtime: () => runtimeRef.current,
|
|
346
|
+
files: () => filesRef.current
|
|
347
|
+
});
|
|
348
|
+
editor2 = monaco.editor.create(hostRef.current, {
|
|
349
|
+
model,
|
|
350
|
+
theme: themeName,
|
|
351
|
+
automaticLayout: true,
|
|
352
|
+
bracketPairColorization: { enabled: true },
|
|
353
|
+
cursorBlinking: "smooth",
|
|
354
|
+
fixedOverflowWidgets: true,
|
|
355
|
+
fontFamily: '"SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace',
|
|
356
|
+
fontSize: 13,
|
|
357
|
+
lineHeight: 20,
|
|
358
|
+
minimap: { enabled: false },
|
|
359
|
+
overviewRulerBorder: false,
|
|
360
|
+
padding: { top: 12, bottom: 12 },
|
|
361
|
+
renderLineHighlight: "line",
|
|
362
|
+
scrollBeyondLastLine: false,
|
|
363
|
+
smoothScrolling: true,
|
|
364
|
+
tabSize: 2,
|
|
365
|
+
wordWrap: "off",
|
|
366
|
+
...options
|
|
367
|
+
});
|
|
368
|
+
modelRef.current = model;
|
|
369
|
+
editorRef.current = editor2;
|
|
370
|
+
setPdlMarkers(model, diagnosticsRef.current);
|
|
371
|
+
contentDisposable = model.onDidChangeContent(() => {
|
|
372
|
+
onChangeRef.current(model?.getValue() ?? "");
|
|
373
|
+
});
|
|
374
|
+
}).catch((err) => {
|
|
375
|
+
if (!cancelled) {
|
|
376
|
+
setSetupError(err instanceof Error ? err.message : String(err));
|
|
377
|
+
}
|
|
378
|
+
});
|
|
379
|
+
return () => {
|
|
380
|
+
cancelled = true;
|
|
381
|
+
contentDisposable?.dispose();
|
|
382
|
+
if (contextKey) {
|
|
383
|
+
editorContexts.delete(contextKey);
|
|
384
|
+
}
|
|
385
|
+
if (model) {
|
|
386
|
+
monaco.editor.setModelMarkers(model, PDL_MARKER_OWNER, []);
|
|
387
|
+
}
|
|
388
|
+
editor2?.dispose();
|
|
389
|
+
model?.dispose();
|
|
390
|
+
if (editorRef.current === editor2) {
|
|
391
|
+
editorRef.current = null;
|
|
392
|
+
}
|
|
393
|
+
if (modelRef.current === model) {
|
|
394
|
+
modelRef.current = null;
|
|
395
|
+
}
|
|
396
|
+
};
|
|
397
|
+
}, [languageId, options, resolvedModelUri, setupOptions, theme, themeName]);
|
|
398
|
+
return /* @__PURE__ */ jsxs("div", { className, children: [
|
|
399
|
+
/* @__PURE__ */ jsx("div", { "aria-label": "PDL source", className: editorClassName, ref: hostRef }),
|
|
400
|
+
setupError ? /* @__PURE__ */ jsxs("div", { className: "editor-error", children: [
|
|
401
|
+
"Editor failed to load: ",
|
|
402
|
+
setupError
|
|
403
|
+
] }) : null
|
|
404
|
+
] });
|
|
405
|
+
}
|
|
406
|
+
function setupPdlMonaco(options = {}) {
|
|
407
|
+
setupPromise ?? (setupPromise = setupPdlMonacoOnce(options).catch((error) => {
|
|
408
|
+
setupPromise = null;
|
|
409
|
+
throw error;
|
|
410
|
+
}));
|
|
411
|
+
return setupPromise;
|
|
412
|
+
}
|
|
413
|
+
function registerPdlLanguage(options = {}) {
|
|
414
|
+
const languageId = options.languageId ?? PDL_LANGUAGE_ID;
|
|
415
|
+
if (monaco.languages.getLanguages().some((language) => language.id === languageId)) {
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
monaco.languages.register({
|
|
419
|
+
id: languageId,
|
|
420
|
+
aliases: options.aliases ?? ["PDL", "pdl"],
|
|
421
|
+
extensions: options.extensions ?? [".pdl"]
|
|
422
|
+
});
|
|
423
|
+
monaco.languages.setLanguageConfiguration(
|
|
424
|
+
languageId,
|
|
425
|
+
options.languageConfiguration ?? language_configuration_default
|
|
426
|
+
);
|
|
427
|
+
}
|
|
428
|
+
function definePdlTheme(themeName = PDL_THEME_NAME, theme = defaultPdlTheme()) {
|
|
429
|
+
monaco.editor.defineTheme(themeName, theme);
|
|
430
|
+
}
|
|
431
|
+
function defaultPdlTheme() {
|
|
432
|
+
return {
|
|
433
|
+
base: "vs",
|
|
434
|
+
inherit: true,
|
|
435
|
+
rules: [
|
|
436
|
+
{ token: "comment", foreground: "6b7280", fontStyle: "italic" },
|
|
437
|
+
{ token: "string", foreground: "7a4a10" },
|
|
438
|
+
{ token: "number", foreground: "b42318" },
|
|
439
|
+
{ token: "keyword", foreground: "166f5c", fontStyle: "bold" },
|
|
440
|
+
{ token: "function", foreground: "0f5f8f", fontStyle: "bold" },
|
|
441
|
+
{ token: "property", foreground: "0e7490" },
|
|
442
|
+
{ token: "variable", foreground: "355f8c" },
|
|
443
|
+
{ token: "pdlBindingDeclaration", foreground: "7c3aed", fontStyle: "bold" },
|
|
444
|
+
{ token: "pdlBindingReference", foreground: "6d28d9" },
|
|
445
|
+
{ token: "pdlColumnDefinition", foreground: "475569" },
|
|
446
|
+
{ token: "pdlColumnReference", foreground: "0e7490" },
|
|
447
|
+
{ token: "pdlContextDeclaration", foreground: "9a5512", fontStyle: "bold" },
|
|
448
|
+
{ token: "pdlContextReference", foreground: "9a5512" },
|
|
449
|
+
{ token: "operator", foreground: "4f5b63" },
|
|
450
|
+
{ token: "constant.character.escape", foreground: "9f5b00", fontStyle: "bold" },
|
|
451
|
+
{ token: "constant.numeric", foreground: "b42318" },
|
|
452
|
+
{ token: "constant.language", foreground: "6f42c1" },
|
|
453
|
+
{ token: "invalid.illegal", foreground: "b42318", fontStyle: "underline" },
|
|
454
|
+
{ token: "keyword.control", foreground: "166f5c", fontStyle: "bold" },
|
|
455
|
+
{ token: "keyword.declaration", foreground: "166f5c", fontStyle: "bold" },
|
|
456
|
+
{ token: "keyword.operator.frame", foreground: "7a3f98", fontStyle: "bold" },
|
|
457
|
+
{ token: "keyword.operator", foreground: "4f5b63" },
|
|
458
|
+
{ token: "support.function", foreground: "0f5f8f", fontStyle: "bold" },
|
|
459
|
+
{ token: "support.function.aggregate", foreground: "0f5f8f", fontStyle: "bold" },
|
|
460
|
+
{ token: "support.function.aggregate.pdl", foreground: "0f5f8f", fontStyle: "bold" },
|
|
461
|
+
{ token: "support.function.scalar", foreground: "0f5f8f", fontStyle: "bold" },
|
|
462
|
+
{ token: "support.function.scalar.pdl", foreground: "0f5f8f", fontStyle: "bold" },
|
|
463
|
+
{ token: "support.function.window", foreground: "0f5f8f", fontStyle: "bold" },
|
|
464
|
+
{ token: "support.function.window.pdl", foreground: "0f5f8f", fontStyle: "bold" },
|
|
465
|
+
{ token: "entity.name.function.geometry", foreground: "0f5f8f", fontStyle: "bold" },
|
|
466
|
+
{ token: "entity.name.function.stat", foreground: "7a3f98", fontStyle: "bold" },
|
|
467
|
+
{ token: "entity.name.function.source", foreground: "3c6b22", fontStyle: "bold" },
|
|
468
|
+
{ token: "entity.name.function.literal", foreground: "6f42c1" },
|
|
469
|
+
{ token: "entity.name.function", foreground: "315f7d" },
|
|
470
|
+
{ token: "entity.name.namespace", foreground: "7c3aed", fontStyle: "bold" },
|
|
471
|
+
{ token: "support.type.namespace", foreground: "2563eb", fontStyle: "bold" },
|
|
472
|
+
{ token: "variable.parameter.property.unknown", foreground: "a33d2d" },
|
|
473
|
+
{ token: "variable.parameter.property", foreground: "9a5512" },
|
|
474
|
+
{ token: "variable.other.declaration", foreground: "7c3aed", fontStyle: "bold" },
|
|
475
|
+
{ token: "variable.other.binding", foreground: "2563eb", fontStyle: "bold" },
|
|
476
|
+
{ token: "variable.other.quoted", foreground: "385f70" },
|
|
477
|
+
{ token: "variable.parameter", foreground: "475569" },
|
|
478
|
+
{ token: "variable.other.member", foreground: "475569" },
|
|
479
|
+
{ token: "variable.other.readwrite", foreground: "475569" },
|
|
480
|
+
{ token: "variable.other.column.definition", foreground: "475569" },
|
|
481
|
+
{ token: "variable.other.column", foreground: "0e7490" },
|
|
482
|
+
{ token: "punctuation", foreground: "68757d" }
|
|
483
|
+
],
|
|
484
|
+
colors: {
|
|
485
|
+
"editor.background": "#ffffff",
|
|
486
|
+
"editor.foreground": "#171f24",
|
|
487
|
+
"editor.lineHighlightBackground": "#f4f7f6",
|
|
488
|
+
"editorLineNumber.foreground": "#9aa6ac",
|
|
489
|
+
"editorLineNumber.activeForeground": "#21695d",
|
|
490
|
+
"editorCursor.foreground": "#1f6f62",
|
|
491
|
+
"editor.selectionBackground": "#cfe8df",
|
|
492
|
+
"editor.inactiveSelectionBackground": "#e8f2ee",
|
|
493
|
+
"editorIndentGuide.background1": "#edf1f3",
|
|
494
|
+
"editorIndentGuide.activeBackground1": "#c9d8d3"
|
|
495
|
+
}
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
function registerPdlEditorProviders(options) {
|
|
499
|
+
const languageId = options.languageId ?? PDL_LANGUAGE_ID;
|
|
500
|
+
const programPathForRequest = options.programPathForModel ?? programPathForModel;
|
|
501
|
+
const disposables = [
|
|
502
|
+
monaco.languages.registerHoverProvider(languageId, {
|
|
503
|
+
provideHover(model, position) {
|
|
504
|
+
const hover = requestFeature(model, options, programPathForRequest, {
|
|
505
|
+
kind: "hover",
|
|
506
|
+
position: toTextPosition(position)
|
|
507
|
+
});
|
|
508
|
+
if (!hover) {
|
|
509
|
+
return null;
|
|
510
|
+
}
|
|
511
|
+
return {
|
|
512
|
+
contents: [{ value: hover.markdown, isTrusted: false, supportHtml: false }],
|
|
513
|
+
range: fromTextRange(hover.range)
|
|
514
|
+
};
|
|
515
|
+
}
|
|
516
|
+
}),
|
|
517
|
+
monaco.languages.registerCompletionItemProvider(languageId, {
|
|
518
|
+
triggerCharacters: ["|", '"', " ", "$", "@"],
|
|
519
|
+
provideCompletionItems(model, position) {
|
|
520
|
+
const completions = requestFeature(model, options, programPathForRequest, {
|
|
521
|
+
kind: "completion",
|
|
522
|
+
position: toTextPosition(position)
|
|
523
|
+
});
|
|
524
|
+
return {
|
|
525
|
+
suggestions: (completions ?? []).map((item) => completionItem(item, position))
|
|
526
|
+
};
|
|
527
|
+
}
|
|
528
|
+
}),
|
|
529
|
+
monaco.languages.registerDocumentFormattingEditProvider(languageId, {
|
|
530
|
+
provideDocumentFormattingEdits(model) {
|
|
531
|
+
const edit = requestFeature(model, options, programPathForRequest, {
|
|
532
|
+
kind: "formatting"
|
|
533
|
+
});
|
|
534
|
+
return edit ? [textEdit(edit)] : [];
|
|
535
|
+
}
|
|
536
|
+
}),
|
|
537
|
+
monaco.languages.registerDocumentSemanticTokensProvider(languageId, {
|
|
538
|
+
getLegend() {
|
|
539
|
+
return {
|
|
540
|
+
tokenTypes: SEMANTIC_TOKEN_TYPES,
|
|
541
|
+
tokenModifiers: []
|
|
542
|
+
};
|
|
543
|
+
},
|
|
544
|
+
provideDocumentSemanticTokens(model) {
|
|
545
|
+
const tokens = requestFeature(model, options, programPathForRequest, {
|
|
546
|
+
kind: "semanticTokens"
|
|
547
|
+
});
|
|
548
|
+
return {
|
|
549
|
+
data: new Uint32Array(encodeSemanticTokens(tokens ?? [])),
|
|
550
|
+
resultId: void 0
|
|
551
|
+
};
|
|
552
|
+
},
|
|
553
|
+
releaseDocumentSemanticTokens() {
|
|
554
|
+
return void 0;
|
|
555
|
+
}
|
|
556
|
+
}),
|
|
557
|
+
monaco.languages.registerDefinitionProvider(languageId, {
|
|
558
|
+
provideDefinition(model, position) {
|
|
559
|
+
const location = requestFeature(model, options, programPathForRequest, {
|
|
560
|
+
kind: "definition",
|
|
561
|
+
position: toTextPosition(position)
|
|
562
|
+
});
|
|
563
|
+
return location ? [{ uri: model.uri, range: fromTextRange(location.range) }] : [];
|
|
564
|
+
}
|
|
565
|
+
}),
|
|
566
|
+
monaco.languages.registerReferenceProvider(languageId, {
|
|
567
|
+
provideReferences(model, position) {
|
|
568
|
+
const locations = requestFeature(model, options, programPathForRequest, {
|
|
569
|
+
kind: "references",
|
|
570
|
+
position: toTextPosition(position)
|
|
571
|
+
});
|
|
572
|
+
return (locations ?? []).map((location) => ({
|
|
573
|
+
uri: model.uri,
|
|
574
|
+
range: fromTextRange(location.range)
|
|
575
|
+
}));
|
|
576
|
+
}
|
|
577
|
+
}),
|
|
578
|
+
monaco.languages.registerRenameProvider(languageId, {
|
|
579
|
+
provideRenameEdits(model, position, newName) {
|
|
580
|
+
const edits = requestFeature(model, options, programPathForRequest, {
|
|
581
|
+
kind: "rename",
|
|
582
|
+
position: toTextPosition(position),
|
|
583
|
+
newName
|
|
584
|
+
});
|
|
585
|
+
return {
|
|
586
|
+
edits: (edits ?? []).map((edit) => ({
|
|
587
|
+
resource: model.uri,
|
|
588
|
+
textEdit: textEdit(edit),
|
|
589
|
+
versionId: void 0
|
|
590
|
+
}))
|
|
591
|
+
};
|
|
592
|
+
}
|
|
593
|
+
}),
|
|
594
|
+
monaco.languages.registerDocumentSymbolProvider(languageId, {
|
|
595
|
+
provideDocumentSymbols(model) {
|
|
596
|
+
const symbols = requestFeature(model, options, programPathForRequest, {
|
|
597
|
+
kind: "documentSymbols"
|
|
598
|
+
});
|
|
599
|
+
return (symbols ?? []).map(documentSymbol);
|
|
600
|
+
}
|
|
601
|
+
})
|
|
602
|
+
];
|
|
603
|
+
return {
|
|
604
|
+
dispose() {
|
|
605
|
+
for (const disposable of disposables) {
|
|
606
|
+
disposable.dispose();
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
};
|
|
610
|
+
}
|
|
611
|
+
function programPathForModel(model) {
|
|
612
|
+
const path = model.uri.path.replace(/^\/+/, "");
|
|
613
|
+
return path ? `memory/${path}` : "memory/main.pdl";
|
|
614
|
+
}
|
|
615
|
+
function setPdlMarkers(model, diagnostics) {
|
|
616
|
+
monaco.editor.setModelMarkers(
|
|
617
|
+
model,
|
|
618
|
+
PDL_MARKER_OWNER,
|
|
619
|
+
diagnostics.map((diagnostic) => diagnosticToPdlMarker(diagnostic))
|
|
620
|
+
);
|
|
621
|
+
}
|
|
622
|
+
function diagnosticToPdlMarker(diagnostic) {
|
|
623
|
+
const start = fromTextPosition(diagnostic.range.start);
|
|
624
|
+
const end = fromTextPosition(diagnostic.range.end);
|
|
625
|
+
return {
|
|
626
|
+
code: diagnostic.code,
|
|
627
|
+
severity: severityToMarkerSeverity(diagnostic.severity),
|
|
628
|
+
source: "PDL",
|
|
629
|
+
message: diagnostic.message,
|
|
630
|
+
startLineNumber: start.lineNumber,
|
|
631
|
+
startColumn: start.column,
|
|
632
|
+
endLineNumber: end.lineNumber,
|
|
633
|
+
endColumn: end.column === start.column && end.lineNumber === start.lineNumber ? end.column + 1 : end.column
|
|
634
|
+
};
|
|
635
|
+
}
|
|
636
|
+
function ensurePdlProviders(languageId) {
|
|
637
|
+
providerDisposable ?? (providerDisposable = registerPdlEditorProviders({
|
|
638
|
+
languageId,
|
|
639
|
+
getRuntime: (model) => editorContexts.get(model.uri.toString())?.runtime() ?? null,
|
|
640
|
+
getFiles: (model) => editorContexts.get(model.uri.toString())?.files() ?? {}
|
|
641
|
+
}));
|
|
642
|
+
}
|
|
643
|
+
async function setupPdlMonacoOnce(options) {
|
|
644
|
+
if (options.configureWorker !== false) {
|
|
645
|
+
configureMonacoWorker();
|
|
646
|
+
}
|
|
647
|
+
registerPdlLanguage(options);
|
|
648
|
+
definePdlTheme(options.themeName ?? PDL_THEME_NAME, options.theme ?? defaultPdlTheme());
|
|
649
|
+
await loadOnigasmOnce(options.onigasmWasmUrl ?? onigasmWasmUrl);
|
|
650
|
+
const registry = new Registry({
|
|
651
|
+
getGrammarDefinition: async () => ({
|
|
652
|
+
format: "json",
|
|
653
|
+
content: options.grammar ?? pdl_tmLanguage_default
|
|
654
|
+
})
|
|
655
|
+
});
|
|
656
|
+
await wireTmGrammars(
|
|
657
|
+
monaco,
|
|
658
|
+
registry,
|
|
659
|
+
/* @__PURE__ */ new Map([[options.languageId ?? PDL_LANGUAGE_ID, options.scopeName ?? PDL_SCOPE_NAME]])
|
|
660
|
+
);
|
|
661
|
+
}
|
|
662
|
+
function configureMonacoWorker() {
|
|
663
|
+
const target = globalThis;
|
|
664
|
+
target.MonacoEnvironment ?? (target.MonacoEnvironment = {
|
|
665
|
+
getWorker: () => new EditorWorker()
|
|
666
|
+
});
|
|
667
|
+
}
|
|
668
|
+
function loadOnigasmOnce(url) {
|
|
669
|
+
onigasmPromise ?? (onigasmPromise = loadOnigasm(url).catch((error) => {
|
|
670
|
+
onigasmPromise = null;
|
|
671
|
+
throw error;
|
|
672
|
+
}));
|
|
673
|
+
return onigasmPromise;
|
|
674
|
+
}
|
|
675
|
+
function requestFeature(model, options, resolveProgramPath, request) {
|
|
676
|
+
const runtime = options.getRuntime(model);
|
|
677
|
+
if (!runtime) {
|
|
678
|
+
return null;
|
|
679
|
+
}
|
|
680
|
+
const response = runtime.editorService(model.getValue(), options.getFiles(model), request, resolveProgramPath(model));
|
|
681
|
+
if (response.error) {
|
|
682
|
+
console.warn(`PDL editor service failed: ${response.error}`);
|
|
683
|
+
return null;
|
|
684
|
+
}
|
|
685
|
+
return response.result;
|
|
686
|
+
}
|
|
687
|
+
function toTextPosition(position) {
|
|
688
|
+
return {
|
|
689
|
+
line: Math.max(0, position.lineNumber - 1),
|
|
690
|
+
character: Math.max(0, position.column - 1)
|
|
691
|
+
};
|
|
692
|
+
}
|
|
693
|
+
function fromTextPosition(position) {
|
|
694
|
+
return {
|
|
695
|
+
lineNumber: position.line + 1,
|
|
696
|
+
column: position.character + 1
|
|
697
|
+
};
|
|
698
|
+
}
|
|
699
|
+
function fromTextRange(range) {
|
|
700
|
+
const start = fromTextPosition(range.start);
|
|
701
|
+
const end = fromTextPosition(range.end);
|
|
702
|
+
return new monaco.Range(start.lineNumber, start.column, end.lineNumber, end.column);
|
|
703
|
+
}
|
|
704
|
+
function completionItem(item, position) {
|
|
705
|
+
return {
|
|
706
|
+
label: item.label,
|
|
707
|
+
kind: completionKind(item.kind),
|
|
708
|
+
detail: item.detail,
|
|
709
|
+
insertText: item.insert_text,
|
|
710
|
+
range: new monaco.Range(position.lineNumber, position.column, position.lineNumber, position.column)
|
|
711
|
+
};
|
|
712
|
+
}
|
|
713
|
+
function completionKind(kind) {
|
|
714
|
+
switch (kind) {
|
|
715
|
+
case "Binding":
|
|
716
|
+
case "Context":
|
|
717
|
+
return monaco.languages.CompletionItemKind.Variable;
|
|
718
|
+
case "Column":
|
|
719
|
+
return monaco.languages.CompletionItemKind.Field;
|
|
720
|
+
case "Format":
|
|
721
|
+
return monaco.languages.CompletionItemKind.EnumMember;
|
|
722
|
+
case "Function":
|
|
723
|
+
return monaco.languages.CompletionItemKind.Function;
|
|
724
|
+
case "Keyword":
|
|
725
|
+
case "Stage":
|
|
726
|
+
return monaco.languages.CompletionItemKind.Keyword;
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
function textEdit(edit) {
|
|
730
|
+
return {
|
|
731
|
+
range: fromTextRange(edit.range),
|
|
732
|
+
text: edit.new_text
|
|
733
|
+
};
|
|
734
|
+
}
|
|
735
|
+
function encodeSemanticTokens(tokens) {
|
|
736
|
+
let previousLine = 0;
|
|
737
|
+
let previousStart = 0;
|
|
738
|
+
const data = [];
|
|
739
|
+
for (const token of tokens) {
|
|
740
|
+
if (token.range.start.line !== token.range.end.line) {
|
|
741
|
+
continue;
|
|
742
|
+
}
|
|
743
|
+
const deltaLine = token.range.start.line - previousLine;
|
|
744
|
+
const deltaStart = deltaLine === 0 ? token.range.start.character - previousStart : token.range.start.character;
|
|
745
|
+
const length = token.range.end.character - token.range.start.character;
|
|
746
|
+
if (length <= 0) {
|
|
747
|
+
continue;
|
|
748
|
+
}
|
|
749
|
+
data.push(deltaLine, deltaStart, length, semanticTokenIndex(token.token_type), 0);
|
|
750
|
+
previousLine = token.range.start.line;
|
|
751
|
+
previousStart = token.range.start.character;
|
|
752
|
+
}
|
|
753
|
+
return data;
|
|
754
|
+
}
|
|
755
|
+
function semanticTokenIndex(kind) {
|
|
756
|
+
switch (kind) {
|
|
757
|
+
case "Keyword":
|
|
758
|
+
return 0;
|
|
759
|
+
case "Function":
|
|
760
|
+
return 1;
|
|
761
|
+
case "Variable":
|
|
762
|
+
return 2;
|
|
763
|
+
case "String":
|
|
764
|
+
return 3;
|
|
765
|
+
case "Number":
|
|
766
|
+
return 4;
|
|
767
|
+
case "Operator":
|
|
768
|
+
return 5;
|
|
769
|
+
case "BindingDeclaration":
|
|
770
|
+
return 6;
|
|
771
|
+
case "BindingReference":
|
|
772
|
+
return 7;
|
|
773
|
+
case "ColumnDefinition":
|
|
774
|
+
return 8;
|
|
775
|
+
case "ColumnReference":
|
|
776
|
+
return 9;
|
|
777
|
+
case "ContextDeclaration":
|
|
778
|
+
return 10;
|
|
779
|
+
case "ContextReference":
|
|
780
|
+
return 11;
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
function documentSymbol(symbol) {
|
|
784
|
+
return {
|
|
785
|
+
name: symbol.name,
|
|
786
|
+
detail: symbol.detail,
|
|
787
|
+
kind: symbolKind(symbol.kind),
|
|
788
|
+
range: fromTextRange(symbol.range),
|
|
789
|
+
selectionRange: fromTextRange(symbol.selection_range),
|
|
790
|
+
tags: [],
|
|
791
|
+
children: symbol.children.map(documentSymbol)
|
|
792
|
+
};
|
|
793
|
+
}
|
|
794
|
+
function symbolKind(kind) {
|
|
795
|
+
switch (kind) {
|
|
796
|
+
case "Binding":
|
|
797
|
+
case "Context":
|
|
798
|
+
return monaco.languages.SymbolKind.Variable;
|
|
799
|
+
case "Function":
|
|
800
|
+
return monaco.languages.SymbolKind.Function;
|
|
801
|
+
case "Stage":
|
|
802
|
+
return monaco.languages.SymbolKind.Method;
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
function severityToMarkerSeverity(severity) {
|
|
806
|
+
switch (severity) {
|
|
807
|
+
case "error":
|
|
808
|
+
return monaco.MarkerSeverity.Error;
|
|
809
|
+
case "warning":
|
|
810
|
+
return monaco.MarkerSeverity.Warning;
|
|
811
|
+
case "info":
|
|
812
|
+
return monaco.MarkerSeverity.Info;
|
|
813
|
+
case "hint":
|
|
814
|
+
return monaco.MarkerSeverity.Hint;
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
export {
|
|
818
|
+
PDL_DEFAULT_MODEL_URI,
|
|
819
|
+
PDL_LANGUAGE_ID,
|
|
820
|
+
PDL_MARKER_OWNER,
|
|
821
|
+
PDL_SCOPE_NAME,
|
|
822
|
+
PDL_THEME_NAME,
|
|
823
|
+
PdlEditor,
|
|
824
|
+
defaultPdlTheme,
|
|
825
|
+
definePdlTheme,
|
|
826
|
+
diagnosticToPdlMarker,
|
|
827
|
+
programPathForModel,
|
|
828
|
+
registerPdlEditorProviders,
|
|
829
|
+
registerPdlLanguage,
|
|
830
|
+
setPdlMarkers,
|
|
831
|
+
setupPdlMonaco
|
|
832
|
+
};
|