funkscript 0.2.6 → 0.2.7
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 +1 -1
- package/dist/cli/build-watch.d.ts.map +1 -1
- package/dist/cli/build-watch.js +4 -24
- package/dist/cli/build-watch.js.map +1 -1
- package/dist/cli/build.d.ts.map +1 -1
- package/dist/cli/build.js +3 -58
- package/dist/cli/build.js.map +1 -1
- package/dist/cli/check-policy.d.ts +9 -0
- package/dist/cli/check-policy.d.ts.map +1 -0
- package/dist/cli/check-policy.js +39 -0
- package/dist/cli/check-policy.js.map +1 -0
- package/dist/cli/check.d.ts.map +1 -1
- package/dist/cli/check.js +16 -30
- package/dist/cli/check.js.map +1 -1
- package/dist/cli/commands.d.ts.map +1 -1
- package/dist/cli/commands.js +11 -0
- package/dist/cli/commands.js.map +1 -1
- package/dist/cli/doctor.d.ts.map +1 -1
- package/dist/cli/doctor.js +2 -6
- package/dist/cli/doctor.js.map +1 -1
- package/dist/cli/index.js +3 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/query.d.ts +3 -0
- package/dist/cli/query.d.ts.map +1 -0
- package/dist/cli/query.js +152 -0
- package/dist/cli/query.js.map +1 -0
- package/dist/cli/run.d.ts.map +1 -1
- package/dist/cli/run.js +2 -29
- package/dist/cli/run.js.map +1 -1
- package/dist/cli/tsc.d.ts.map +1 -1
- package/dist/cli/tsc.js +2 -6
- package/dist/cli/tsc.js.map +1 -1
- package/dist/compiler/check.d.ts.map +1 -1
- package/dist/compiler/check.js +18 -28
- package/dist/compiler/check.js.map +1 -1
- package/dist/compiler/diagnostics-json.d.ts +73 -0
- package/dist/compiler/diagnostics-json.d.ts.map +1 -0
- package/dist/compiler/diagnostics-json.js +957 -0
- package/dist/compiler/diagnostics-json.js.map +1 -0
- package/dist/compiler/escape-audit.d.ts +46 -0
- package/dist/compiler/escape-audit.d.ts.map +1 -0
- package/dist/compiler/escape-audit.js +682 -0
- package/dist/compiler/escape-audit.js.map +1 -0
- package/dist/compiler/modules/output-plan.d.ts.map +1 -1
- package/dist/compiler/modules/output-plan.js +10 -5
- package/dist/compiler/modules/output-plan.js.map +1 -1
- package/dist/compiler/modules/source-files.d.ts +2 -0
- package/dist/compiler/modules/source-files.d.ts.map +1 -1
- package/dist/compiler/modules/source-files.js +8 -0
- package/dist/compiler/modules/source-files.js.map +1 -1
- package/dist/compiler/numeric-comparisons.d.ts.map +1 -1
- package/dist/compiler/numeric-comparisons.js +13 -7
- package/dist/compiler/numeric-comparisons.js.map +1 -1
- package/dist/compiler/pipelines/resolution.d.ts.map +1 -1
- package/dist/compiler/pipelines/resolution.js +24 -23
- package/dist/compiler/pipelines/resolution.js.map +1 -1
- package/dist/compiler/query.d.ts +53 -0
- package/dist/compiler/query.d.ts.map +1 -0
- package/dist/compiler/query.js +781 -0
- package/dist/compiler/query.js.map +1 -0
- package/dist/compiler/source-map.d.ts.map +1 -1
- package/dist/compiler/source-map.js +2 -7
- package/dist/compiler/source-map.js.map +1 -1
- package/dist/compiler/type-view-paths.d.ts +2 -0
- package/dist/compiler/type-view-paths.d.ts.map +1 -1
- package/dist/compiler/type-view-paths.js +8 -0
- package/dist/compiler/type-view-paths.js.map +1 -1
- package/dist/compiler/typescript-context.d.ts.map +1 -1
- package/dist/compiler/typescript-context.js +5 -7
- package/dist/compiler/typescript-context.js.map +1 -1
- package/dist/emitter/assemblyscript.d.ts.map +1 -1
- package/dist/emitter/assemblyscript.js +120 -136
- package/dist/emitter/assemblyscript.js.map +1 -1
- package/dist/formatter/index.d.ts +9 -0
- package/dist/formatter/index.d.ts.map +1 -1
- package/dist/formatter/index.js +158 -2
- package/dist/formatter/index.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/lsp/completion.d.ts +25 -0
- package/dist/lsp/completion.d.ts.map +1 -1
- package/dist/lsp/completion.js +1114 -51
- package/dist/lsp/completion.js.map +1 -1
- package/dist/lsp/definition.d.ts +2 -0
- package/dist/lsp/definition.d.ts.map +1 -1
- package/dist/lsp/definition.js +52 -58
- package/dist/lsp/definition.js.map +1 -1
- package/dist/lsp/hover.d.ts +5 -1
- package/dist/lsp/hover.d.ts.map +1 -1
- package/dist/lsp/hover.js +1000 -41
- package/dist/lsp/hover.js.map +1 -1
- package/dist/lsp/imports.d.ts +2 -0
- package/dist/lsp/imports.d.ts.map +1 -1
- package/dist/lsp/imports.js +35 -20
- package/dist/lsp/imports.js.map +1 -1
- package/dist/lsp/navigation.d.ts +1 -1
- package/dist/lsp/navigation.d.ts.map +1 -1
- package/dist/lsp/navigation.js +30 -12
- package/dist/lsp/navigation.js.map +1 -1
- package/dist/lsp/range-format.d.ts +4 -0
- package/dist/lsp/range-format.d.ts.map +1 -0
- package/dist/lsp/range-format.js +88 -0
- package/dist/lsp/range-format.js.map +1 -0
- package/dist/lsp/schema-import-hover.d.ts +8 -0
- package/dist/lsp/schema-import-hover.d.ts.map +1 -0
- package/dist/lsp/schema-import-hover.js +52 -0
- package/dist/lsp/schema-import-hover.js.map +1 -0
- package/dist/lsp/server.d.ts +1 -0
- package/dist/lsp/server.d.ts.map +1 -1
- package/dist/lsp/server.js +53 -48
- package/dist/lsp/server.js.map +1 -1
- package/dist/lsp/workspace.d.ts +3 -1
- package/dist/lsp/workspace.d.ts.map +1 -1
- package/dist/lsp/workspace.js +66 -10
- package/dist/lsp/workspace.js.map +1 -1
- package/dist/plugins/bun.d.ts +2 -18
- package/dist/plugins/bun.d.ts.map +1 -1
- package/dist/plugins/bun.js +5 -30
- package/dist/plugins/bun.js.map +1 -1
- package/dist/plugins/esbuild.d.ts +1 -1
- package/dist/plugins/esbuild.d.ts.map +1 -1
- package/dist/plugins/esbuild.js +10 -36
- package/dist/plugins/esbuild.js.map +1 -1
- package/dist/plugins/server-boundary.d.ts +14 -0
- package/dist/plugins/server-boundary.d.ts.map +1 -0
- package/dist/plugins/server-boundary.js +25 -0
- package/dist/plugins/server-boundary.js.map +1 -0
- package/dist/plugins/vite.d.ts +2 -18
- package/dist/plugins/vite.d.ts.map +1 -1
- package/dist/plugins/vite.js +4 -29
- package/dist/plugins/vite.js.map +1 -1
- package/package.json +1 -1
- package/src/cli/build-watch.ts +4 -26
- package/src/cli/build.ts +9 -60
- package/src/cli/check-policy.ts +54 -0
- package/src/cli/check.ts +19 -31
- package/src/cli/commands.ts +13 -0
- package/src/cli/doctor.ts +2 -5
- package/src/cli/index.ts +3 -0
- package/src/cli/query.ts +191 -0
- package/src/cli/run.ts +5 -30
- package/src/cli/tsc.ts +2 -5
- package/src/compiler/check.ts +28 -48
- package/src/compiler/diagnostics-json.ts +1205 -0
- package/src/compiler/escape-audit.ts +913 -0
- package/src/compiler/modules/output-plan.ts +11 -9
- package/src/compiler/modules/source-files.ts +9 -0
- package/src/compiler/numeric-comparisons.ts +14 -8
- package/src/compiler/pipelines/resolution.ts +30 -26
- package/src/compiler/query.ts +1177 -0
- package/src/compiler/source-map.ts +3 -7
- package/src/compiler/type-view-paths.ts +7 -0
- package/src/compiler/typescript-context.ts +6 -7
- package/src/emitter/assemblyscript.ts +101 -147
- package/src/formatter/index.ts +229 -2
- package/src/index.ts +3 -0
- package/src/lsp/completion.ts +1452 -66
- package/src/lsp/definition.ts +50 -58
- package/src/lsp/hover.ts +1442 -40
- package/src/lsp/imports.ts +55 -21
- package/src/lsp/navigation.ts +41 -22
- package/src/lsp/range-format.ts +102 -0
- package/src/lsp/schema-import-hover.ts +76 -0
- package/src/lsp/server.ts +69 -69
- package/src/lsp/workspace.ts +63 -9
- package/src/plugins/bun.ts +14 -66
- package/src/plugins/esbuild.ts +16 -55
- package/src/plugins/server-boundary.ts +41 -0
- package/src/plugins/vite.ts +12 -62
package/dist/lsp/completion.js
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { dirname, resolve } from "node:path";
|
|
3
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
1
4
|
import { CompletionItemKind, } from "vscode-languageserver/node";
|
|
2
5
|
import { PIPELINE_COMPANION_CATALOG, pipelineCompanionCandidates, } from "../compiler/pipelines/catalog.js";
|
|
6
|
+
import { isExpectedSyntaxError, isExpectedUriError, isFileNotFoundError, } from "../errors.js";
|
|
7
|
+
import { Lexer } from "../lexer/lexer.js";
|
|
8
|
+
import { Parser } from "../parser/parser.js";
|
|
3
9
|
import { DOC_CATALOG, getAllDocKeywords } from "./docs.js";
|
|
4
10
|
const PRIMARY_DISAMBIGUATION_MODULES = new Set([
|
|
5
11
|
"Array",
|
|
@@ -50,56 +56,1136 @@ const DEFERRED_PIPELINE_CONSTRUCTORS = [
|
|
|
50
56
|
documentation: "Lazily computes an error value and fails on the Effect error channel (`Effect<never, E>`).",
|
|
51
57
|
},
|
|
52
58
|
];
|
|
59
|
+
const INTRINSIC_JSX_TAGS = [
|
|
60
|
+
"div",
|
|
61
|
+
"span",
|
|
62
|
+
"button",
|
|
63
|
+
"input",
|
|
64
|
+
"form",
|
|
65
|
+
"main",
|
|
66
|
+
"section",
|
|
67
|
+
"header",
|
|
68
|
+
"footer",
|
|
69
|
+
"ul",
|
|
70
|
+
"li",
|
|
71
|
+
"a",
|
|
72
|
+
"p",
|
|
73
|
+
"h1",
|
|
74
|
+
"h2",
|
|
75
|
+
"h3",
|
|
76
|
+
"label",
|
|
77
|
+
"textarea",
|
|
78
|
+
"select",
|
|
79
|
+
"option",
|
|
80
|
+
"img",
|
|
81
|
+
"svg",
|
|
82
|
+
"path",
|
|
83
|
+
];
|
|
84
|
+
const COMMON_JSX_PROPS = [
|
|
85
|
+
"class",
|
|
86
|
+
"className",
|
|
87
|
+
"id",
|
|
88
|
+
"style",
|
|
89
|
+
"key",
|
|
90
|
+
"children",
|
|
91
|
+
"onClick",
|
|
92
|
+
"onChange",
|
|
93
|
+
"onInput",
|
|
94
|
+
"onSubmit",
|
|
95
|
+
"disabled",
|
|
96
|
+
"href",
|
|
97
|
+
"type",
|
|
98
|
+
"value",
|
|
99
|
+
"placeholder",
|
|
100
|
+
"title",
|
|
101
|
+
];
|
|
53
102
|
function escapeRegExp(value) {
|
|
54
103
|
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
55
104
|
}
|
|
105
|
+
function isJsxOpenStart(lastSig, prevLastSig, nextChar) {
|
|
106
|
+
if (nextChar === "=" || nextChar === "<")
|
|
107
|
+
return false;
|
|
108
|
+
if (nextChar !== undefined && !/[A-Za-z_>]/.test(nextChar))
|
|
109
|
+
return false;
|
|
110
|
+
if (lastSig === "" || lastSig === "\n")
|
|
111
|
+
return true;
|
|
112
|
+
if (lastSig === ">" && prevLastSig === "=")
|
|
113
|
+
return true;
|
|
114
|
+
if (/[=([{,:?|&!]/.test(lastSig))
|
|
115
|
+
return true;
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
/** Scans `.funx` source up to cursor to determine the active JSX syntactic context. */
|
|
119
|
+
export function detectJsxContext(sourceUpToCursor) {
|
|
120
|
+
const stack = [
|
|
121
|
+
{ kind: "code", braceDepth: 0, lastSig: "", prevLastSig: "" },
|
|
122
|
+
];
|
|
123
|
+
let i = 0;
|
|
124
|
+
const len = sourceUpToCursor.length;
|
|
125
|
+
while (i < len) {
|
|
126
|
+
const top = stack[stack.length - 1];
|
|
127
|
+
const ch = sourceUpToCursor[i];
|
|
128
|
+
if (top.kind === "string") {
|
|
129
|
+
if (ch === "\\") {
|
|
130
|
+
i += 2;
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
if (ch === '"') {
|
|
134
|
+
stack.pop();
|
|
135
|
+
i++;
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
if (ch === "{") {
|
|
139
|
+
stack.push({
|
|
140
|
+
kind: "code",
|
|
141
|
+
braceDepth: 0,
|
|
142
|
+
lastSig: "{",
|
|
143
|
+
prevLastSig: "",
|
|
144
|
+
returnTo: "string",
|
|
145
|
+
});
|
|
146
|
+
i++;
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
i++;
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
if (top.kind === "jsx-children") {
|
|
153
|
+
if (ch === "<") {
|
|
154
|
+
if (sourceUpToCursor[i + 1] === "/") {
|
|
155
|
+
stack.push({
|
|
156
|
+
kind: "jsx-tag",
|
|
157
|
+
isClosing: true,
|
|
158
|
+
tagName: "",
|
|
159
|
+
phase: "name",
|
|
160
|
+
usedAttrs: new Set(),
|
|
161
|
+
currentAttr: "",
|
|
162
|
+
});
|
|
163
|
+
i += 2;
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
stack.push({
|
|
167
|
+
kind: "jsx-tag",
|
|
168
|
+
isClosing: false,
|
|
169
|
+
tagName: "",
|
|
170
|
+
phase: "name",
|
|
171
|
+
usedAttrs: new Set(),
|
|
172
|
+
currentAttr: "",
|
|
173
|
+
});
|
|
174
|
+
i++;
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
if (ch === "{") {
|
|
178
|
+
stack.push({
|
|
179
|
+
kind: "code",
|
|
180
|
+
braceDepth: 0,
|
|
181
|
+
lastSig: "{",
|
|
182
|
+
prevLastSig: "",
|
|
183
|
+
returnTo: "jsx-children",
|
|
184
|
+
});
|
|
185
|
+
i++;
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
i++;
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
if (top.kind === "jsx-tag") {
|
|
192
|
+
if (ch === "/" && sourceUpToCursor[i + 1] === "/") {
|
|
193
|
+
const nl = sourceUpToCursor.indexOf("\n", i + 2);
|
|
194
|
+
if (nl === -1)
|
|
195
|
+
return { kind: "non-jsx" };
|
|
196
|
+
i = nl + 1;
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
if (ch === "/" && sourceUpToCursor[i + 1] === ">") {
|
|
200
|
+
stack.pop();
|
|
201
|
+
i += 2;
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
if (ch === ">") {
|
|
205
|
+
stack.pop();
|
|
206
|
+
if (top.isClosing) {
|
|
207
|
+
for (let k = stack.length - 1; k >= 0; k--) {
|
|
208
|
+
if (stack[k].kind === "jsx-children") {
|
|
209
|
+
if (!top.tagName ||
|
|
210
|
+
stack[k].tagName === top.tagName) {
|
|
211
|
+
stack.splice(k);
|
|
212
|
+
break;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
else if (stack[k].kind === "code") {
|
|
216
|
+
break;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
stack.push({ kind: "jsx-children", tagName: top.tagName });
|
|
222
|
+
}
|
|
223
|
+
i++;
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
if (top.phase === "name") {
|
|
227
|
+
if (/[A-Za-z0-9_$.-]/.test(ch)) {
|
|
228
|
+
top.tagName += ch;
|
|
229
|
+
i++;
|
|
230
|
+
continue;
|
|
231
|
+
}
|
|
232
|
+
if (/\s/.test(ch)) {
|
|
233
|
+
if (top.tagName.length > 0) {
|
|
234
|
+
top.phase = top.isClosing ? "close-ws" : "attrs";
|
|
235
|
+
}
|
|
236
|
+
i++;
|
|
237
|
+
continue;
|
|
238
|
+
}
|
|
239
|
+
i++;
|
|
240
|
+
continue;
|
|
241
|
+
}
|
|
242
|
+
if (top.phase === "close-ws") {
|
|
243
|
+
i++;
|
|
244
|
+
continue;
|
|
245
|
+
}
|
|
246
|
+
if (top.phase === "attr-val") {
|
|
247
|
+
if (/\s/.test(ch)) {
|
|
248
|
+
i++;
|
|
249
|
+
continue;
|
|
250
|
+
}
|
|
251
|
+
if (ch === '"') {
|
|
252
|
+
top.phase = "attrs";
|
|
253
|
+
stack.push({ kind: "string", returnTo: "jsx-tag" });
|
|
254
|
+
i++;
|
|
255
|
+
continue;
|
|
256
|
+
}
|
|
257
|
+
if (ch === "{") {
|
|
258
|
+
top.phase = "attrs";
|
|
259
|
+
stack.push({
|
|
260
|
+
kind: "code",
|
|
261
|
+
braceDepth: 0,
|
|
262
|
+
lastSig: "{",
|
|
263
|
+
prevLastSig: "",
|
|
264
|
+
returnTo: "jsx-tag",
|
|
265
|
+
});
|
|
266
|
+
i++;
|
|
267
|
+
continue;
|
|
268
|
+
}
|
|
269
|
+
if (/[A-Za-z_$-]/.test(ch)) {
|
|
270
|
+
top.phase = "attrs";
|
|
271
|
+
top.currentAttr = ch;
|
|
272
|
+
i++;
|
|
273
|
+
continue;
|
|
274
|
+
}
|
|
275
|
+
top.phase = "attrs";
|
|
276
|
+
i++;
|
|
277
|
+
continue;
|
|
278
|
+
}
|
|
279
|
+
// phase === "attrs"
|
|
280
|
+
if (/\s/.test(ch)) {
|
|
281
|
+
if (top.currentAttr) {
|
|
282
|
+
top.usedAttrs.add(top.currentAttr);
|
|
283
|
+
top.currentAttr = "";
|
|
284
|
+
}
|
|
285
|
+
i++;
|
|
286
|
+
continue;
|
|
287
|
+
}
|
|
288
|
+
if (ch === "=") {
|
|
289
|
+
if (top.currentAttr) {
|
|
290
|
+
top.usedAttrs.add(top.currentAttr);
|
|
291
|
+
top.currentAttr = "";
|
|
292
|
+
}
|
|
293
|
+
top.phase = "attr-val";
|
|
294
|
+
i++;
|
|
295
|
+
continue;
|
|
296
|
+
}
|
|
297
|
+
if (ch === '"') {
|
|
298
|
+
stack.push({ kind: "string", returnTo: "jsx-tag" });
|
|
299
|
+
i++;
|
|
300
|
+
continue;
|
|
301
|
+
}
|
|
302
|
+
if (ch === "{") {
|
|
303
|
+
stack.push({
|
|
304
|
+
kind: "code",
|
|
305
|
+
braceDepth: 0,
|
|
306
|
+
lastSig: "{",
|
|
307
|
+
prevLastSig: "",
|
|
308
|
+
returnTo: "jsx-tag",
|
|
309
|
+
});
|
|
310
|
+
i++;
|
|
311
|
+
continue;
|
|
312
|
+
}
|
|
313
|
+
if (/[A-Za-z0-9_$:-]/.test(ch)) {
|
|
314
|
+
top.currentAttr += ch;
|
|
315
|
+
i++;
|
|
316
|
+
continue;
|
|
317
|
+
}
|
|
318
|
+
i++;
|
|
319
|
+
continue;
|
|
320
|
+
}
|
|
321
|
+
// top.kind === "code"
|
|
322
|
+
if (ch === "/" && sourceUpToCursor[i + 1] === "/") {
|
|
323
|
+
const nl = sourceUpToCursor.indexOf("\n", i + 2);
|
|
324
|
+
if (nl === -1)
|
|
325
|
+
return { kind: "non-jsx" };
|
|
326
|
+
top.prevLastSig = top.lastSig;
|
|
327
|
+
top.lastSig = "\n";
|
|
328
|
+
i = nl + 1;
|
|
329
|
+
continue;
|
|
330
|
+
}
|
|
331
|
+
if (ch === "/" && sourceUpToCursor[i + 1] === "*") {
|
|
332
|
+
const end = sourceUpToCursor.indexOf("*/", i + 2);
|
|
333
|
+
if (end === -1)
|
|
334
|
+
return { kind: "non-jsx" };
|
|
335
|
+
i = end + 2;
|
|
336
|
+
continue;
|
|
337
|
+
}
|
|
338
|
+
if (ch === '"') {
|
|
339
|
+
top.prevLastSig = top.lastSig;
|
|
340
|
+
top.lastSig = '"';
|
|
341
|
+
stack.push({ kind: "string", returnTo: "code" });
|
|
342
|
+
i++;
|
|
343
|
+
continue;
|
|
344
|
+
}
|
|
345
|
+
if (ch === "{") {
|
|
346
|
+
top.braceDepth++;
|
|
347
|
+
top.prevLastSig = top.lastSig;
|
|
348
|
+
top.lastSig = "{";
|
|
349
|
+
i++;
|
|
350
|
+
continue;
|
|
351
|
+
}
|
|
352
|
+
if (ch === "}") {
|
|
353
|
+
if (top.braceDepth > 0) {
|
|
354
|
+
top.braceDepth--;
|
|
355
|
+
top.prevLastSig = top.lastSig;
|
|
356
|
+
top.lastSig = "}";
|
|
357
|
+
}
|
|
358
|
+
else if (top.returnTo) {
|
|
359
|
+
stack.pop();
|
|
360
|
+
}
|
|
361
|
+
i++;
|
|
362
|
+
continue;
|
|
363
|
+
}
|
|
364
|
+
if (ch === "<") {
|
|
365
|
+
const next = sourceUpToCursor[i + 1];
|
|
366
|
+
if (next === "/") {
|
|
367
|
+
stack.push({
|
|
368
|
+
kind: "jsx-tag",
|
|
369
|
+
isClosing: true,
|
|
370
|
+
tagName: "",
|
|
371
|
+
phase: "name",
|
|
372
|
+
usedAttrs: new Set(),
|
|
373
|
+
currentAttr: "",
|
|
374
|
+
});
|
|
375
|
+
i += 2;
|
|
376
|
+
continue;
|
|
377
|
+
}
|
|
378
|
+
if (isJsxOpenStart(top.lastSig, top.prevLastSig, next)) {
|
|
379
|
+
stack.push({
|
|
380
|
+
kind: "jsx-tag",
|
|
381
|
+
isClosing: false,
|
|
382
|
+
tagName: "",
|
|
383
|
+
phase: "name",
|
|
384
|
+
usedAttrs: new Set(),
|
|
385
|
+
currentAttr: "",
|
|
386
|
+
});
|
|
387
|
+
i++;
|
|
388
|
+
continue;
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
if (ch === "\n") {
|
|
392
|
+
top.prevLastSig = top.lastSig;
|
|
393
|
+
top.lastSig = "\n";
|
|
394
|
+
i++;
|
|
395
|
+
continue;
|
|
396
|
+
}
|
|
397
|
+
if (/\s/.test(ch)) {
|
|
398
|
+
i++;
|
|
399
|
+
continue;
|
|
400
|
+
}
|
|
401
|
+
top.prevLastSig = top.lastSig;
|
|
402
|
+
top.lastSig = ch;
|
|
403
|
+
i++;
|
|
404
|
+
}
|
|
405
|
+
const finalTop = stack[stack.length - 1];
|
|
406
|
+
if (finalTop.kind === "string") {
|
|
407
|
+
return { kind: "non-jsx" };
|
|
408
|
+
}
|
|
409
|
+
if (finalTop.kind === "jsx-children") {
|
|
410
|
+
return { kind: "jsx-children" };
|
|
411
|
+
}
|
|
412
|
+
if (finalTop.kind === "jsx-tag") {
|
|
413
|
+
if (finalTop.isClosing) {
|
|
414
|
+
let expectedTag = null;
|
|
415
|
+
for (let k = stack.length - 2; k >= 0; k--) {
|
|
416
|
+
if (stack[k].kind === "jsx-children") {
|
|
417
|
+
const name = stack[k].tagName;
|
|
418
|
+
if (name)
|
|
419
|
+
expectedTag = name;
|
|
420
|
+
break;
|
|
421
|
+
}
|
|
422
|
+
if (stack[k].kind === "code")
|
|
423
|
+
break;
|
|
424
|
+
}
|
|
425
|
+
return { kind: "jsx-close-tag", prefix: finalTop.tagName, expectedTag };
|
|
426
|
+
}
|
|
427
|
+
if (finalTop.phase === "name") {
|
|
428
|
+
const dotIdx = finalTop.tagName.lastIndexOf(".");
|
|
429
|
+
if (dotIdx !== -1) {
|
|
430
|
+
return {
|
|
431
|
+
kind: "jsx-member-tag",
|
|
432
|
+
objectName: finalTop.tagName.slice(0, dotIdx),
|
|
433
|
+
prefix: finalTop.tagName.slice(dotIdx + 1),
|
|
434
|
+
};
|
|
435
|
+
}
|
|
436
|
+
return { kind: "jsx-open-tag", prefix: finalTop.tagName };
|
|
437
|
+
}
|
|
438
|
+
if (finalTop.phase === "attrs") {
|
|
439
|
+
return {
|
|
440
|
+
kind: "jsx-attribute",
|
|
441
|
+
tagName: finalTop.tagName,
|
|
442
|
+
prefix: finalTop.currentAttr,
|
|
443
|
+
usedAttrs: finalTop.usedAttrs,
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
return { kind: "normal" };
|
|
448
|
+
}
|
|
449
|
+
function formatBindingTarget(target) {
|
|
450
|
+
if (target.kind === "Identifier" || target.kind === "UpperIdentifier") {
|
|
451
|
+
return target.name;
|
|
452
|
+
}
|
|
453
|
+
if (target.kind === "RecordPattern") {
|
|
454
|
+
return `{ ${target.fields
|
|
455
|
+
.map((f) => f.pattern
|
|
456
|
+
? `${f.key.name}: ${formatBindingTarget(f.pattern)}`
|
|
457
|
+
: f.key.name)
|
|
458
|
+
.join(", ")} }`;
|
|
459
|
+
}
|
|
460
|
+
return `[${target.elements.map((e) => ("name" in e && typeof e.name === "object" && e.name && "name" in e.name ? String(e.name.name) : "_")).join(", ")}]`;
|
|
461
|
+
}
|
|
462
|
+
function formatTypeNode(typeNode) {
|
|
463
|
+
switch (typeNode.kind) {
|
|
464
|
+
case "TypeReferenceNode": {
|
|
465
|
+
const args = typeNode.typeArgs && typeNode.typeArgs.length > 0
|
|
466
|
+
? `<${typeNode.typeArgs.map(formatTypeNode).join(", ")}>`
|
|
467
|
+
: "";
|
|
468
|
+
return `${typeNode.name.name}${args}`;
|
|
469
|
+
}
|
|
470
|
+
case "QualifiedTypeReferenceNode": {
|
|
471
|
+
const args = typeNode.typeArgs && typeNode.typeArgs.length > 0
|
|
472
|
+
? `<${typeNode.typeArgs.map(formatTypeNode).join(", ")}>`
|
|
473
|
+
: "";
|
|
474
|
+
return `${typeNode.parts.map((p) => p.name).join(".")}${args}`;
|
|
475
|
+
}
|
|
476
|
+
case "FunctionTypeNode": {
|
|
477
|
+
const params = typeNode.params
|
|
478
|
+
.map((p) => p.typeAnnotation
|
|
479
|
+
? `${formatBindingTarget(p.name)}: ${formatTypeNode(p.typeAnnotation)}`
|
|
480
|
+
: formatBindingTarget(p.name))
|
|
481
|
+
.join(", ");
|
|
482
|
+
return `(${params}) => ${formatTypeNode(typeNode.returnType)}`;
|
|
483
|
+
}
|
|
484
|
+
case "EffectTypeNode": {
|
|
485
|
+
const parts = [formatTypeNode(typeNode.success)];
|
|
486
|
+
if (typeNode.error)
|
|
487
|
+
parts.push(formatTypeNode(typeNode.error));
|
|
488
|
+
if (typeNode.requirements) {
|
|
489
|
+
if (!typeNode.error)
|
|
490
|
+
parts.push("never");
|
|
491
|
+
parts.push(formatTypeNode(typeNode.requirements));
|
|
492
|
+
}
|
|
493
|
+
return `Effect<${parts.join(", ")}>`;
|
|
494
|
+
}
|
|
495
|
+
case "RecordTypeNode":
|
|
496
|
+
return `{ ${typeNode.fields.map((f) => `${f.name.name}${f.optional ? "?" : ""}: ${formatTypeNode(f.typeAnnotation)}`).join(", ")} }`;
|
|
497
|
+
case "ArrayTypeNode":
|
|
498
|
+
return `Array<${formatTypeNode(typeNode.elementType)}>`;
|
|
499
|
+
case "UnionTypeNode":
|
|
500
|
+
return typeNode.types.map(formatTypeNode).join(" | ");
|
|
501
|
+
case "IntersectionTypeNode":
|
|
502
|
+
return typeNode.types.map(formatTypeNode).join(" & ");
|
|
503
|
+
case "LiteralTypeNode":
|
|
504
|
+
return typeof typeNode.value === "string"
|
|
505
|
+
? JSON.stringify(typeNode.value)
|
|
506
|
+
: String(typeNode.value);
|
|
507
|
+
case "ParenthesizedTypeNode":
|
|
508
|
+
return `(${formatTypeNode(typeNode.typeNode)})`;
|
|
509
|
+
case "TypeQueryNode":
|
|
510
|
+
return "typeof ...";
|
|
511
|
+
case "IndexedAccessTypeNode":
|
|
512
|
+
return `${formatTypeNode(typeNode.objectType)}[${formatTypeNode(typeNode.indexType)}]`;
|
|
513
|
+
case "TsEscapeTypeNode":
|
|
514
|
+
return `ts { ${typeNode.code.trim()} }`;
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
function tryParse(source, uri) {
|
|
518
|
+
try {
|
|
519
|
+
return new Parser(new Lexer(source, uri).tokenize(), uri).parse();
|
|
520
|
+
}
|
|
521
|
+
catch (error) {
|
|
522
|
+
if (!isExpectedSyntaxError(error))
|
|
523
|
+
throw error;
|
|
524
|
+
return null;
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
function resolveModuleDoc(fromUri, modulePath, documents) {
|
|
528
|
+
if (!modulePath.startsWith("."))
|
|
529
|
+
return null;
|
|
530
|
+
let base;
|
|
531
|
+
try {
|
|
532
|
+
base = resolve(dirname(fileURLToPath(fromUri)), modulePath);
|
|
533
|
+
}
|
|
534
|
+
catch (error) {
|
|
535
|
+
if (!isExpectedUriError(error))
|
|
536
|
+
throw error;
|
|
537
|
+
return null;
|
|
538
|
+
}
|
|
539
|
+
const candidates = [
|
|
540
|
+
base,
|
|
541
|
+
`${base}.fun`,
|
|
542
|
+
`${base}.funs`,
|
|
543
|
+
`${base}.funx`,
|
|
544
|
+
`${base}.ts`,
|
|
545
|
+
`${base}.tsx`,
|
|
546
|
+
resolve(base, "index.fun"),
|
|
547
|
+
resolve(base, "index.funs"),
|
|
548
|
+
resolve(base, "index.funx"),
|
|
549
|
+
];
|
|
550
|
+
for (const doc of documents) {
|
|
551
|
+
try {
|
|
552
|
+
if (candidates.includes(fileURLToPath(doc.uri)))
|
|
553
|
+
return doc;
|
|
554
|
+
}
|
|
555
|
+
catch (error) {
|
|
556
|
+
if (!isExpectedUriError(error))
|
|
557
|
+
throw error;
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
for (const candidate of candidates) {
|
|
561
|
+
try {
|
|
562
|
+
if (existsSync(candidate)) {
|
|
563
|
+
return {
|
|
564
|
+
uri: pathToFileURL(candidate).href,
|
|
565
|
+
text: readFileSync(candidate, "utf8"),
|
|
566
|
+
};
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
catch (error) {
|
|
570
|
+
if (!isFileNotFoundError(error) && !isExpectedUriError(error))
|
|
571
|
+
throw error;
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
return null;
|
|
575
|
+
}
|
|
576
|
+
function collectServiceMembersFromText(text, uri, serviceName) {
|
|
577
|
+
const ast = tryParse(text, uri);
|
|
578
|
+
if (ast) {
|
|
579
|
+
for (const top of ast.body) {
|
|
580
|
+
const inner = top.kind === "ExportDeclaration" ? top.declaration : top;
|
|
581
|
+
if (inner.kind === "ServiceDeclaration" &&
|
|
582
|
+
inner.id.name === serviceName) {
|
|
583
|
+
return inner.members.map((m) => ({
|
|
584
|
+
name: m.name.name,
|
|
585
|
+
detail: formatTypeNode(m.signature),
|
|
586
|
+
}));
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
const escaped = escapeRegExp(serviceName);
|
|
591
|
+
const blockMatch = new RegExp(`(?:^|\\n)\\s*(?:export\\s+)?service\\s+${escaped}\\b[^\\n]*\\n([\\s\\S]*?)(?=\\n\\S|$)`).exec(text);
|
|
592
|
+
if (!blockMatch)
|
|
593
|
+
return [];
|
|
594
|
+
const members = [];
|
|
595
|
+
for (const line of blockMatch[1].split(/\r?\n/)) {
|
|
596
|
+
const m = /^\s+([A-Za-z_$][\w$]*)\s*:\s*(.+)$/.exec(line);
|
|
597
|
+
if (m) {
|
|
598
|
+
members.push({ name: m[1], detail: m[2].trim() });
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
return members;
|
|
602
|
+
}
|
|
603
|
+
function collectSchemaMembersFromText(text, uri, schemaName) {
|
|
604
|
+
const results = [];
|
|
605
|
+
const ast = tryParse(text, uri);
|
|
606
|
+
if (ast) {
|
|
607
|
+
for (const top of ast.body) {
|
|
608
|
+
const inner = top.kind === "ExportDeclaration" ? top.declaration : top;
|
|
609
|
+
if (inner.kind === "SchemaDeclaration" && inner.id.name === schemaName) {
|
|
610
|
+
if (inner.body.kind === "RecordSchema") {
|
|
611
|
+
for (const f of inner.body.fields) {
|
|
612
|
+
results.push({
|
|
613
|
+
name: f.name.name,
|
|
614
|
+
kind: CompletionItemKind.Field,
|
|
615
|
+
detail: formatTypeNode(f.typeAnnotation),
|
|
616
|
+
});
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
else if (inner.body.kind === "TaggedUnionSchema") {
|
|
620
|
+
for (const v of inner.body.variants) {
|
|
621
|
+
results.push({
|
|
622
|
+
name: v.name.name,
|
|
623
|
+
kind: CompletionItemKind.EnumMember,
|
|
624
|
+
detail: `${schemaName} variant`,
|
|
625
|
+
});
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
return results;
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
const escaped = escapeRegExp(schemaName);
|
|
633
|
+
const schema = new RegExp(`(?:schema\\s+)?${escaped}\\s*=\\s*\\{([\\s\\S]*?)\\n\\}`, "m").exec(text);
|
|
634
|
+
if (schema) {
|
|
635
|
+
for (const field of schema[1].matchAll(/^\s*([A-Za-z_$][\w$]*)\s*:\s*([^,\n}]+)/gm)) {
|
|
636
|
+
results.push({
|
|
637
|
+
name: field[1],
|
|
638
|
+
kind: CompletionItemKind.Field,
|
|
639
|
+
detail: field[2].trim(),
|
|
640
|
+
});
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
const variants = new RegExp(`schema\\s+${escaped}\\s*=([\\s\\S]*?)(?:\\n\\S|$)`, "m").exec(text);
|
|
644
|
+
if (variants) {
|
|
645
|
+
for (const variant of variants[1].matchAll(/\|\s*([A-Z][A-Za-z0-9_$]*)/g)) {
|
|
646
|
+
results.push({
|
|
647
|
+
name: variant[1],
|
|
648
|
+
kind: CompletionItemKind.EnumMember,
|
|
649
|
+
detail: `${schemaName} variant`,
|
|
650
|
+
});
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
return results;
|
|
654
|
+
}
|
|
655
|
+
function inferExprDetail(expr) {
|
|
656
|
+
switch (expr.kind) {
|
|
657
|
+
case "FunctionExpression": {
|
|
658
|
+
const params = expr.params
|
|
659
|
+
.map((p) => p.typeAnnotation
|
|
660
|
+
? `${formatBindingTarget(p.name)}: ${formatTypeNode(p.typeAnnotation)}`
|
|
661
|
+
: formatBindingTarget(p.name))
|
|
662
|
+
.join(", ");
|
|
663
|
+
const ret = expr.returnType
|
|
664
|
+
? formatTypeNode(expr.returnType)
|
|
665
|
+
: "JSX.Element";
|
|
666
|
+
return `(${params}) => ${ret}`;
|
|
667
|
+
}
|
|
668
|
+
case "RecordExpression":
|
|
669
|
+
return "{ ... }";
|
|
670
|
+
case "NumberLiteral":
|
|
671
|
+
return "number";
|
|
672
|
+
case "StringLiteral":
|
|
673
|
+
return "string";
|
|
674
|
+
case "BooleanLiteral":
|
|
675
|
+
return "boolean";
|
|
676
|
+
default:
|
|
677
|
+
return "property";
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
function extractRecordFieldsFromRecordExpr(expr) {
|
|
681
|
+
const results = [];
|
|
682
|
+
for (const entry of expr.entries) {
|
|
683
|
+
if (entry.kind === "FieldEntry") {
|
|
684
|
+
results.push({
|
|
685
|
+
name: entry.key.name,
|
|
686
|
+
kind: entry.value.kind === "FunctionExpression"
|
|
687
|
+
? CompletionItemKind.Function
|
|
688
|
+
: CompletionItemKind.Property,
|
|
689
|
+
detail: inferExprDetail(entry.value),
|
|
690
|
+
});
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
return results;
|
|
694
|
+
}
|
|
695
|
+
function collectRecordBindingMembersFromText(text, uri, bindingName) {
|
|
696
|
+
const ast = tryParse(text, uri);
|
|
697
|
+
if (ast) {
|
|
698
|
+
for (const top of ast.body) {
|
|
699
|
+
const inner = top.kind === "ExportDeclaration" ? top.declaration : top;
|
|
700
|
+
if (inner.kind === "BindingDeclaration" &&
|
|
701
|
+
"name" in inner.id &&
|
|
702
|
+
inner.id.name === bindingName) {
|
|
703
|
+
if (inner.init.kind === "RecordExpression") {
|
|
704
|
+
return extractRecordFieldsFromRecordExpr(inner.init);
|
|
705
|
+
}
|
|
706
|
+
if (inner.typeAnnotation?.kind === "RecordTypeNode") {
|
|
707
|
+
return inner.typeAnnotation.fields.map((f) => ({
|
|
708
|
+
name: f.name.name,
|
|
709
|
+
kind: CompletionItemKind.Field,
|
|
710
|
+
detail: formatTypeNode(f.typeAnnotation),
|
|
711
|
+
}));
|
|
712
|
+
}
|
|
713
|
+
if (inner.typeAnnotation?.kind === "TypeReferenceNode") {
|
|
714
|
+
return collectSchemaMembersFromText(text, uri, inner.typeAnnotation.name.name);
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
// Regex + balanced-brace fallback when current buffer has incomplete syntax (e.g. `<Icons.`)
|
|
720
|
+
const headerRe = new RegExp(`(?:^|\\n)\\s*(?:export\\s+)?(?:mut\\s+)?${escapeRegExp(bindingName)}\\s*(?::[^=\\n]+)?=\\s*\\{`);
|
|
721
|
+
const headerMatch = headerRe.exec(text);
|
|
722
|
+
if (!headerMatch)
|
|
723
|
+
return [];
|
|
724
|
+
const openBraceIdx = headerMatch.index + headerMatch[0].length - 1;
|
|
725
|
+
let depth = 0;
|
|
726
|
+
let inString = false;
|
|
727
|
+
let lineStart = openBraceIdx + 1;
|
|
728
|
+
const results = [];
|
|
729
|
+
for (let i = openBraceIdx; i < text.length; i++) {
|
|
730
|
+
const ch = text[i];
|
|
731
|
+
if (inString) {
|
|
732
|
+
if (ch === "\\") {
|
|
733
|
+
i++;
|
|
734
|
+
continue;
|
|
735
|
+
}
|
|
736
|
+
if (ch === '"')
|
|
737
|
+
inString = false;
|
|
738
|
+
continue;
|
|
739
|
+
}
|
|
740
|
+
if (ch === '"') {
|
|
741
|
+
inString = true;
|
|
742
|
+
continue;
|
|
743
|
+
}
|
|
744
|
+
if (ch === "/" && text[i + 1] === "/") {
|
|
745
|
+
const nl = text.indexOf("\n", i + 2);
|
|
746
|
+
i = nl === -1 ? text.length : nl;
|
|
747
|
+
lineStart = i + 1;
|
|
748
|
+
continue;
|
|
749
|
+
}
|
|
750
|
+
if (ch === "{") {
|
|
751
|
+
depth++;
|
|
752
|
+
if (depth === 1)
|
|
753
|
+
lineStart = i + 1;
|
|
754
|
+
continue;
|
|
755
|
+
}
|
|
756
|
+
if (ch === "}") {
|
|
757
|
+
if (depth === 1) {
|
|
758
|
+
const segment = text.slice(lineStart, i).trim();
|
|
759
|
+
const field = /^([A-Za-z_$][\w$]*)\s*:/.exec(segment);
|
|
760
|
+
if (field) {
|
|
761
|
+
results.push({
|
|
762
|
+
name: field[1],
|
|
763
|
+
kind: CompletionItemKind.Property,
|
|
764
|
+
detail: "property",
|
|
765
|
+
});
|
|
766
|
+
}
|
|
767
|
+
break;
|
|
768
|
+
}
|
|
769
|
+
depth--;
|
|
770
|
+
continue;
|
|
771
|
+
}
|
|
772
|
+
if (depth === 1 && (ch === "\n" || ch === ",")) {
|
|
773
|
+
const segment = text.slice(lineStart, i).trim();
|
|
774
|
+
const field = /^([A-Za-z_$][\w$]*)\s*:/.exec(segment);
|
|
775
|
+
if (field) {
|
|
776
|
+
results.push({
|
|
777
|
+
name: field[1],
|
|
778
|
+
kind: CompletionItemKind.Property,
|
|
779
|
+
detail: "property",
|
|
780
|
+
});
|
|
781
|
+
}
|
|
782
|
+
lineStart = i + 1;
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
return results;
|
|
786
|
+
}
|
|
787
|
+
function collectExportedSymbolsFromText(text, uri) {
|
|
788
|
+
const ast = tryParse(text, uri);
|
|
789
|
+
const results = [];
|
|
790
|
+
if (ast) {
|
|
791
|
+
for (const top of ast.body) {
|
|
792
|
+
if (top.kind !== "ExportDeclaration")
|
|
793
|
+
continue;
|
|
794
|
+
const decl = top.declaration;
|
|
795
|
+
if (decl.kind === "BindingDeclaration" && "name" in decl.id) {
|
|
796
|
+
results.push({
|
|
797
|
+
name: decl.id.name,
|
|
798
|
+
kind: decl.init.kind === "FunctionExpression"
|
|
799
|
+
? CompletionItemKind.Function
|
|
800
|
+
: CompletionItemKind.Variable,
|
|
801
|
+
detail: inferExprDetail(decl.init),
|
|
802
|
+
});
|
|
803
|
+
}
|
|
804
|
+
else if (decl.kind === "SchemaDeclaration") {
|
|
805
|
+
results.push({
|
|
806
|
+
name: decl.id.name,
|
|
807
|
+
kind: CompletionItemKind.Struct,
|
|
808
|
+
detail: "schema",
|
|
809
|
+
});
|
|
810
|
+
}
|
|
811
|
+
else if (decl.kind === "ServiceDeclaration") {
|
|
812
|
+
results.push({
|
|
813
|
+
name: decl.id.name,
|
|
814
|
+
kind: CompletionItemKind.Interface,
|
|
815
|
+
detail: "service",
|
|
816
|
+
});
|
|
817
|
+
}
|
|
818
|
+
else if (decl.kind === "ErrorDeclaration") {
|
|
819
|
+
results.push({
|
|
820
|
+
name: decl.id.name,
|
|
821
|
+
kind: CompletionItemKind.Class,
|
|
822
|
+
detail: "error",
|
|
823
|
+
});
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
return results;
|
|
827
|
+
}
|
|
828
|
+
for (const found of text.matchAll(/^\s*export\s+(?:(?:schema|error|service)\s+)?([A-Za-z_$][\w$]*)/gm)) {
|
|
829
|
+
results.push({
|
|
830
|
+
name: found[1],
|
|
831
|
+
kind: CompletionItemKind.Variable,
|
|
832
|
+
detail: "export",
|
|
833
|
+
});
|
|
834
|
+
}
|
|
835
|
+
return results;
|
|
836
|
+
}
|
|
837
|
+
function collectNamespaceImports(source, uri, documents) {
|
|
838
|
+
const namespaces = new Map();
|
|
839
|
+
for (const match of source.matchAll(/^\s*import\s+\*\s+as\s+([A-Za-z_$][\w$]*)\s+from\s+["']([^"']+)["']/gm)) {
|
|
840
|
+
const localName = match[1];
|
|
841
|
+
const modulePath = match[2];
|
|
842
|
+
const targetDoc = resolveModuleDoc(uri, modulePath, documents);
|
|
843
|
+
if (targetDoc) {
|
|
844
|
+
namespaces.set(localName, { doc: targetDoc, modulePath });
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
return namespaces;
|
|
848
|
+
}
|
|
849
|
+
function collectImportedSymbols(source, uri, documents) {
|
|
850
|
+
const imported = new Map();
|
|
851
|
+
for (const match of source.matchAll(/^\s*import\s+(?:type\s+)?\{([^}]+)\}\s+from\s+["']([^"']+)["']/gm)) {
|
|
852
|
+
const specList = match[1];
|
|
853
|
+
const modulePath = match[2];
|
|
854
|
+
const targetDoc = resolveModuleDoc(uri, modulePath, documents);
|
|
855
|
+
if (!targetDoc)
|
|
856
|
+
continue;
|
|
857
|
+
for (const rawSpec of specList.split(",")) {
|
|
858
|
+
const cleaned = rawSpec.trim().replace(/^type\s+/, "");
|
|
859
|
+
if (!cleaned)
|
|
860
|
+
continue;
|
|
861
|
+
const aliasMatch = /^([A-Za-z_$][\w$]*)\s+as\s+([A-Za-z_$][\w$]*)$/.exec(cleaned);
|
|
862
|
+
const exportedName = aliasMatch ? aliasMatch[1] : cleaned;
|
|
863
|
+
const localName = aliasMatch ? aliasMatch[2] : cleaned;
|
|
864
|
+
imported.set(localName, { doc: targetDoc, exportedName, modulePath });
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
return imported;
|
|
868
|
+
}
|
|
869
|
+
function findBindingInProgram(program, name) {
|
|
870
|
+
for (const top of program.body) {
|
|
871
|
+
const inner = top.kind === "ExportDeclaration" ? top.declaration : top;
|
|
872
|
+
if (inner.kind === "BindingDeclaration" &&
|
|
873
|
+
"name" in inner.id &&
|
|
874
|
+
inner.id.name === name) {
|
|
875
|
+
return inner;
|
|
876
|
+
}
|
|
877
|
+
}
|
|
878
|
+
return null;
|
|
879
|
+
}
|
|
880
|
+
function resolvePropsFromTypeNode(typeNode, ownerText, ownerUri, documents) {
|
|
881
|
+
if (typeNode.kind === "RecordTypeNode") {
|
|
882
|
+
return typeNode.fields.map((f) => ({
|
|
883
|
+
name: f.name.name,
|
|
884
|
+
type: formatTypeNode(f.typeAnnotation),
|
|
885
|
+
}));
|
|
886
|
+
}
|
|
887
|
+
if (typeNode.kind === "TypeReferenceNode") {
|
|
888
|
+
const schemaName = typeNode.name.name;
|
|
889
|
+
const localFields = collectSchemaMembersFromText(ownerText, ownerUri, schemaName);
|
|
890
|
+
if (localFields.length > 0) {
|
|
891
|
+
return localFields.map((f) => ({ name: f.name, type: f.detail }));
|
|
892
|
+
}
|
|
893
|
+
const ownerImports = collectImportedSymbols(ownerText, ownerUri, documents);
|
|
894
|
+
const importedSchema = ownerImports.get(schemaName);
|
|
895
|
+
if (importedSchema) {
|
|
896
|
+
return collectSchemaMembersFromText(importedSchema.doc.text, importedSchema.doc.uri, importedSchema.exportedName).map((f) => ({ name: f.name, type: f.detail }));
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
return [];
|
|
900
|
+
}
|
|
901
|
+
function resolveFunctionComponentProps(binding, ownerText, ownerUri, documents) {
|
|
902
|
+
if (binding.init.kind === "FunctionExpression") {
|
|
903
|
+
const firstParam = binding.init.params[0];
|
|
904
|
+
if (firstParam?.typeAnnotation) {
|
|
905
|
+
return resolvePropsFromTypeNode(firstParam.typeAnnotation, ownerText, ownerUri, documents);
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
if (binding.typeAnnotation?.kind === "FunctionTypeNode") {
|
|
909
|
+
const firstParam = binding.typeAnnotation.params[0];
|
|
910
|
+
if (firstParam?.typeAnnotation) {
|
|
911
|
+
return resolvePropsFromTypeNode(firstParam.typeAnnotation, ownerText, ownerUri, documents);
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
return [];
|
|
915
|
+
}
|
|
916
|
+
function parseCleanPrefixAst(source, uri) {
|
|
917
|
+
const direct = tryParse(source, uri);
|
|
918
|
+
if (direct)
|
|
919
|
+
return direct;
|
|
920
|
+
// When the user is mid-edit on a JSX tag, strip trailing lines until a clean AST parses
|
|
921
|
+
const lines = source.split("\n");
|
|
922
|
+
for (let end = lines.length - 1; end >= 1; end--) {
|
|
923
|
+
const candidate = lines.slice(0, end).join("\n");
|
|
924
|
+
const parsed = tryParse(candidate, uri);
|
|
925
|
+
if (parsed)
|
|
926
|
+
return parsed;
|
|
927
|
+
}
|
|
928
|
+
return null;
|
|
929
|
+
}
|
|
930
|
+
function collectComponentProps(source, uri, tagName, documents) {
|
|
931
|
+
const dotIdx = tagName.indexOf(".");
|
|
932
|
+
if (dotIdx !== -1) {
|
|
933
|
+
const objName = tagName.slice(0, dotIdx);
|
|
934
|
+
const propName = tagName.slice(dotIdx + 1);
|
|
935
|
+
let ownerText = source;
|
|
936
|
+
let ownerUri = uri;
|
|
937
|
+
let targetObjName = objName;
|
|
938
|
+
const imported = collectImportedSymbols(source, uri, documents).get(objName);
|
|
939
|
+
if (imported) {
|
|
940
|
+
ownerText = imported.doc.text;
|
|
941
|
+
ownerUri = imported.doc.uri;
|
|
942
|
+
targetObjName = imported.exportedName;
|
|
943
|
+
}
|
|
944
|
+
else {
|
|
945
|
+
const ns = collectNamespaceImports(source, uri, documents).get(objName);
|
|
946
|
+
if (ns) {
|
|
947
|
+
const nsAst = parseCleanPrefixAst(ns.doc.text, ns.doc.uri);
|
|
948
|
+
const memberBinding = nsAst
|
|
949
|
+
? findBindingInProgram(nsAst, propName)
|
|
950
|
+
: null;
|
|
951
|
+
if (memberBinding) {
|
|
952
|
+
return resolveFunctionComponentProps(memberBinding, ns.doc.text, ns.doc.uri, documents);
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
const ast = parseCleanPrefixAst(ownerText, ownerUri);
|
|
957
|
+
const binding = ast ? findBindingInProgram(ast, targetObjName) : null;
|
|
958
|
+
if (binding && binding.init.kind === "RecordExpression") {
|
|
959
|
+
const field = binding.init.entries.find((e) => e.kind === "FieldEntry" && e.key.name === propName);
|
|
960
|
+
if (field &&
|
|
961
|
+
field.kind === "FieldEntry" &&
|
|
962
|
+
field.value.kind === "FunctionExpression") {
|
|
963
|
+
const firstParam = field.value.params[0];
|
|
964
|
+
if (firstParam?.typeAnnotation) {
|
|
965
|
+
return resolvePropsFromTypeNode(firstParam.typeAnnotation, ownerText, ownerUri, documents);
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
return [];
|
|
970
|
+
}
|
|
971
|
+
let ownerText = source;
|
|
972
|
+
let ownerUri = uri;
|
|
973
|
+
let targetName = tagName;
|
|
974
|
+
const imported = collectImportedSymbols(source, uri, documents).get(tagName);
|
|
975
|
+
if (imported) {
|
|
976
|
+
ownerText = imported.doc.text;
|
|
977
|
+
ownerUri = imported.doc.uri;
|
|
978
|
+
targetName = imported.exportedName;
|
|
979
|
+
}
|
|
980
|
+
const ast = parseCleanPrefixAst(ownerText, ownerUri);
|
|
981
|
+
if (ast) {
|
|
982
|
+
const binding = findBindingInProgram(ast, targetName);
|
|
983
|
+
if (binding) {
|
|
984
|
+
const props = resolveFunctionComponentProps(binding, ownerText, ownerUri, documents);
|
|
985
|
+
if (props.length > 0)
|
|
986
|
+
return props;
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
// Regex fallback when AST parsing fails due to incomplete syntax
|
|
990
|
+
const fnRe = new RegExp(`(?:^|\\n)\\s*(?:export\\s+)?${escapeRegExp(targetName)}\\s*(?::[^=\\n]+)?=\\s*\\(\\s*[A-Za-z_$][\\w$]*\\s*:\\s*([A-Za-z_$][\\w$]*|\\{[^}]*\\})\\s*\\)`);
|
|
991
|
+
const fnMatch = fnRe.exec(ownerText);
|
|
992
|
+
if (fnMatch) {
|
|
993
|
+
const paramType = fnMatch[1].trim();
|
|
994
|
+
if (paramType.startsWith("{")) {
|
|
995
|
+
const fields = [];
|
|
996
|
+
for (const f of paramType
|
|
997
|
+
.slice(1, -1)
|
|
998
|
+
.matchAll(/([A-Za-z_$][\w$]*)\s*:\s*([^,\n}]+)/g)) {
|
|
999
|
+
fields.push({ name: f[1], type: f[2].trim() });
|
|
1000
|
+
}
|
|
1001
|
+
return fields;
|
|
1002
|
+
}
|
|
1003
|
+
const schemaFields = collectSchemaMembersFromText(ownerText, ownerUri, paramType);
|
|
1004
|
+
if (schemaFields.length > 0) {
|
|
1005
|
+
return schemaFields.map((f) => ({ name: f.name, type: f.detail }));
|
|
1006
|
+
}
|
|
1007
|
+
const ownerImports = collectImportedSymbols(ownerText, ownerUri, documents);
|
|
1008
|
+
const importedSchema = ownerImports.get(paramType);
|
|
1009
|
+
if (importedSchema) {
|
|
1010
|
+
return collectSchemaMembersFromText(importedSchema.doc.text, importedSchema.doc.uri, importedSchema.exportedName).map((f) => ({ name: f.name, type: f.detail }));
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
return [];
|
|
1014
|
+
}
|
|
1015
|
+
function collectPascalCaseComponents(priorSource, source, uri, documents) {
|
|
1016
|
+
const components = new Set();
|
|
1017
|
+
const nonComponentDecls = new Set();
|
|
1018
|
+
for (const found of source.matchAll(/\b(?:export\s+)?(?:schema|error|service)\s+([A-Z][\w$]*)/g)) {
|
|
1019
|
+
nonComponentDecls.add(found[1]);
|
|
1020
|
+
}
|
|
1021
|
+
for (const found of priorSource.matchAll(/^\s*(?:export\s+)?(?:mut\s+)?([A-Z][\w$]*)\s*(?:=|:)/gm)) {
|
|
1022
|
+
if (!nonComponentDecls.has(found[1])) {
|
|
1023
|
+
components.add(found[1]);
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
for (const [localName, info] of collectImportedSymbols(source, uri, documents)) {
|
|
1027
|
+
if (!/^[A-Z]/.test(localName))
|
|
1028
|
+
continue;
|
|
1029
|
+
const isNonComponent = new RegExp(`\\bexport\\s+(?:schema|error|service)\\s+${escapeRegExp(info.exportedName)}\\b`).test(info.doc.text);
|
|
1030
|
+
if (!isNonComponent) {
|
|
1031
|
+
components.add(localName);
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
for (const [nsName] of collectNamespaceImports(source, uri, documents)) {
|
|
1035
|
+
if (/^[A-Z]/.test(nsName)) {
|
|
1036
|
+
components.add(nsName);
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
return components;
|
|
1040
|
+
}
|
|
1041
|
+
function makeItemAdder(prefix, range, items, exclude) {
|
|
1042
|
+
return (label, kind, detail, documentation, sortPrefix = "") => {
|
|
1043
|
+
if (prefix && !label.toLowerCase().startsWith(prefix.toLowerCase()))
|
|
1044
|
+
return;
|
|
1045
|
+
if (exclude && label === exclude)
|
|
1046
|
+
return;
|
|
1047
|
+
items.set(label, {
|
|
1048
|
+
label,
|
|
1049
|
+
kind,
|
|
1050
|
+
detail,
|
|
1051
|
+
...(documentation ? { documentation } : {}),
|
|
1052
|
+
textEdit: { range, newText: label },
|
|
1053
|
+
sortText: `${sortPrefix}${label.toLowerCase()}`,
|
|
1054
|
+
});
|
|
1055
|
+
};
|
|
1056
|
+
}
|
|
1057
|
+
function sortCompletionItems(items) {
|
|
1058
|
+
return [...items.values()].sort((a, b) => String(a.sortText).localeCompare(String(b.sortText)) ||
|
|
1059
|
+
a.label.localeCompare(b.label));
|
|
1060
|
+
}
|
|
56
1061
|
/** Builds completion candidates from the current open workspace snapshot. */
|
|
57
1062
|
export function complete(source, uri, position, documents, pipelineAnalysis) {
|
|
1063
|
+
const isFunx = uri.endsWith(".funx");
|
|
58
1064
|
const lines = source.split("\n");
|
|
59
1065
|
const line = lines[position.line] ?? "";
|
|
60
1066
|
const before = line.slice(0, position.character);
|
|
61
1067
|
const priorSource = lines.slice(0, position.line).join("\n") +
|
|
62
1068
|
(position.line > 0 ? "\n" : "") +
|
|
63
1069
|
before;
|
|
1070
|
+
const sourceUpToCursor = lines
|
|
1071
|
+
.slice(0, position.line)
|
|
1072
|
+
.concat(before)
|
|
1073
|
+
.join("\n");
|
|
1074
|
+
const jsxCtx = isFunx
|
|
1075
|
+
? detectJsxContext(sourceUpToCursor)
|
|
1076
|
+
: { kind: "normal" };
|
|
1077
|
+
if (isFunx && jsxCtx.kind === "non-jsx") {
|
|
1078
|
+
return [];
|
|
1079
|
+
}
|
|
1080
|
+
if (isFunx && jsxCtx.kind === "jsx-open-tag") {
|
|
1081
|
+
const items = new Map();
|
|
1082
|
+
const range = {
|
|
1083
|
+
start: {
|
|
1084
|
+
line: position.line,
|
|
1085
|
+
character: position.character - jsxCtx.prefix.length,
|
|
1086
|
+
},
|
|
1087
|
+
end: position,
|
|
1088
|
+
};
|
|
1089
|
+
const add = makeItemAdder(jsxCtx.prefix, range, items);
|
|
1090
|
+
for (const comp of collectPascalCaseComponents(priorSource, source, uri, documents)) {
|
|
1091
|
+
add(comp, CompletionItemKind.Function, "JSX component", undefined, "0-");
|
|
1092
|
+
}
|
|
1093
|
+
for (const tag of INTRINSIC_JSX_TAGS) {
|
|
1094
|
+
add(tag, CompletionItemKind.Property, "JSX element", undefined, "1-");
|
|
1095
|
+
}
|
|
1096
|
+
return sortCompletionItems(items);
|
|
1097
|
+
}
|
|
1098
|
+
if (isFunx && jsxCtx.kind === "jsx-close-tag") {
|
|
1099
|
+
const items = new Map();
|
|
1100
|
+
const range = {
|
|
1101
|
+
start: {
|
|
1102
|
+
line: position.line,
|
|
1103
|
+
character: position.character - jsxCtx.prefix.length,
|
|
1104
|
+
},
|
|
1105
|
+
end: position,
|
|
1106
|
+
};
|
|
1107
|
+
const add = makeItemAdder(jsxCtx.prefix, range, items);
|
|
1108
|
+
if (jsxCtx.expectedTag) {
|
|
1109
|
+
add(jsxCtx.expectedTag, CompletionItemKind.Property, "Closing JSX tag");
|
|
1110
|
+
}
|
|
1111
|
+
return [...items.values()];
|
|
1112
|
+
}
|
|
1113
|
+
if (isFunx && jsxCtx.kind === "jsx-attribute") {
|
|
1114
|
+
const items = new Map();
|
|
1115
|
+
const range = {
|
|
1116
|
+
start: {
|
|
1117
|
+
line: position.line,
|
|
1118
|
+
character: position.character - jsxCtx.prefix.length,
|
|
1119
|
+
},
|
|
1120
|
+
end: position,
|
|
1121
|
+
};
|
|
1122
|
+
const add = makeItemAdder(jsxCtx.prefix, range, items);
|
|
1123
|
+
for (const prop of collectComponentProps(source, uri, jsxCtx.tagName, documents)) {
|
|
1124
|
+
if (jsxCtx.usedAttrs.has(prop.name))
|
|
1125
|
+
continue;
|
|
1126
|
+
add(prop.name, CompletionItemKind.Property, prop.type, `${jsxCtx.tagName} prop`, "0-");
|
|
1127
|
+
}
|
|
1128
|
+
for (const common of COMMON_JSX_PROPS) {
|
|
1129
|
+
if (jsxCtx.usedAttrs.has(common) || items.has(common))
|
|
1130
|
+
continue;
|
|
1131
|
+
add(common, CompletionItemKind.Property, "JSX attribute", undefined, "1-");
|
|
1132
|
+
}
|
|
1133
|
+
return sortCompletionItems(items);
|
|
1134
|
+
}
|
|
1135
|
+
const isJsxMemberTag = isFunx && jsxCtx.kind === "jsx-member-tag";
|
|
64
1136
|
const match = before.match(/[\w$.-]*$/);
|
|
65
1137
|
const typedPrefix = match?.[0] ?? "";
|
|
66
|
-
const
|
|
67
|
-
const
|
|
68
|
-
|
|
1138
|
+
const deferredPipelineContext = !isJsxMemberTag && /\|>>\s*(?:[\w.]*)$/.test(before);
|
|
1139
|
+
const pipelineContext = !isJsxMemberTag &&
|
|
1140
|
+
!deferredPipelineContext &&
|
|
1141
|
+
/\|>\s*(?:[\w.]*)$/.test(before);
|
|
1142
|
+
const member = isJsxMemberTag
|
|
1143
|
+
? jsxCtx.objectName
|
|
1144
|
+
: !deferredPipelineContext && !pipelineContext
|
|
1145
|
+
? /([A-Za-z_$][\w$]*)\.$/.exec(before)?.[1]
|
|
1146
|
+
: undefined;
|
|
1147
|
+
const prefix = isJsxMemberTag ? jsxCtx.prefix : member ? "" : typedPrefix;
|
|
1148
|
+
const start = position.character - prefix.length;
|
|
69
1149
|
const range = {
|
|
70
1150
|
start: { line: position.line, character: start },
|
|
71
1151
|
end: position,
|
|
72
1152
|
};
|
|
73
1153
|
const items = new Map();
|
|
74
|
-
const add = (
|
|
75
|
-
if (prefix && !label.toLowerCase().startsWith(prefix.toLowerCase()))
|
|
76
|
-
return;
|
|
77
|
-
if (label === member)
|
|
78
|
-
return;
|
|
79
|
-
items.set(label, {
|
|
80
|
-
label,
|
|
81
|
-
kind,
|
|
82
|
-
detail,
|
|
83
|
-
...(documentation ? { documentation } : {}),
|
|
84
|
-
textEdit: { range, newText: label },
|
|
85
|
-
sortText: label.toLowerCase(),
|
|
86
|
-
});
|
|
87
|
-
};
|
|
1154
|
+
const add = makeItemAdder(prefix, range, items, member);
|
|
88
1155
|
if (member) {
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
1156
|
+
for (const item of collectSchemaMembersFromText(source, uri, member)) {
|
|
1157
|
+
add(item.name, item.kind, item.detail);
|
|
1158
|
+
}
|
|
1159
|
+
for (const svcMethod of collectServiceMembersFromText(source, uri, member)) {
|
|
1160
|
+
add(svcMethod.name, CompletionItemKind.Method, svcMethod.detail, `${member}.${svcMethod.name}`);
|
|
1161
|
+
}
|
|
1162
|
+
for (const recField of collectRecordBindingMembersFromText(source, uri, member)) {
|
|
1163
|
+
add(recField.name, recField.kind, recField.detail);
|
|
1164
|
+
}
|
|
1165
|
+
const importedTarget = collectImportedSymbols(source, uri, documents).get(member);
|
|
1166
|
+
if (importedTarget) {
|
|
1167
|
+
for (const svcMethod of collectServiceMembersFromText(importedTarget.doc.text, importedTarget.doc.uri, importedTarget.exportedName)) {
|
|
1168
|
+
add(svcMethod.name, CompletionItemKind.Method, svcMethod.detail, `${member}.${svcMethod.name} (from ${importedTarget.modulePath})`);
|
|
1169
|
+
}
|
|
1170
|
+
for (const item of collectSchemaMembersFromText(importedTarget.doc.text, importedTarget.doc.uri, importedTarget.exportedName)) {
|
|
1171
|
+
add(item.name, item.kind, item.detail);
|
|
1172
|
+
}
|
|
1173
|
+
for (const recField of collectRecordBindingMembersFromText(importedTarget.doc.text, importedTarget.doc.uri, importedTarget.exportedName)) {
|
|
1174
|
+
add(recField.name, recField.kind, recField.detail, `${member}.${recField.name} (from ${importedTarget.modulePath})`);
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
const namespaceTarget = collectNamespaceImports(source, uri, documents).get(member);
|
|
1178
|
+
if (namespaceTarget) {
|
|
1179
|
+
for (const exp of collectExportedSymbolsFromText(namespaceTarget.doc.text, namespaceTarget.doc.uri)) {
|
|
1180
|
+
add(exp.name, exp.kind, exp.detail, `${member}.${exp.name} (from ${namespaceTarget.modulePath})`);
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
if (member === "Effect") {
|
|
99
1184
|
for (const key of getAllDocKeywords().filter((key) => key.startsWith("Effect."))) {
|
|
100
1185
|
const doc = DOC_CATALOG[key];
|
|
101
1186
|
add(key.slice(7), CompletionItemKind.Function, doc.signature, doc.summary);
|
|
102
1187
|
}
|
|
1188
|
+
}
|
|
103
1189
|
}
|
|
104
1190
|
else {
|
|
105
1191
|
const visible = new Set();
|
|
@@ -124,9 +1210,6 @@ export function complete(source, uri, position, documents, pipelineAnalysis) {
|
|
|
124
1210
|
}
|
|
125
1211
|
}
|
|
126
1212
|
}
|
|
127
|
-
const deferredPipelineContext = /\|>>\s*(?:[\w.]*)$/.test(before);
|
|
128
|
-
const pipelineContext = !deferredPipelineContext && /\|>\s*(?:[\w.]*)$/.test(before);
|
|
129
|
-
const jsxContext = /<\s*[A-Za-z_$\w]*$/.test(before);
|
|
130
1213
|
if (!deferredPipelineContext) {
|
|
131
1214
|
for (const name of visible)
|
|
132
1215
|
add(name, CompletionItemKind.Variable, "Workspace symbol");
|
|
@@ -234,27 +1317,7 @@ export function complete(source, uri, position, documents, pipelineAnalysis) {
|
|
|
234
1317
|
}
|
|
235
1318
|
}
|
|
236
1319
|
}
|
|
237
|
-
if (/\.funx?$/.test(uri) && jsxContext)
|
|
238
|
-
for (const tag of [
|
|
239
|
-
"div",
|
|
240
|
-
"span",
|
|
241
|
-
"button",
|
|
242
|
-
"input",
|
|
243
|
-
"form",
|
|
244
|
-
"main",
|
|
245
|
-
"section",
|
|
246
|
-
"header",
|
|
247
|
-
"footer",
|
|
248
|
-
"ul",
|
|
249
|
-
"li",
|
|
250
|
-
"a",
|
|
251
|
-
"p",
|
|
252
|
-
"h1",
|
|
253
|
-
"h2",
|
|
254
|
-
])
|
|
255
|
-
add(tag, CompletionItemKind.Property, "JSX element");
|
|
256
1320
|
}
|
|
257
|
-
return
|
|
258
|
-
a.label.localeCompare(b.label));
|
|
1321
|
+
return sortCompletionItems(items);
|
|
259
1322
|
}
|
|
260
1323
|
//# sourceMappingURL=completion.js.map
|