@coze-editor/preset-code 0.1.0-alpha.09ffeb
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/LICENSE +21 -0
- package/dist/esm/index.js +1281 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/index.d.mts +117 -0
- package/dist/index.d.ts +117 -0
- package/dist/index.js +1246 -0
- package/dist/index.js.map +1 -0
- package/package.json +73 -0
|
@@ -0,0 +1,1281 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import universal from "@coze-editor/preset-universal";
|
|
3
|
+
import {
|
|
4
|
+
scrollBeyondLastLine,
|
|
5
|
+
colorizationBrackets,
|
|
6
|
+
matchingBrackets
|
|
7
|
+
} from "@coze-editor/extensions";
|
|
8
|
+
import { scrollbar } from "@coze-editor/extension-scrollbar";
|
|
9
|
+
import { icons } from "@coze-editor/extension-completion-icons";
|
|
10
|
+
import { maxHeight, minHeight, height } from "@coze-editor/core-plugins";
|
|
11
|
+
import {
|
|
12
|
+
api,
|
|
13
|
+
extension,
|
|
14
|
+
option
|
|
15
|
+
} from "@coze-editor/core";
|
|
16
|
+
import {
|
|
17
|
+
uriFacet,
|
|
18
|
+
languageIdFacet,
|
|
19
|
+
transformerFacet,
|
|
20
|
+
textDocumentField as textDocumentField2
|
|
21
|
+
} from "@coze-editor/code-language-shared";
|
|
22
|
+
import { EditorView as EditorView4, lineNumbers } from "@codemirror/view";
|
|
23
|
+
import { Prec } from "@codemirror/state";
|
|
24
|
+
import { foldGutter } from "@codemirror/language";
|
|
25
|
+
|
|
26
|
+
// src/themes.ts
|
|
27
|
+
var Themes = class {
|
|
28
|
+
_store = /* @__PURE__ */ Object.create(null);
|
|
29
|
+
register(name, theme) {
|
|
30
|
+
this._store[name] = theme;
|
|
31
|
+
}
|
|
32
|
+
get(name) {
|
|
33
|
+
return this._store[name];
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
var symbol = Symbol.for("codemirror.themes");
|
|
37
|
+
if (!globalThis[symbol]) {
|
|
38
|
+
globalThis[symbol] = new Themes();
|
|
39
|
+
}
|
|
40
|
+
var themes = globalThis[symbol];
|
|
41
|
+
|
|
42
|
+
// src/theme-vscode.ts
|
|
43
|
+
import {
|
|
44
|
+
darkSyntaxTheme,
|
|
45
|
+
darkTheme,
|
|
46
|
+
lightSyntaxTheme,
|
|
47
|
+
lightTheme
|
|
48
|
+
} from "@coze-editor/vscode";
|
|
49
|
+
import { HighlightStyle, syntaxHighlighting } from "@codemirror/language";
|
|
50
|
+
var vscodeLight = [
|
|
51
|
+
syntaxHighlighting(HighlightStyle.define(lightSyntaxTheme)),
|
|
52
|
+
lightTheme()
|
|
53
|
+
];
|
|
54
|
+
var vscodeDark = [
|
|
55
|
+
syntaxHighlighting(HighlightStyle.define(darkSyntaxTheme)),
|
|
56
|
+
darkTheme()
|
|
57
|
+
];
|
|
58
|
+
|
|
59
|
+
// src/language-registry.ts
|
|
60
|
+
import {
|
|
61
|
+
MarkupContent as MarkupContent2
|
|
62
|
+
} from "vscode-languageserver-types";
|
|
63
|
+
import shiki from "codemirror-shiki";
|
|
64
|
+
import createFuzzySearch from "@nozbe/microfuzz";
|
|
65
|
+
import { linter } from "@coze-editor/extension-lint";
|
|
66
|
+
import { links } from "@coze-editor/extension-links";
|
|
67
|
+
import {
|
|
68
|
+
MarkerTag,
|
|
69
|
+
textDocumentField
|
|
70
|
+
} from "@coze-editor/code-language-shared";
|
|
71
|
+
import {
|
|
72
|
+
EditorView as EditorView2,
|
|
73
|
+
hoverTooltip,
|
|
74
|
+
ViewPlugin as ViewPlugin3
|
|
75
|
+
} from "@codemirror/view";
|
|
76
|
+
import {
|
|
77
|
+
EditorSelection,
|
|
78
|
+
StateField as StateField2
|
|
79
|
+
} from "@codemirror/state";
|
|
80
|
+
import { LanguageSupport } from "@codemirror/language";
|
|
81
|
+
import {
|
|
82
|
+
autocompletion,
|
|
83
|
+
insertCompletionText,
|
|
84
|
+
snippet
|
|
85
|
+
} from "@codemirror/autocomplete";
|
|
86
|
+
|
|
87
|
+
// src/signature-help.ts
|
|
88
|
+
import {
|
|
89
|
+
MarkupContent
|
|
90
|
+
} from "vscode-languageserver-types";
|
|
91
|
+
import {
|
|
92
|
+
EditorView,
|
|
93
|
+
ViewPlugin,
|
|
94
|
+
keymap,
|
|
95
|
+
showTooltip
|
|
96
|
+
} from "@codemirror/view";
|
|
97
|
+
import {
|
|
98
|
+
Facet,
|
|
99
|
+
StateEffect,
|
|
100
|
+
StateField
|
|
101
|
+
} from "@codemirror/state";
|
|
102
|
+
|
|
103
|
+
// src/markdown.ts
|
|
104
|
+
import markedShiki from "marked-shiki";
|
|
105
|
+
import { Marked } from "marked";
|
|
106
|
+
|
|
107
|
+
// src/highlighter.ts
|
|
108
|
+
import { createOnigurumaEngine } from "shiki/engine/oniguruma";
|
|
109
|
+
import { createHighlighterCore } from "shiki/core";
|
|
110
|
+
var highlighterPromise = createHighlighterCore({
|
|
111
|
+
langs: [
|
|
112
|
+
() => import("@shikijs/langs/markdown"),
|
|
113
|
+
() => import("@shikijs/langs/javascript"),
|
|
114
|
+
() => import("@shikijs/langs/typescript"),
|
|
115
|
+
() => import("@shikijs/langs/python"),
|
|
116
|
+
() => import("@shikijs/langs/sql")
|
|
117
|
+
],
|
|
118
|
+
themes: [
|
|
119
|
+
() => import("@shikijs/themes/github-dark"),
|
|
120
|
+
() => import("@shikijs/themes/one-dark-pro")
|
|
121
|
+
],
|
|
122
|
+
engine: createOnigurumaEngine(import("shiki/wasm"))
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
// src/const.ts
|
|
126
|
+
var LINT_REFRESH_USER_EVENT = "sdk.lint.refresh";
|
|
127
|
+
var DEFAULT_SYNTAX_THEME = "one-dark-pro";
|
|
128
|
+
|
|
129
|
+
// src/markdown.ts
|
|
130
|
+
var marked = new Marked().use(
|
|
131
|
+
markedShiki({
|
|
132
|
+
async highlight(code, lang, props) {
|
|
133
|
+
const highlighter = await highlighterPromise;
|
|
134
|
+
return (await highlighter).codeToHtml(code, {
|
|
135
|
+
lang,
|
|
136
|
+
theme: DEFAULT_SYNTAX_THEME,
|
|
137
|
+
transformers: [
|
|
138
|
+
{
|
|
139
|
+
pre(node) {
|
|
140
|
+
delete node.properties.style;
|
|
141
|
+
node.properties.style = "white-space: pre-wrap;";
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
]
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
})
|
|
148
|
+
).use({
|
|
149
|
+
renderer: {
|
|
150
|
+
link(link) {
|
|
151
|
+
return `<a title="${link.title ?? ""}" target="_blank" href="${link.href}">${link.text}</a>`;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
async function renderMarkdown(content) {
|
|
156
|
+
return await marked.parse(content);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// src/signature-help.ts
|
|
160
|
+
var setSignatureHelpRequestPosition = StateEffect.define({});
|
|
161
|
+
var setSignatureHelpResult = StateEffect.define({});
|
|
162
|
+
var SignatureHelpState = class {
|
|
163
|
+
pos;
|
|
164
|
+
// maybe stale
|
|
165
|
+
result;
|
|
166
|
+
constructor(pos, result) {
|
|
167
|
+
if (result && pos === -1) {
|
|
168
|
+
throw new Error("Invalid state");
|
|
169
|
+
}
|
|
170
|
+
this.pos = pos;
|
|
171
|
+
this.result = result;
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
var signatureHelpTooltipField = StateField.define({
|
|
175
|
+
create: () => new SignatureHelpState(-1, null),
|
|
176
|
+
update(state, tr) {
|
|
177
|
+
let { pos, result } = state;
|
|
178
|
+
for (const effect of tr.effects) {
|
|
179
|
+
if (effect.is(setSignatureHelpRequestPosition)) {
|
|
180
|
+
pos = effect.value;
|
|
181
|
+
} else if (effect.is(setSignatureHelpResult)) {
|
|
182
|
+
result = effect.value;
|
|
183
|
+
if (!result) {
|
|
184
|
+
pos = -1;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
if (pos === -1) {
|
|
189
|
+
result = null;
|
|
190
|
+
}
|
|
191
|
+
pos = pos === -1 ? -1 : tr.changes.mapPos(pos);
|
|
192
|
+
if (state.pos === pos && state.result === result) {
|
|
193
|
+
return state;
|
|
194
|
+
}
|
|
195
|
+
return new SignatureHelpState(pos, result);
|
|
196
|
+
},
|
|
197
|
+
provide: (f) => showTooltip.compute([f], (state) => {
|
|
198
|
+
const val = state.field(signatureHelpTooltipField);
|
|
199
|
+
const { result, pos } = val;
|
|
200
|
+
if (result) {
|
|
201
|
+
return {
|
|
202
|
+
pos,
|
|
203
|
+
above: true,
|
|
204
|
+
create: () => {
|
|
205
|
+
const dom = document.createElement("div");
|
|
206
|
+
dom.className = "cm-signature-tooltip";
|
|
207
|
+
dom.style.cssText = "font-size: 12px;max-width: 320px;";
|
|
208
|
+
const div = document.createElement("div");
|
|
209
|
+
div.innerHTML = result;
|
|
210
|
+
dom.appendChild(div);
|
|
211
|
+
return { dom };
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
return null;
|
|
216
|
+
})
|
|
217
|
+
});
|
|
218
|
+
async function renderSignatureHelp(state, help) {
|
|
219
|
+
const {
|
|
220
|
+
signatures,
|
|
221
|
+
activeSignature: activeSignatureIndex,
|
|
222
|
+
activeParameter: activeParameterIndex
|
|
223
|
+
} = help;
|
|
224
|
+
if (typeof activeSignatureIndex !== "number" || typeof activeParameterIndex !== "number") {
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
const activeSignature = signatures[activeSignatureIndex];
|
|
228
|
+
if (!activeSignature || !Array.isArray(activeSignature.parameters)) {
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
const { label } = activeSignature;
|
|
232
|
+
const keyword = getParameterLabel(
|
|
233
|
+
activeSignature.label,
|
|
234
|
+
activeSignature.parameters[activeParameterIndex]
|
|
235
|
+
);
|
|
236
|
+
const documentation = MarkupContent.is(activeSignature.documentation) ? activeSignature.documentation.value : activeSignature.documentation ?? "";
|
|
237
|
+
const rendered = await renderMarkdown(highlightByKeyword(label, keyword)) + await renderMarkdown(documentation.trim().split("\n")[0]);
|
|
238
|
+
return rendered;
|
|
239
|
+
}
|
|
240
|
+
function getParameterLabel(fullText, parameter) {
|
|
241
|
+
let keyword = (parameter == null ? void 0 : parameter.label) ?? "";
|
|
242
|
+
if (Array.isArray(keyword)) {
|
|
243
|
+
const [from, to] = keyword;
|
|
244
|
+
keyword = fullText.slice(from, to);
|
|
245
|
+
}
|
|
246
|
+
return keyword;
|
|
247
|
+
}
|
|
248
|
+
function highlightByKeyword(content, keyword) {
|
|
249
|
+
if (!keyword) {
|
|
250
|
+
return content;
|
|
251
|
+
}
|
|
252
|
+
return content.split(keyword).join(`<span class="cm-signature-parameter-active">${keyword}</span>`);
|
|
253
|
+
}
|
|
254
|
+
var closeSignatureHelp = (view2) => {
|
|
255
|
+
if (view2.state.field(signatureHelpTooltipField).pos !== -1) {
|
|
256
|
+
view2.dispatch({
|
|
257
|
+
effects: setSignatureHelpRequestPosition.of(-1)
|
|
258
|
+
});
|
|
259
|
+
return true;
|
|
260
|
+
}
|
|
261
|
+
return false;
|
|
262
|
+
};
|
|
263
|
+
var signatureHelpKeymap = [
|
|
264
|
+
{ key: "Escape", run: closeSignatureHelp }
|
|
265
|
+
];
|
|
266
|
+
var SignatureHelpView = class {
|
|
267
|
+
constructor(view2) {
|
|
268
|
+
this.view = view2;
|
|
269
|
+
}
|
|
270
|
+
update(update) {
|
|
271
|
+
if ((update.docChanged || update.selectionSet) && this.view.state.field(signatureHelpTooltipField).pos !== -1) {
|
|
272
|
+
triggerSignatureHelpRequest(this.view, update.state);
|
|
273
|
+
} else if (update.docChanged) {
|
|
274
|
+
const last = update.transactions[update.transactions.length - 1];
|
|
275
|
+
if (last.isUserEvent("input")) {
|
|
276
|
+
update.changes.iterChanges((_fromA, _toA, _fromB, _toB, inserted) => {
|
|
277
|
+
if (inserted.sliceString(0).trim().endsWith("()") || inserted.toString() === ",") {
|
|
278
|
+
triggerSignatureHelpRequest(this.view, update.state);
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
var doSignatureHelpFacet = Facet.define({
|
|
286
|
+
combine(values) {
|
|
287
|
+
return values[values.length - 1];
|
|
288
|
+
}
|
|
289
|
+
});
|
|
290
|
+
var triggerSignatureHelpRequest = async (view2, state) => {
|
|
291
|
+
const doSignatureHelp = state.facet(doSignatureHelpFacet);
|
|
292
|
+
const pos = state.selection.main.from;
|
|
293
|
+
try {
|
|
294
|
+
queueMicrotask(() => {
|
|
295
|
+
view2.dispatch({
|
|
296
|
+
effects: [setSignatureHelpRequestPosition.of(pos)]
|
|
297
|
+
});
|
|
298
|
+
});
|
|
299
|
+
const info = await doSignatureHelp(state, pos);
|
|
300
|
+
if (!info || !info.signatures || info.signatures.length === 0) {
|
|
301
|
+
queueMicrotask(() => {
|
|
302
|
+
view2.dispatch({
|
|
303
|
+
effects: [setSignatureHelpResult.of(null)]
|
|
304
|
+
});
|
|
305
|
+
});
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
const result = await renderSignatureHelp(state, info) ?? "";
|
|
309
|
+
queueMicrotask(() => {
|
|
310
|
+
view2.dispatch({
|
|
311
|
+
effects: [setSignatureHelpResult.of(result)]
|
|
312
|
+
});
|
|
313
|
+
});
|
|
314
|
+
} catch (e) {
|
|
315
|
+
queueMicrotask(() => {
|
|
316
|
+
view2.dispatch({
|
|
317
|
+
effects: [setSignatureHelpResult.of(null)]
|
|
318
|
+
});
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
};
|
|
322
|
+
var signatureHelpToolTipBaseTheme = EditorView.baseTheme({
|
|
323
|
+
".cm-tooltip.cm-signature-tooltip": {
|
|
324
|
+
padding: "3px 9px",
|
|
325
|
+
width: "max-content",
|
|
326
|
+
maxWidth: "500px"
|
|
327
|
+
},
|
|
328
|
+
".cm-tooltip .cm-signature-parameter-active": {
|
|
329
|
+
fontWeight: "bold"
|
|
330
|
+
}
|
|
331
|
+
});
|
|
332
|
+
function signatureHelp(doSignatureHelp) {
|
|
333
|
+
return [
|
|
334
|
+
doSignatureHelpFacet.of(doSignatureHelp),
|
|
335
|
+
ViewPlugin.fromClass(SignatureHelpView),
|
|
336
|
+
signatureHelpTooltipField,
|
|
337
|
+
signatureHelpToolTipBaseTheme,
|
|
338
|
+
keymap.of(signatureHelpKeymap),
|
|
339
|
+
EditorView.domEventHandlers({
|
|
340
|
+
blur(event, view2) {
|
|
341
|
+
if (!(event.relatedTarget instanceof Element) || !event.relatedTarget.closest(".cm-signature-tooltip")) {
|
|
342
|
+
queueMicrotask(() => {
|
|
343
|
+
view2.dispatch({
|
|
344
|
+
effects: setSignatureHelpRequestPosition.of(-1)
|
|
345
|
+
});
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
})
|
|
350
|
+
];
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
// src/goto-definition.ts
|
|
354
|
+
import { FacetCombineStrategy } from "@coze-editor/utils";
|
|
355
|
+
import { ViewPlugin as ViewPlugin2 } from "@codemirror/view";
|
|
356
|
+
import { Facet as Facet2 } from "@codemirror/state";
|
|
357
|
+
var handlerFacet = Facet2.define({
|
|
358
|
+
combine: FacetCombineStrategy.Last
|
|
359
|
+
});
|
|
360
|
+
var view = ViewPlugin2.fromClass(
|
|
361
|
+
class {
|
|
362
|
+
dispose;
|
|
363
|
+
constructor(view2) {
|
|
364
|
+
function trigger(e) {
|
|
365
|
+
const target = e.target;
|
|
366
|
+
if (!e.metaKey || !target.closest(".cm-content")) {
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
const pos = view2.posAtCoords({
|
|
370
|
+
x: e.clientX,
|
|
371
|
+
y: e.clientY
|
|
372
|
+
});
|
|
373
|
+
if (typeof pos !== "number") {
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
const handler = view2.state.facet(handlerFacet);
|
|
377
|
+
handler({
|
|
378
|
+
view: view2,
|
|
379
|
+
pos
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
document.addEventListener("click", trigger, false);
|
|
383
|
+
this.dispose = () => {
|
|
384
|
+
document.removeEventListener("click", trigger, false);
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
destroy() {
|
|
388
|
+
if (typeof this.dispose === "function") {
|
|
389
|
+
this.dispose();
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
);
|
|
394
|
+
function gotoDefinition(handler) {
|
|
395
|
+
return [handlerFacet.of(handler), view];
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
// src/language-registry.ts
|
|
399
|
+
function formatContents(contents) {
|
|
400
|
+
if (MarkupContent2.is(contents)) {
|
|
401
|
+
const { value } = contents;
|
|
402
|
+
if (contents.kind === "markdown") {
|
|
403
|
+
}
|
|
404
|
+
return value;
|
|
405
|
+
} else if (Array.isArray(contents)) {
|
|
406
|
+
return contents.map((c) => `${formatContents(c)}
|
|
407
|
+
|
|
408
|
+
`).join("");
|
|
409
|
+
} else if (typeof contents === "string") {
|
|
410
|
+
return contents;
|
|
411
|
+
}
|
|
412
|
+
return "";
|
|
413
|
+
}
|
|
414
|
+
var identRe = /^[\w$]+$/;
|
|
415
|
+
var LanguagesRegistry = class {
|
|
416
|
+
languages = {};
|
|
417
|
+
register(id, options) {
|
|
418
|
+
if (!this.languages[id]) {
|
|
419
|
+
this.languages[id] = options;
|
|
420
|
+
}
|
|
421
|
+
return () => {
|
|
422
|
+
delete this.languages[id];
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
get(languageId) {
|
|
426
|
+
return this.languages[languageId];
|
|
427
|
+
}
|
|
428
|
+
getExtension(id) {
|
|
429
|
+
var _a;
|
|
430
|
+
if (!this.languages[id]) {
|
|
431
|
+
return [];
|
|
432
|
+
}
|
|
433
|
+
const { languageService, language, extensions } = this.languages[id];
|
|
434
|
+
const langaugeExtensions = [];
|
|
435
|
+
langaugeExtensions.push(new LanguageSupport(language));
|
|
436
|
+
if (id === "typescript" || id === "python" || id === "sql") {
|
|
437
|
+
langaugeExtensions.push(
|
|
438
|
+
shiki({
|
|
439
|
+
highlighter: highlighterPromise,
|
|
440
|
+
language: id,
|
|
441
|
+
theme: DEFAULT_SYNTAX_THEME
|
|
442
|
+
})
|
|
443
|
+
);
|
|
444
|
+
}
|
|
445
|
+
langaugeExtensions.push(
|
|
446
|
+
StateField2.define({
|
|
447
|
+
create(state) {
|
|
448
|
+
if (languageService == null ? void 0 : languageService.onTextDocumentDidChange) {
|
|
449
|
+
const { textDocument } = state.field(textDocumentField);
|
|
450
|
+
languageService.onTextDocumentDidChange({
|
|
451
|
+
textDocument
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
},
|
|
455
|
+
update(_value, tr) {
|
|
456
|
+
if (tr.docChanged) {
|
|
457
|
+
if (languageService == null ? void 0 : languageService.onTextDocumentDidChange) {
|
|
458
|
+
const { textDocument } = tr.state.field(textDocumentField);
|
|
459
|
+
languageService.onTextDocumentDidChange({
|
|
460
|
+
textDocument
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
})
|
|
466
|
+
);
|
|
467
|
+
if (languageService && languageService.doValidation) {
|
|
468
|
+
langaugeExtensions.push(
|
|
469
|
+
ViewPlugin3.fromClass(
|
|
470
|
+
class {
|
|
471
|
+
toDispose;
|
|
472
|
+
constructor(view2) {
|
|
473
|
+
var _a2;
|
|
474
|
+
function onRefreshDiagnostics() {
|
|
475
|
+
view2.dispatch({
|
|
476
|
+
userEvent: LINT_REFRESH_USER_EVENT
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
(_a2 = languageService.events) == null ? void 0 : _a2.on(
|
|
480
|
+
"refresh-diagnostics",
|
|
481
|
+
onRefreshDiagnostics
|
|
482
|
+
);
|
|
483
|
+
this.toDispose = () => {
|
|
484
|
+
var _a3;
|
|
485
|
+
(_a3 = languageService.events) == null ? void 0 : _a3.off(
|
|
486
|
+
"refresh-diagnostics",
|
|
487
|
+
onRefreshDiagnostics
|
|
488
|
+
);
|
|
489
|
+
};
|
|
490
|
+
}
|
|
491
|
+
destroy() {
|
|
492
|
+
if (typeof this.toDispose === "function") {
|
|
493
|
+
this.toDispose();
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
),
|
|
498
|
+
EditorView2.theme({
|
|
499
|
+
".cm-tooltip-lint": {
|
|
500
|
+
maxWidth: "360px"
|
|
501
|
+
},
|
|
502
|
+
".cm-lint-tag-unnecessary": {
|
|
503
|
+
opacity: "0.5"
|
|
504
|
+
},
|
|
505
|
+
".cm-lint-tag-deprecated": {
|
|
506
|
+
textDecoration: "line-through"
|
|
507
|
+
},
|
|
508
|
+
".cm-lintRange-hint.cm-lint-tag-deprecated": {
|
|
509
|
+
backgroundImage: "unset"
|
|
510
|
+
},
|
|
511
|
+
".cm-lintRange-hint.cm-lint-tag-unnecessary": {
|
|
512
|
+
backgroundImage: "unset"
|
|
513
|
+
}
|
|
514
|
+
})
|
|
515
|
+
);
|
|
516
|
+
langaugeExtensions.push(
|
|
517
|
+
linter(
|
|
518
|
+
async (view2) => {
|
|
519
|
+
var _a2;
|
|
520
|
+
const { textDocument, originalRangeFor } = view2.state.field(textDocumentField);
|
|
521
|
+
const diagnostics = await languageService.doValidation({
|
|
522
|
+
textDocument
|
|
523
|
+
});
|
|
524
|
+
const finalDiagnostics = diagnostics.map((diagnostic) => {
|
|
525
|
+
var _a3, _b;
|
|
526
|
+
const range = originalRangeFor({
|
|
527
|
+
from: diagnostic.from,
|
|
528
|
+
to: diagnostic.to
|
|
529
|
+
});
|
|
530
|
+
if (range) {
|
|
531
|
+
let markClass = "";
|
|
532
|
+
if ((_a3 = diagnostic.tags) == null ? void 0 : _a3.includes(MarkerTag.Unnecessary)) {
|
|
533
|
+
markClass += "cm-lint-tag-unnecessary";
|
|
534
|
+
}
|
|
535
|
+
if ((_b = diagnostic.tags) == null ? void 0 : _b.includes(MarkerTag.Deprecated)) {
|
|
536
|
+
markClass += "cm-lint-tag-deprecated";
|
|
537
|
+
}
|
|
538
|
+
return {
|
|
539
|
+
...diagnostic,
|
|
540
|
+
markClass,
|
|
541
|
+
...range
|
|
542
|
+
};
|
|
543
|
+
}
|
|
544
|
+
}).filter((v) => isDiagnostic(v));
|
|
545
|
+
(_a2 = languageService.events) == null ? void 0 : _a2.emit("diagnostics", {
|
|
546
|
+
uri: textDocument.uri,
|
|
547
|
+
diagnostics: finalDiagnostics.map((d) => ({
|
|
548
|
+
from: d.from,
|
|
549
|
+
to: d.to,
|
|
550
|
+
message: d.message,
|
|
551
|
+
severity: d.severity
|
|
552
|
+
}))
|
|
553
|
+
});
|
|
554
|
+
return finalDiagnostics;
|
|
555
|
+
},
|
|
556
|
+
{
|
|
557
|
+
delay: ((_a = languageService.options) == null ? void 0 : _a.lintDelay) ?? 100,
|
|
558
|
+
needsRefresh(update) {
|
|
559
|
+
return update.transactions.some(
|
|
560
|
+
(tr) => tr.isUserEvent(LINT_REFRESH_USER_EVENT)
|
|
561
|
+
);
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
)
|
|
565
|
+
);
|
|
566
|
+
}
|
|
567
|
+
if (languageService == null ? void 0 : languageService.doHover) {
|
|
568
|
+
langaugeExtensions.push(
|
|
569
|
+
hoverTooltip(async (view2, pos) => {
|
|
570
|
+
const { textDocument, generatedOffsetFor } = view2.state.field(textDocumentField);
|
|
571
|
+
const offset = generatedOffsetFor(pos);
|
|
572
|
+
if (typeof offset !== "number") {
|
|
573
|
+
return null;
|
|
574
|
+
}
|
|
575
|
+
const result = await languageService.doHover({
|
|
576
|
+
textDocument,
|
|
577
|
+
offset
|
|
578
|
+
});
|
|
579
|
+
if (!result) {
|
|
580
|
+
return null;
|
|
581
|
+
}
|
|
582
|
+
const html = await renderMarkdown(formatContents(result));
|
|
583
|
+
const word = view2.state.wordAt(offset);
|
|
584
|
+
return {
|
|
585
|
+
pos: (word == null ? void 0 : word.from) ?? offset,
|
|
586
|
+
end: (word == null ? void 0 : word.to) ?? offset,
|
|
587
|
+
create() {
|
|
588
|
+
const dom = document.createElement("div");
|
|
589
|
+
dom.classList.add("cm-code-hover");
|
|
590
|
+
dom.innerHTML = html;
|
|
591
|
+
dom.style.cssText = "padding: 5px 10px;max-width: 360px;";
|
|
592
|
+
return {
|
|
593
|
+
dom
|
|
594
|
+
};
|
|
595
|
+
}
|
|
596
|
+
};
|
|
597
|
+
}),
|
|
598
|
+
EditorView2.theme({
|
|
599
|
+
".cm-code-hover a": {
|
|
600
|
+
color: "#3b98ff"
|
|
601
|
+
},
|
|
602
|
+
".cm-code-hover pre": {
|
|
603
|
+
margin: "0"
|
|
604
|
+
}
|
|
605
|
+
})
|
|
606
|
+
);
|
|
607
|
+
}
|
|
608
|
+
if (languageService == null ? void 0 : languageService.doSignatureHelp) {
|
|
609
|
+
langaugeExtensions.push(
|
|
610
|
+
signatureHelp(async (state, pos) => {
|
|
611
|
+
const { textDocument, generatedRangeFor } = state.field(textDocumentField);
|
|
612
|
+
const range = generatedRangeFor({ from: pos, to: pos });
|
|
613
|
+
const offset = range == null ? void 0 : range.from;
|
|
614
|
+
if (typeof offset !== "number") {
|
|
615
|
+
return null;
|
|
616
|
+
}
|
|
617
|
+
const result = await languageService.doSignatureHelp({
|
|
618
|
+
textDocument,
|
|
619
|
+
offset
|
|
620
|
+
});
|
|
621
|
+
return result;
|
|
622
|
+
})
|
|
623
|
+
);
|
|
624
|
+
}
|
|
625
|
+
if (languageService == null ? void 0 : languageService.doComplete) {
|
|
626
|
+
langaugeExtensions.push(
|
|
627
|
+
EditorView2.theme({
|
|
628
|
+
".cm-completionInfo p": {
|
|
629
|
+
margin: 0
|
|
630
|
+
},
|
|
631
|
+
".cm-completionMatchedText": {
|
|
632
|
+
textDecoration: "none",
|
|
633
|
+
color: "#4daafc"
|
|
634
|
+
}
|
|
635
|
+
}),
|
|
636
|
+
autocompletion({
|
|
637
|
+
override: [
|
|
638
|
+
async function({ state, pos, view: view2 }) {
|
|
639
|
+
var _a2;
|
|
640
|
+
const { textDocument, originalRangeFor, generatedRangeFor } = state.field(textDocumentField);
|
|
641
|
+
const range = generatedRangeFor({ from: pos, to: pos });
|
|
642
|
+
const offset = range == null ? void 0 : range.from;
|
|
643
|
+
if (typeof offset !== "number") {
|
|
644
|
+
return null;
|
|
645
|
+
}
|
|
646
|
+
const completionResult = await languageService.doComplete({
|
|
647
|
+
textDocument,
|
|
648
|
+
offset
|
|
649
|
+
});
|
|
650
|
+
if (!completionResult || !Array.isArray(completionResult.items) || completionResult.items.length === 0) {
|
|
651
|
+
return null;
|
|
652
|
+
}
|
|
653
|
+
let { items } = completionResult;
|
|
654
|
+
const content = state.doc.toString();
|
|
655
|
+
const charBefore = content.slice(pos - 1, pos);
|
|
656
|
+
const triggerCharacters = languageService.triggerCharacters ?? [];
|
|
657
|
+
if (!triggerCharacters.includes(charBefore)) {
|
|
658
|
+
let i = pos - 1;
|
|
659
|
+
let query = "";
|
|
660
|
+
while (i >= 0) {
|
|
661
|
+
const char = content.slice(i, i + 1);
|
|
662
|
+
if (char === "\n") {
|
|
663
|
+
break;
|
|
664
|
+
}
|
|
665
|
+
if (!identRe.test(char) && i + 1 <= pos) {
|
|
666
|
+
break;
|
|
667
|
+
}
|
|
668
|
+
i--;
|
|
669
|
+
}
|
|
670
|
+
query = content.slice(i + 1, pos);
|
|
671
|
+
if (query) {
|
|
672
|
+
const fuzzySearch = createFuzzySearch(items, {
|
|
673
|
+
key: "label"
|
|
674
|
+
});
|
|
675
|
+
items = fuzzySearch(query).map((v) => ({
|
|
676
|
+
...v.item,
|
|
677
|
+
textEdit: {
|
|
678
|
+
range: {
|
|
679
|
+
start: textDocument.positionAt(i + 1),
|
|
680
|
+
end: textDocument.positionAt(pos)
|
|
681
|
+
},
|
|
682
|
+
newText: v.item.label
|
|
683
|
+
},
|
|
684
|
+
data: {
|
|
685
|
+
matches: v.matches.reduce((memo, current) => {
|
|
686
|
+
if (!current) {
|
|
687
|
+
return memo;
|
|
688
|
+
}
|
|
689
|
+
return [
|
|
690
|
+
...memo,
|
|
691
|
+
...current.reduce(
|
|
692
|
+
(m, c) => [...m, c[0], c[1] + 1],
|
|
693
|
+
[]
|
|
694
|
+
)
|
|
695
|
+
];
|
|
696
|
+
}, [])
|
|
697
|
+
}
|
|
698
|
+
}));
|
|
699
|
+
} else if (Array.isArray(languageService.triggerCharacters)) {
|
|
700
|
+
items = [];
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
const completionOptions = [];
|
|
704
|
+
const mapping = /* @__PURE__ */ new WeakMap();
|
|
705
|
+
let resolveCompletion = void 0;
|
|
706
|
+
if (typeof languageService.resolveCompletionItem === "function") {
|
|
707
|
+
resolveCompletion = createResolveCompletion(
|
|
708
|
+
view2,
|
|
709
|
+
languageService,
|
|
710
|
+
mapping
|
|
711
|
+
);
|
|
712
|
+
}
|
|
713
|
+
const matchesMapping = /* @__PURE__ */ new WeakMap();
|
|
714
|
+
for (const item of items) {
|
|
715
|
+
const { kind, label, textEdit, textEditText } = item;
|
|
716
|
+
const completion = {
|
|
717
|
+
label,
|
|
718
|
+
type: defaultFromCompletionItemKind(kind),
|
|
719
|
+
detail: item.detail ?? ""
|
|
720
|
+
};
|
|
721
|
+
mapping.set(completion, item);
|
|
722
|
+
matchesMapping.set(completion, (_a2 = item.data) == null ? void 0 : _a2.matches);
|
|
723
|
+
if (textEdit) {
|
|
724
|
+
const range2 = "range" in textEdit ? textEdit.range : textEdit.replace;
|
|
725
|
+
const from = textDocument.offsetAt(range2.start);
|
|
726
|
+
const to = textDocument.offsetAt(range2.end);
|
|
727
|
+
const oRange = originalRangeFor({
|
|
728
|
+
from,
|
|
729
|
+
to
|
|
730
|
+
});
|
|
731
|
+
if (!oRange) {
|
|
732
|
+
continue;
|
|
733
|
+
}
|
|
734
|
+
const insert = textEdit.newText;
|
|
735
|
+
const { insertTextFormat } = item;
|
|
736
|
+
completion.apply = (view3) => {
|
|
737
|
+
if (insertTextFormat === 2) {
|
|
738
|
+
snippet(
|
|
739
|
+
addAnchor(
|
|
740
|
+
insert.replace(/\$(\d+)/g, "$${$1}").replace(/\\\$/g, "$")
|
|
741
|
+
)
|
|
742
|
+
)(view3, completion, oRange.from, oRange.to);
|
|
743
|
+
} else {
|
|
744
|
+
view3.dispatch(
|
|
745
|
+
insertCompletionText(
|
|
746
|
+
view3.state,
|
|
747
|
+
insert,
|
|
748
|
+
oRange.from,
|
|
749
|
+
oRange.to
|
|
750
|
+
)
|
|
751
|
+
);
|
|
752
|
+
}
|
|
753
|
+
};
|
|
754
|
+
} else if (textEditText) {
|
|
755
|
+
completion.apply = textEditText;
|
|
756
|
+
}
|
|
757
|
+
completion.info = resolveCompletion;
|
|
758
|
+
completionOptions.push(completion);
|
|
759
|
+
}
|
|
760
|
+
return {
|
|
761
|
+
from: pos,
|
|
762
|
+
options: completionOptions,
|
|
763
|
+
filter: false,
|
|
764
|
+
getMatch(completion) {
|
|
765
|
+
return matchesMapping.get(completion) ?? [];
|
|
766
|
+
}
|
|
767
|
+
};
|
|
768
|
+
}
|
|
769
|
+
]
|
|
770
|
+
})
|
|
771
|
+
);
|
|
772
|
+
}
|
|
773
|
+
if (languageService == null ? void 0 : languageService.findDefinition) {
|
|
774
|
+
langaugeExtensions.push(
|
|
775
|
+
gotoDefinition(async ({ pos, view: view2 }) => {
|
|
776
|
+
const { textDocument, originalRangeFor, generatedRangeFor } = view2.state.field(textDocumentField);
|
|
777
|
+
const range = generatedRangeFor({ from: pos, to: pos });
|
|
778
|
+
const offset = range == null ? void 0 : range.from;
|
|
779
|
+
if (typeof offset !== "number") {
|
|
780
|
+
return null;
|
|
781
|
+
}
|
|
782
|
+
const definitions = await languageService.findDefinition({
|
|
783
|
+
textDocument,
|
|
784
|
+
offset
|
|
785
|
+
});
|
|
786
|
+
if (!Array.isArray(definitions) || definitions.length === 0) {
|
|
787
|
+
return;
|
|
788
|
+
}
|
|
789
|
+
const definition = definitions[0];
|
|
790
|
+
const oRange = originalRangeFor({
|
|
791
|
+
from: definition.from,
|
|
792
|
+
to: definition.to
|
|
793
|
+
});
|
|
794
|
+
if (!oRange) {
|
|
795
|
+
return;
|
|
796
|
+
}
|
|
797
|
+
view2.dispatch({
|
|
798
|
+
effects: EditorView2.scrollIntoView(oRange.from, {
|
|
799
|
+
y: "center"
|
|
800
|
+
}),
|
|
801
|
+
selection: EditorSelection.range(oRange.from, oRange.to)
|
|
802
|
+
});
|
|
803
|
+
})
|
|
804
|
+
);
|
|
805
|
+
}
|
|
806
|
+
if (languageService == null ? void 0 : languageService.findLinks) {
|
|
807
|
+
langaugeExtensions.push(
|
|
808
|
+
links(async (view2) => {
|
|
809
|
+
const { textDocument, originalRangeFor } = view2.state.field(textDocumentField);
|
|
810
|
+
const links2 = await languageService.findLinks({
|
|
811
|
+
textDocument
|
|
812
|
+
});
|
|
813
|
+
return links2.map((link) => {
|
|
814
|
+
const range = originalRangeFor(link.range);
|
|
815
|
+
if (!range) {
|
|
816
|
+
return;
|
|
817
|
+
}
|
|
818
|
+
return {
|
|
819
|
+
range,
|
|
820
|
+
target: link.target
|
|
821
|
+
};
|
|
822
|
+
}).filter((v) => isLink(v));
|
|
823
|
+
})
|
|
824
|
+
);
|
|
825
|
+
}
|
|
826
|
+
if (extensions) {
|
|
827
|
+
langaugeExtensions.push(extensions);
|
|
828
|
+
}
|
|
829
|
+
return langaugeExtensions;
|
|
830
|
+
}
|
|
831
|
+
};
|
|
832
|
+
function createResolveCompletion(view2, languageService, mapping) {
|
|
833
|
+
const dom = document.createElement("div");
|
|
834
|
+
let controller = new AbortController();
|
|
835
|
+
function hideDOM(controller2) {
|
|
836
|
+
if (!controller2.signal.aborted) {
|
|
837
|
+
dom.style.display = "none";
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
function showDOM(html, controller2) {
|
|
841
|
+
if (!controller2.signal.aborted) {
|
|
842
|
+
dom.innerHTML = html;
|
|
843
|
+
dom.style.display = "block";
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
return (completion) => {
|
|
847
|
+
controller.abort();
|
|
848
|
+
controller = new AbortController();
|
|
849
|
+
const closureController = controller;
|
|
850
|
+
(async () => {
|
|
851
|
+
const completionItem = mapping.get(completion);
|
|
852
|
+
if (!view2 || !completionItem || typeof languageService.resolveCompletionItem !== "function") {
|
|
853
|
+
hideDOM(closureController);
|
|
854
|
+
return;
|
|
855
|
+
}
|
|
856
|
+
const { textDocument, originalRangeFor } = view2.state.field(textDocumentField);
|
|
857
|
+
const oRange = originalRangeFor({
|
|
858
|
+
from: view2.state.selection.main.from,
|
|
859
|
+
to: view2.state.selection.main.from
|
|
860
|
+
});
|
|
861
|
+
if (!oRange) {
|
|
862
|
+
hideDOM(closureController);
|
|
863
|
+
return;
|
|
864
|
+
}
|
|
865
|
+
const details = await languageService.resolveCompletionItem(
|
|
866
|
+
{
|
|
867
|
+
textDocument,
|
|
868
|
+
offset: oRange.from
|
|
869
|
+
},
|
|
870
|
+
completionItem
|
|
871
|
+
);
|
|
872
|
+
if (!details.detail && !details.documentation) {
|
|
873
|
+
hideDOM(closureController);
|
|
874
|
+
return;
|
|
875
|
+
}
|
|
876
|
+
const documentationString = MarkupContent2.is(details.documentation) ? await renderMarkdown(details.documentation.value) : details.documentation ?? "";
|
|
877
|
+
const html = [
|
|
878
|
+
`<div style="opacity: 0.8;white-space: pre-wrap;">${details.detail ?? ""}</div>`,
|
|
879
|
+
details.documentation ? "<br />" : "",
|
|
880
|
+
`<div>${documentationString}</div>`
|
|
881
|
+
].join("");
|
|
882
|
+
if (!closureController.signal.aborted) {
|
|
883
|
+
showDOM(html, closureController);
|
|
884
|
+
}
|
|
885
|
+
})();
|
|
886
|
+
return dom;
|
|
887
|
+
};
|
|
888
|
+
}
|
|
889
|
+
function isDiagnostic(v) {
|
|
890
|
+
return Boolean(v);
|
|
891
|
+
}
|
|
892
|
+
function isLink(v) {
|
|
893
|
+
return Boolean(v);
|
|
894
|
+
}
|
|
895
|
+
function addAnchor(str) {
|
|
896
|
+
if (!str.includes("${")) {
|
|
897
|
+
return `${str}\${0}`;
|
|
898
|
+
}
|
|
899
|
+
return str;
|
|
900
|
+
}
|
|
901
|
+
function defaultFromCompletionItemKind(kind) {
|
|
902
|
+
switch (kind) {
|
|
903
|
+
case 1:
|
|
904
|
+
return "text";
|
|
905
|
+
case 15:
|
|
906
|
+
return "snippet";
|
|
907
|
+
case 2:
|
|
908
|
+
return "method";
|
|
909
|
+
case 3:
|
|
910
|
+
return "function";
|
|
911
|
+
case 4:
|
|
912
|
+
return "constructor";
|
|
913
|
+
case 7:
|
|
914
|
+
return "class";
|
|
915
|
+
case 5:
|
|
916
|
+
return "field";
|
|
917
|
+
case 10:
|
|
918
|
+
return "property";
|
|
919
|
+
case 6:
|
|
920
|
+
return "variable";
|
|
921
|
+
case 18:
|
|
922
|
+
return "reference";
|
|
923
|
+
case 23:
|
|
924
|
+
return "event";
|
|
925
|
+
case 8:
|
|
926
|
+
return "interface";
|
|
927
|
+
case 22:
|
|
928
|
+
return "struct";
|
|
929
|
+
case 25:
|
|
930
|
+
return "typeParameter";
|
|
931
|
+
case 9:
|
|
932
|
+
return "module";
|
|
933
|
+
case 12:
|
|
934
|
+
return "value";
|
|
935
|
+
case 13:
|
|
936
|
+
case 20:
|
|
937
|
+
return "enum";
|
|
938
|
+
case 11:
|
|
939
|
+
return "unit";
|
|
940
|
+
case 14:
|
|
941
|
+
return "keyword";
|
|
942
|
+
case 24:
|
|
943
|
+
return "operator";
|
|
944
|
+
case 16:
|
|
945
|
+
return "color";
|
|
946
|
+
case 21:
|
|
947
|
+
return "constant";
|
|
948
|
+
default:
|
|
949
|
+
return "value";
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
var languages = new LanguagesRegistry();
|
|
953
|
+
|
|
954
|
+
// src/extension/tab-size/index.ts
|
|
955
|
+
import { EditorState } from "@codemirror/state";
|
|
956
|
+
import { indentUnit } from "@codemirror/language";
|
|
957
|
+
var tabSize = (size = 2) => [
|
|
958
|
+
EditorState.tabSize.of(size),
|
|
959
|
+
indentUnit.of(" ".repeat(size))
|
|
960
|
+
];
|
|
961
|
+
|
|
962
|
+
// src/extension/basic-setup.ts
|
|
963
|
+
import {
|
|
964
|
+
crosshairCursor,
|
|
965
|
+
drawSelection,
|
|
966
|
+
dropCursor,
|
|
967
|
+
highlightActiveLine,
|
|
968
|
+
highlightActiveLineGutter,
|
|
969
|
+
highlightSpecialChars,
|
|
970
|
+
keymap as keymap2,
|
|
971
|
+
rectangularSelection
|
|
972
|
+
} from "@codemirror/view";
|
|
973
|
+
import { EditorState as EditorState2 } from "@codemirror/state";
|
|
974
|
+
import {
|
|
975
|
+
defaultHighlightStyle,
|
|
976
|
+
foldKeymap,
|
|
977
|
+
indentOnInput,
|
|
978
|
+
syntaxHighlighting as syntaxHighlighting2
|
|
979
|
+
} from "@codemirror/language";
|
|
980
|
+
import {
|
|
981
|
+
defaultKeymap,
|
|
982
|
+
history,
|
|
983
|
+
historyKeymap,
|
|
984
|
+
indentWithTab
|
|
985
|
+
} from "@codemirror/commands";
|
|
986
|
+
import {
|
|
987
|
+
acceptCompletion,
|
|
988
|
+
autocompletion as autocompletion2,
|
|
989
|
+
closeBrackets,
|
|
990
|
+
closeBracketsKeymap,
|
|
991
|
+
completionKeymap
|
|
992
|
+
} from "@codemirror/autocomplete";
|
|
993
|
+
var basicSetup = (() => [
|
|
994
|
+
highlightActiveLineGutter(),
|
|
995
|
+
highlightSpecialChars(),
|
|
996
|
+
history(),
|
|
997
|
+
drawSelection(),
|
|
998
|
+
dropCursor(),
|
|
999
|
+
EditorState2.allowMultipleSelections.of(true),
|
|
1000
|
+
indentOnInput(),
|
|
1001
|
+
syntaxHighlighting2(defaultHighlightStyle, { fallback: true }),
|
|
1002
|
+
closeBrackets(),
|
|
1003
|
+
autocompletion2(),
|
|
1004
|
+
rectangularSelection(),
|
|
1005
|
+
crosshairCursor(),
|
|
1006
|
+
highlightActiveLine(),
|
|
1007
|
+
keymap2.of([
|
|
1008
|
+
...defaultKeymap,
|
|
1009
|
+
...closeBracketsKeymap,
|
|
1010
|
+
...historyKeymap,
|
|
1011
|
+
...foldKeymap,
|
|
1012
|
+
...completionKeymap,
|
|
1013
|
+
indentWithTab,
|
|
1014
|
+
{ key: "Tab", run: acceptCompletion }
|
|
1015
|
+
])
|
|
1016
|
+
])();
|
|
1017
|
+
|
|
1018
|
+
// src/create-theme.ts
|
|
1019
|
+
import { EditorView as EditorView3 } from "@codemirror/view";
|
|
1020
|
+
import {
|
|
1021
|
+
HighlightStyle as HighlightStyle2,
|
|
1022
|
+
syntaxHighlighting as syntaxHighlighting3
|
|
1023
|
+
} from "@codemirror/language";
|
|
1024
|
+
var createTheme = ({ variant, settings, styles }) => {
|
|
1025
|
+
const bracketTheme = (settings.bracketColors ?? []).reduce(
|
|
1026
|
+
(memo, color, index) => ({
|
|
1027
|
+
...memo,
|
|
1028
|
+
[`.colorization-bracket-${index}`]: { color },
|
|
1029
|
+
[`.colorization-bracket-${index} > span`]: { color }
|
|
1030
|
+
}),
|
|
1031
|
+
{}
|
|
1032
|
+
);
|
|
1033
|
+
const tooltipTheme = {
|
|
1034
|
+
".cm-tooltip": settings.tooltip ?? {},
|
|
1035
|
+
".cm-tooltip-autocomplete": settings.tooltipCompletion ?? {},
|
|
1036
|
+
".cm-tooltip a": settings.link ?? {
|
|
1037
|
+
color: "#4daafc"
|
|
1038
|
+
}
|
|
1039
|
+
};
|
|
1040
|
+
const completionTheme = {
|
|
1041
|
+
".cm-tooltip-autocomplete ul li[aria-selected]": settings.completionItemSelected ?? {},
|
|
1042
|
+
".cm-tooltip-autocomplete ul li:not([aria-selected]):hover": settings.completionItemHover ?? {},
|
|
1043
|
+
".cm-completionIcon": settings.completionItemIcon ?? {},
|
|
1044
|
+
".cm-completionLabel": settings.completionItemLabel ?? {},
|
|
1045
|
+
".cm-completionDetail": settings.completionItemDetail ?? {},
|
|
1046
|
+
".cm-completionInfo": settings.completionItemInfo ?? {}
|
|
1047
|
+
};
|
|
1048
|
+
const theme = EditorView3.theme(
|
|
1049
|
+
{
|
|
1050
|
+
"&": {
|
|
1051
|
+
backgroundColor: settings.background,
|
|
1052
|
+
color: settings.foreground
|
|
1053
|
+
},
|
|
1054
|
+
".cm-content": {
|
|
1055
|
+
caretColor: settings.caret
|
|
1056
|
+
},
|
|
1057
|
+
".cm-cursor, .cm-dropCursor": {
|
|
1058
|
+
borderLeftColor: settings.caret
|
|
1059
|
+
},
|
|
1060
|
+
"&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection": {
|
|
1061
|
+
backgroundColor: settings.selection
|
|
1062
|
+
},
|
|
1063
|
+
".cm-activeLine": {
|
|
1064
|
+
backgroundColor: settings.lineHighlight
|
|
1065
|
+
},
|
|
1066
|
+
".cm-gutters": {
|
|
1067
|
+
backgroundColor: settings.gutterBackground,
|
|
1068
|
+
color: settings.gutterForeground,
|
|
1069
|
+
borderRightColor: settings.gutterBorderColor,
|
|
1070
|
+
borderRightWidth: `${settings.gutterBorderWidth}px`
|
|
1071
|
+
},
|
|
1072
|
+
".cm-activeLineGutter": {
|
|
1073
|
+
backgroundColor: settings.lineHighlight
|
|
1074
|
+
},
|
|
1075
|
+
...bracketTheme,
|
|
1076
|
+
...tooltipTheme,
|
|
1077
|
+
...completionTheme
|
|
1078
|
+
},
|
|
1079
|
+
{
|
|
1080
|
+
dark: variant === "dark"
|
|
1081
|
+
}
|
|
1082
|
+
);
|
|
1083
|
+
const highlightStyle = HighlightStyle2.define(styles);
|
|
1084
|
+
const extension2 = [theme, syntaxHighlighting3(highlightStyle)];
|
|
1085
|
+
return extension2;
|
|
1086
|
+
};
|
|
1087
|
+
var create_theme_default = createTheme;
|
|
1088
|
+
|
|
1089
|
+
// src/index.ts
|
|
1090
|
+
import "@coze-editor/extension-scrollbar/dist/index.css";
|
|
1091
|
+
import "@coze-editor/extension-completion-icons/dist/index.css";
|
|
1092
|
+
|
|
1093
|
+
// src/transformer.ts
|
|
1094
|
+
import { Text } from "text-mapping";
|
|
1095
|
+
var transformerCreator = (processor) => (source) => {
|
|
1096
|
+
const text = processor(new Text(source));
|
|
1097
|
+
return {
|
|
1098
|
+
code: text.toString(),
|
|
1099
|
+
mapping: {
|
|
1100
|
+
originalRangeFor: text.originalRangeFor.bind(text),
|
|
1101
|
+
generatedRangeFor: text.generatedRangeFor.bind(text),
|
|
1102
|
+
originalOffsetFor: text.originalOffsetFor.bind(text),
|
|
1103
|
+
generatedOffsetFor: text.generatedOffsetFor.bind(text)
|
|
1104
|
+
}
|
|
1105
|
+
};
|
|
1106
|
+
};
|
|
1107
|
+
|
|
1108
|
+
// src/index.ts
|
|
1109
|
+
import { tags } from "@lezer/highlight";
|
|
1110
|
+
var SVG_FOLD_CLOSE = '<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 16 16"><path fill="currentColor" fill-rule="evenodd" d="M10.072 8.024L5.715 3.667l.618-.62L11 7.716v.618L6.333 13l-.618-.619z" clip-rule="evenodd"/></svg>';
|
|
1111
|
+
var SVG_FOLD_OPEN = '<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 16 16"><path fill="currentColor" fill-rule="evenodd" d="m7.976 10.072l4.357-4.357l.62.618L8.284 11h-.618L3 6.333l.619-.618z" clip-rule="evenodd"/></svg>';
|
|
1112
|
+
var preset = [
|
|
1113
|
+
...universal,
|
|
1114
|
+
extension([
|
|
1115
|
+
basicSetup,
|
|
1116
|
+
matchingBrackets,
|
|
1117
|
+
// indentGuides(),
|
|
1118
|
+
icons,
|
|
1119
|
+
textDocumentField2,
|
|
1120
|
+
Prec.low(
|
|
1121
|
+
EditorView4.theme({
|
|
1122
|
+
".cm-foldGutter .cm-gutterElement": {
|
|
1123
|
+
display: "flex",
|
|
1124
|
+
alignItems: "center",
|
|
1125
|
+
cursor: "pointer"
|
|
1126
|
+
}
|
|
1127
|
+
})
|
|
1128
|
+
),
|
|
1129
|
+
Prec.low(
|
|
1130
|
+
EditorView4.theme({
|
|
1131
|
+
".cm-link": {
|
|
1132
|
+
textDecoration: "underline"
|
|
1133
|
+
}
|
|
1134
|
+
})
|
|
1135
|
+
),
|
|
1136
|
+
Prec.low(
|
|
1137
|
+
EditorView4.theme({
|
|
1138
|
+
".cm-tooltip": {
|
|
1139
|
+
borderRadius: "5px",
|
|
1140
|
+
fontSize: "12px"
|
|
1141
|
+
},
|
|
1142
|
+
".cm-diagnostic-error": {
|
|
1143
|
+
borderLeft: "none"
|
|
1144
|
+
},
|
|
1145
|
+
".cm-diagnostic": {
|
|
1146
|
+
padding: "5px 10px"
|
|
1147
|
+
},
|
|
1148
|
+
".cm-lineNumbers": {
|
|
1149
|
+
userSelect: "none"
|
|
1150
|
+
},
|
|
1151
|
+
".cm-tooltip.cm-tooltip-autocomplete > ul": {
|
|
1152
|
+
width: "264px",
|
|
1153
|
+
padding: "4px"
|
|
1154
|
+
},
|
|
1155
|
+
".cm-completionInfo": {
|
|
1156
|
+
minWidth: "200px",
|
|
1157
|
+
margin: "0 2px"
|
|
1158
|
+
},
|
|
1159
|
+
".cm-tooltip.cm-completionInfo": {
|
|
1160
|
+
padding: "6px 9px"
|
|
1161
|
+
},
|
|
1162
|
+
".cm-completionInfo p:last-child": {
|
|
1163
|
+
display: "inline-block"
|
|
1164
|
+
},
|
|
1165
|
+
".cm-tooltip.cm-tooltip-autocomplete > ul > li[aria-selected]": {
|
|
1166
|
+
color: "inherit"
|
|
1167
|
+
},
|
|
1168
|
+
".cm-tooltip.cm-tooltip-autocomplete > ul > li": {
|
|
1169
|
+
padding: "1px 9px",
|
|
1170
|
+
height: "24px",
|
|
1171
|
+
display: "flex",
|
|
1172
|
+
alignItems: "center",
|
|
1173
|
+
borderRadius: "5px"
|
|
1174
|
+
},
|
|
1175
|
+
".cm-tooltip.cm-tooltip-autocomplete > ul > li:not(:first-child)": {
|
|
1176
|
+
marginTop: "2px"
|
|
1177
|
+
},
|
|
1178
|
+
".cm-completionIcon": {
|
|
1179
|
+
fontSize: "11px",
|
|
1180
|
+
opacity: "1",
|
|
1181
|
+
display: "flex"
|
|
1182
|
+
},
|
|
1183
|
+
".cm-completionLabel": {
|
|
1184
|
+
flex: 1,
|
|
1185
|
+
overflow: "hidden",
|
|
1186
|
+
textOverflow: "ellipsis"
|
|
1187
|
+
},
|
|
1188
|
+
".cm-completionDetail": {
|
|
1189
|
+
maxWidth: "86px",
|
|
1190
|
+
overflow: "hidden",
|
|
1191
|
+
textOverflow: "ellipsis",
|
|
1192
|
+
textAlign: "right",
|
|
1193
|
+
fontStyle: "initial"
|
|
1194
|
+
},
|
|
1195
|
+
".cm-tooltip-autocomplete": {
|
|
1196
|
+
borderRadius: "8px"
|
|
1197
|
+
},
|
|
1198
|
+
".cm-tooltip-hover": {
|
|
1199
|
+
overflowY: "auto",
|
|
1200
|
+
maxHeight: "360px",
|
|
1201
|
+
wordBreak: "break-word"
|
|
1202
|
+
},
|
|
1203
|
+
".cm-tooltip-hover p": {
|
|
1204
|
+
margin: 0
|
|
1205
|
+
},
|
|
1206
|
+
".cm-tooltip-section:not(:first-child)": {
|
|
1207
|
+
"border-top": "solid 0.5px #666666ab"
|
|
1208
|
+
}
|
|
1209
|
+
})
|
|
1210
|
+
)
|
|
1211
|
+
]),
|
|
1212
|
+
option("tabSize", tabSize),
|
|
1213
|
+
option("height", height),
|
|
1214
|
+
option("minHeight", minHeight),
|
|
1215
|
+
option("maxHeight", maxHeight),
|
|
1216
|
+
option(
|
|
1217
|
+
"scrollBeyondLastLine",
|
|
1218
|
+
(use) => use ? scrollBeyondLastLine() : []
|
|
1219
|
+
),
|
|
1220
|
+
option("uri", (id) => uriFacet.of(id)),
|
|
1221
|
+
option("theme", (themeName) => themes.get(themeName) ?? []),
|
|
1222
|
+
option("languageId", (id) => [
|
|
1223
|
+
languageIdFacet.of(id),
|
|
1224
|
+
languages.getExtension(id)
|
|
1225
|
+
]),
|
|
1226
|
+
option(
|
|
1227
|
+
"transformer",
|
|
1228
|
+
(transformer) => transformerFacet.of(transformer)
|
|
1229
|
+
),
|
|
1230
|
+
option("overlayScrollbar", (enable = true) => enable ? [scrollbar()] : []),
|
|
1231
|
+
option(
|
|
1232
|
+
"lineNumbersGutter",
|
|
1233
|
+
(enable = true) => enable ? lineNumbers({
|
|
1234
|
+
domEventHandlers: {
|
|
1235
|
+
// avoid blur
|
|
1236
|
+
mousedown: (view2, line, event) => {
|
|
1237
|
+
event.preventDefault();
|
|
1238
|
+
return false;
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
1241
|
+
}) : []
|
|
1242
|
+
),
|
|
1243
|
+
option(
|
|
1244
|
+
"foldGutter",
|
|
1245
|
+
(enable = true) => enable ? foldGutter({
|
|
1246
|
+
markerDOM(open) {
|
|
1247
|
+
const dom = document.createElement("div");
|
|
1248
|
+
dom.innerHTML = open ? SVG_FOLD_OPEN : SVG_FOLD_CLOSE;
|
|
1249
|
+
return dom;
|
|
1250
|
+
},
|
|
1251
|
+
domEventHandlers: {
|
|
1252
|
+
// avoid blur
|
|
1253
|
+
mousedown: (view2, line, event) => {
|
|
1254
|
+
event.preventDefault();
|
|
1255
|
+
return false;
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
}) : []
|
|
1259
|
+
),
|
|
1260
|
+
option(
|
|
1261
|
+
"colorizeBrackets",
|
|
1262
|
+
(enable = true) => enable ? colorizationBrackets : []
|
|
1263
|
+
),
|
|
1264
|
+
api("validate", ({ view: view2 }) => () => {
|
|
1265
|
+
view2.dispatch({
|
|
1266
|
+
userEvent: LINT_REFRESH_USER_EVENT
|
|
1267
|
+
});
|
|
1268
|
+
})
|
|
1269
|
+
];
|
|
1270
|
+
themes.register("_light", vscodeLight);
|
|
1271
|
+
themes.register("_dark", vscodeDark);
|
|
1272
|
+
var index_default = preset;
|
|
1273
|
+
export {
|
|
1274
|
+
create_theme_default as createTheme,
|
|
1275
|
+
index_default as default,
|
|
1276
|
+
languages,
|
|
1277
|
+
tags,
|
|
1278
|
+
themes,
|
|
1279
|
+
transformerCreator
|
|
1280
|
+
};
|
|
1281
|
+
//# sourceMappingURL=index.js.map
|