@soda-gql/lsp 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +73 -0
- package/dist/bin.cjs +13 -0
- package/dist/bin.cjs.map +1 -0
- package/dist/bin.d.cts +1 -0
- package/dist/bin.d.mts +1 -0
- package/dist/bin.mjs +14 -0
- package/dist/bin.mjs.map +1 -0
- package/dist/index.cjs +8 -0
- package/dist/index.d.cts +254 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +254 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +3 -0
- package/dist/server-0Mbk3BXO.cjs +4408 -0
- package/dist/server-0Mbk3BXO.cjs.map +1 -0
- package/dist/server-BgXl3W41.mjs +4345 -0
- package/dist/server-BgXl3W41.mjs.map +1 -0
- package/index.d.ts +2 -0
- package/index.js +1 -0
- package/package.json +71 -0
|
@@ -0,0 +1,4345 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
3
|
+
import { createSwcSpanConverter } from "@soda-gql/common";
|
|
4
|
+
import { TypeInfo, buildASTSchema, concatAST, getNamedType, isTypeDefinitionNode, parse, print, visit, visitWithTypeInfo } from "graphql";
|
|
5
|
+
import { readFileSync } from "node:fs";
|
|
6
|
+
import { dirname, resolve, sep } from "node:path";
|
|
7
|
+
import { hashSchema } from "@soda-gql/codegen";
|
|
8
|
+
import { err, ok } from "neverthrow";
|
|
9
|
+
import { findAllConfigFiles, findConfigFile, loadConfig } from "@soda-gql/config";
|
|
10
|
+
import { DidChangeWatchedFilesNotification, FileChangeType, ProposedFeatures, TextDocumentSyncKind, TextDocuments, createConnection } from "vscode-languageserver/node";
|
|
11
|
+
import { TextDocument } from "vscode-languageserver-textdocument";
|
|
12
|
+
import { createGraphqlSystemIdentifyHelper } from "@soda-gql/builder";
|
|
13
|
+
import ts from "typescript";
|
|
14
|
+
import { getAutocompleteSuggestions, getContextAtPosition, getDefinitionQueryResultForField, getDefinitionQueryResultForFragmentSpread, getDiagnostics, getHoverInformation, getOutline } from "graphql-language-service";
|
|
15
|
+
|
|
16
|
+
//#region packages/lsp/src/fragment-args-preprocessor.ts
|
|
17
|
+
/**
|
|
18
|
+
* Find the matching closing parenthesis for a balanced group.
|
|
19
|
+
* Handles nested parentheses, string literals, and comments.
|
|
20
|
+
* Returns the index of the closing ')' or -1 if not found.
|
|
21
|
+
*/
|
|
22
|
+
const findMatchingParen = (content, openIndex) => {
|
|
23
|
+
let depth = 1;
|
|
24
|
+
let inString = false;
|
|
25
|
+
for (let i = openIndex + 1; i < content.length; i++) {
|
|
26
|
+
const ch = content[i];
|
|
27
|
+
if (ch === undefined) break;
|
|
28
|
+
if (inString) {
|
|
29
|
+
if (ch === inString) {
|
|
30
|
+
let backslashes = 0;
|
|
31
|
+
for (let j = i - 1; j >= 0 && content[j] === "\\"; j--) {
|
|
32
|
+
backslashes++;
|
|
33
|
+
}
|
|
34
|
+
if (backslashes % 2 === 0) {
|
|
35
|
+
inString = false;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
if (ch === "\"" || ch === "'") {
|
|
41
|
+
inString = ch;
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
if (ch === "(") {
|
|
45
|
+
depth++;
|
|
46
|
+
} else if (ch === ")") {
|
|
47
|
+
depth--;
|
|
48
|
+
if (depth === 0) {
|
|
49
|
+
return i;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return -1;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Replace a range [start, end] (inclusive) with spaces, preserving newlines.
|
|
57
|
+
*/
|
|
58
|
+
const replaceWithSpaces = (content, start, end) => {
|
|
59
|
+
let result = content.slice(0, start);
|
|
60
|
+
for (let i = start; i <= end; i++) {
|
|
61
|
+
result += content[i] === "\n" ? "\n" : " ";
|
|
62
|
+
}
|
|
63
|
+
result += content.slice(end + 1);
|
|
64
|
+
return result;
|
|
65
|
+
};
|
|
66
|
+
const FRAGMENT_DEF_PATTERN = /\bfragment\s+(\w+)\s*\(/g;
|
|
67
|
+
const FRAGMENT_DEF_CURRIED_PATTERN = /\bfragment\s+\w+\s+on\s+\w+\s*\(/g;
|
|
68
|
+
const FRAGMENT_SPREAD_PATTERN = /\.\.\.(\w+)\s*\(/g;
|
|
69
|
+
/**
|
|
70
|
+
* Preprocess Fragment Arguments RFC syntax by replacing argument lists with spaces.
|
|
71
|
+
*
|
|
72
|
+
* Transforms:
|
|
73
|
+
* - `fragment UserProfile($showEmail: Boolean = false) on User` → `fragment UserProfile on User`
|
|
74
|
+
* - `...UserProfile(showEmail: true)` → `...UserProfile `
|
|
75
|
+
*/
|
|
76
|
+
const preprocessFragmentArgs = (content) => {
|
|
77
|
+
let result = content;
|
|
78
|
+
let modified = false;
|
|
79
|
+
let match;
|
|
80
|
+
FRAGMENT_DEF_PATTERN.lastIndex = 0;
|
|
81
|
+
while ((match = FRAGMENT_DEF_PATTERN.exec(result)) !== null) {
|
|
82
|
+
const openParenIndex = match.index + match[0].length - 1;
|
|
83
|
+
const closeParenIndex = findMatchingParen(result, openParenIndex);
|
|
84
|
+
if (closeParenIndex === -1) {
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
const afterParen = result.slice(closeParenIndex + 1).trimStart();
|
|
88
|
+
if (!afterParen.startsWith("on")) {
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
result = replaceWithSpaces(result, openParenIndex, closeParenIndex);
|
|
92
|
+
modified = true;
|
|
93
|
+
FRAGMENT_DEF_PATTERN.lastIndex = 0;
|
|
94
|
+
}
|
|
95
|
+
FRAGMENT_DEF_CURRIED_PATTERN.lastIndex = 0;
|
|
96
|
+
while ((match = FRAGMENT_DEF_CURRIED_PATTERN.exec(result)) !== null) {
|
|
97
|
+
const openParenIndex = match.index + match[0].length - 1;
|
|
98
|
+
const closeParenIndex = findMatchingParen(result, openParenIndex);
|
|
99
|
+
if (closeParenIndex === -1) {
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
const afterParen = result.slice(closeParenIndex + 1).trimStart();
|
|
103
|
+
if (!afterParen.startsWith("{")) {
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
result = replaceWithSpaces(result, openParenIndex, closeParenIndex);
|
|
107
|
+
modified = true;
|
|
108
|
+
FRAGMENT_DEF_CURRIED_PATTERN.lastIndex = 0;
|
|
109
|
+
}
|
|
110
|
+
FRAGMENT_SPREAD_PATTERN.lastIndex = 0;
|
|
111
|
+
while ((match = FRAGMENT_SPREAD_PATTERN.exec(result)) !== null) {
|
|
112
|
+
const openParenIndex = match.index + match[0].length - 1;
|
|
113
|
+
const closeParenIndex = findMatchingParen(result, openParenIndex);
|
|
114
|
+
if (closeParenIndex === -1) {
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
result = replaceWithSpaces(result, openParenIndex, closeParenIndex);
|
|
118
|
+
modified = true;
|
|
119
|
+
FRAGMENT_SPREAD_PATTERN.lastIndex = 0;
|
|
120
|
+
}
|
|
121
|
+
return {
|
|
122
|
+
preprocessed: result,
|
|
123
|
+
modified
|
|
124
|
+
};
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
//#endregion
|
|
128
|
+
//#region packages/lsp/src/document-manager.ts
|
|
129
|
+
/**
|
|
130
|
+
* Document manager: tracks open documents and extracts tagged templates using SWC.
|
|
131
|
+
* @module
|
|
132
|
+
*/
|
|
133
|
+
const OPERATION_KINDS = new Set([
|
|
134
|
+
"query",
|
|
135
|
+
"mutation",
|
|
136
|
+
"subscription",
|
|
137
|
+
"fragment"
|
|
138
|
+
]);
|
|
139
|
+
const isOperationKind = (value) => OPERATION_KINDS.has(value);
|
|
140
|
+
/**
|
|
141
|
+
* Collect gql identifiers from import declarations.
|
|
142
|
+
* Adapted from builder's collectGqlIdentifiers pattern.
|
|
143
|
+
*/
|
|
144
|
+
const collectGqlIdentifiers = (module, filePath, helper) => {
|
|
145
|
+
const identifiers = new Set();
|
|
146
|
+
for (const item of module.body) {
|
|
147
|
+
let declaration = null;
|
|
148
|
+
if (item.type === "ImportDeclaration") {
|
|
149
|
+
declaration = item;
|
|
150
|
+
} else if ("declaration" in item && item.declaration && item.declaration.type === "ImportDeclaration") {
|
|
151
|
+
declaration = item.declaration;
|
|
152
|
+
}
|
|
153
|
+
if (!declaration) {
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
if (!helper.isGraphqlSystemImportSpecifier({
|
|
157
|
+
filePath,
|
|
158
|
+
specifier: declaration.source.value
|
|
159
|
+
})) {
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
for (const specifier of declaration.specifiers ?? []) {
|
|
163
|
+
if (specifier.type === "ImportSpecifier") {
|
|
164
|
+
const imported = specifier.imported ? specifier.imported.value : specifier.local.value;
|
|
165
|
+
if (imported === "gql" && !specifier.imported) {
|
|
166
|
+
identifiers.add(specifier.local.value);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return identifiers;
|
|
172
|
+
};
|
|
173
|
+
/**
|
|
174
|
+
* Check if a call expression is a gql.{schemaName}(...) call.
|
|
175
|
+
* Returns the schema name if it is, null otherwise.
|
|
176
|
+
*/
|
|
177
|
+
const getGqlCallSchemaName = (identifiers, call) => {
|
|
178
|
+
const callee = call.callee;
|
|
179
|
+
if (callee.type !== "MemberExpression") {
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
const member = callee;
|
|
183
|
+
if (member.object.type !== "Identifier" || !identifiers.has(member.object.value)) {
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
if (member.property.type !== "Identifier") {
|
|
187
|
+
return null;
|
|
188
|
+
}
|
|
189
|
+
const firstArg = call.arguments[0];
|
|
190
|
+
if (!firstArg?.expression || firstArg.expression.type !== "ArrowFunctionExpression") {
|
|
191
|
+
return null;
|
|
192
|
+
}
|
|
193
|
+
return member.property.value;
|
|
194
|
+
};
|
|
195
|
+
/**
|
|
196
|
+
* Extract templates from a gql callback's arrow function body.
|
|
197
|
+
* Handles both expression bodies and block bodies with return statements.
|
|
198
|
+
*/
|
|
199
|
+
const extractTemplatesFromCallback = (arrow, schemaName, spanOffset, converter) => {
|
|
200
|
+
const templates = [];
|
|
201
|
+
const processExpression = (expr) => {
|
|
202
|
+
if (expr.type === "TaggedTemplateExpression") {
|
|
203
|
+
const tagged = expr;
|
|
204
|
+
extractFromTaggedTemplate(tagged, schemaName, spanOffset, converter, templates);
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
if (expr.type === "CallExpression") {
|
|
208
|
+
const call = expr;
|
|
209
|
+
if (call.callee.type === "TaggedTemplateExpression") {
|
|
210
|
+
extractFromTaggedTemplate(call.callee, schemaName, spanOffset, converter, templates);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
if (arrow.body.type !== "BlockStatement") {
|
|
215
|
+
processExpression(arrow.body);
|
|
216
|
+
return templates;
|
|
217
|
+
}
|
|
218
|
+
for (const stmt of arrow.body.stmts) {
|
|
219
|
+
if (stmt.type === "ReturnStatement" && stmt.argument) {
|
|
220
|
+
processExpression(stmt.argument);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
return templates;
|
|
224
|
+
};
|
|
225
|
+
const extractFromTaggedTemplate = (tagged, schemaName, spanOffset, converter, templates) => {
|
|
226
|
+
if (tagged.tag.type !== "CallExpression") {
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
const tagCall = tagged.tag;
|
|
230
|
+
if (tagCall.callee.type !== "Identifier") {
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
const kind = tagCall.callee.value;
|
|
234
|
+
if (!isOperationKind(kind)) {
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
let elementName;
|
|
238
|
+
let typeName;
|
|
239
|
+
const firstArg = tagCall.arguments[0]?.expression;
|
|
240
|
+
if (firstArg?.type === "StringLiteral") {
|
|
241
|
+
elementName = firstArg.value;
|
|
242
|
+
}
|
|
243
|
+
const secondArg = tagCall.arguments[1]?.expression;
|
|
244
|
+
if (secondArg?.type === "StringLiteral") {
|
|
245
|
+
typeName = secondArg.value;
|
|
246
|
+
}
|
|
247
|
+
const { quasis, expressions } = tagged.template;
|
|
248
|
+
if (quasis.length === 0) {
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
const parts = [];
|
|
252
|
+
let contentStart = -1;
|
|
253
|
+
let contentEnd = -1;
|
|
254
|
+
for (let i = 0; i < quasis.length; i++) {
|
|
255
|
+
const quasi = quasis[i];
|
|
256
|
+
if (!quasi) {
|
|
257
|
+
continue;
|
|
258
|
+
}
|
|
259
|
+
const quasiStart = converter.byteOffsetToCharIndex(quasi.span.start - spanOffset);
|
|
260
|
+
const quasiEnd = converter.byteOffsetToCharIndex(quasi.span.end - spanOffset);
|
|
261
|
+
if (contentStart === -1) {
|
|
262
|
+
contentStart = quasiStart;
|
|
263
|
+
}
|
|
264
|
+
contentEnd = quasiEnd;
|
|
265
|
+
const quasiContent = quasi.cooked ?? quasi.raw;
|
|
266
|
+
parts.push(quasiContent);
|
|
267
|
+
if (i < expressions.length) {
|
|
268
|
+
parts.push(`__FRAG_SPREAD_${i}__`);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
if (contentStart === -1 || contentEnd === -1) {
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
const content = parts.join("");
|
|
275
|
+
templates.push({
|
|
276
|
+
contentRange: {
|
|
277
|
+
start: contentStart,
|
|
278
|
+
end: contentEnd
|
|
279
|
+
},
|
|
280
|
+
schemaName,
|
|
281
|
+
kind,
|
|
282
|
+
content,
|
|
283
|
+
...elementName !== undefined ? { elementName } : {},
|
|
284
|
+
...typeName !== undefined ? { typeName } : {}
|
|
285
|
+
});
|
|
286
|
+
};
|
|
287
|
+
/**
|
|
288
|
+
* Walk AST to find gql calls and extract templates.
|
|
289
|
+
* Adapted from builder's unwrapMethodChains + visit pattern.
|
|
290
|
+
*/
|
|
291
|
+
const walkAndExtract = (node, identifiers, spanOffset, converter) => {
|
|
292
|
+
const templates = [];
|
|
293
|
+
const visit$1 = (n) => {
|
|
294
|
+
if (!n || typeof n !== "object") {
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
if ("type" in n && n.type === "CallExpression") {
|
|
298
|
+
const gqlCall = findGqlCall(identifiers, n);
|
|
299
|
+
if (gqlCall) {
|
|
300
|
+
const schemaName = getGqlCallSchemaName(identifiers, gqlCall);
|
|
301
|
+
if (schemaName) {
|
|
302
|
+
const arrow = gqlCall.arguments[0]?.expression;
|
|
303
|
+
templates.push(...extractTemplatesFromCallback(arrow, schemaName, spanOffset, converter));
|
|
304
|
+
}
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
if (Array.isArray(n)) {
|
|
309
|
+
for (const item of n) {
|
|
310
|
+
visit$1(item);
|
|
311
|
+
}
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
for (const key of Object.keys(n)) {
|
|
315
|
+
if (key === "span" || key === "type") {
|
|
316
|
+
continue;
|
|
317
|
+
}
|
|
318
|
+
const value = n[key];
|
|
319
|
+
if (value && typeof value === "object") {
|
|
320
|
+
visit$1(value);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
};
|
|
324
|
+
visit$1(node);
|
|
325
|
+
return templates;
|
|
326
|
+
};
|
|
327
|
+
/**
|
|
328
|
+
* Find the innermost gql call, unwrapping method chains like .attach().
|
|
329
|
+
*/
|
|
330
|
+
const findGqlCall = (identifiers, node) => {
|
|
331
|
+
if (!node || node.type !== "CallExpression") {
|
|
332
|
+
return null;
|
|
333
|
+
}
|
|
334
|
+
const call = node;
|
|
335
|
+
if (getGqlCallSchemaName(identifiers, call) !== null) {
|
|
336
|
+
return call;
|
|
337
|
+
}
|
|
338
|
+
const callee = call.callee;
|
|
339
|
+
if (callee.type !== "MemberExpression") {
|
|
340
|
+
return null;
|
|
341
|
+
}
|
|
342
|
+
return findGqlCall(identifiers, callee.object);
|
|
343
|
+
};
|
|
344
|
+
/**
|
|
345
|
+
* Index fragment definitions from extracted templates.
|
|
346
|
+
* Parses each fragment template to extract FragmentDefinitionNode for cross-file resolution.
|
|
347
|
+
*/
|
|
348
|
+
/**
|
|
349
|
+
* Reconstruct full GraphQL source from an extracted template.
|
|
350
|
+
* Prepends the definition header from curried tag call arguments.
|
|
351
|
+
*/
|
|
352
|
+
const reconstructGraphql = (template) => {
|
|
353
|
+
const content = template.content;
|
|
354
|
+
if (template.elementName) {
|
|
355
|
+
if (template.kind === "fragment" && template.typeName) {
|
|
356
|
+
return `fragment ${template.elementName} on ${template.typeName} ${content}`;
|
|
357
|
+
}
|
|
358
|
+
return `${template.kind} ${template.elementName} ${content}`;
|
|
359
|
+
}
|
|
360
|
+
return content;
|
|
361
|
+
};
|
|
362
|
+
const indexFragments = (uri, templates, source) => {
|
|
363
|
+
const fragments = [];
|
|
364
|
+
for (const template of templates) {
|
|
365
|
+
if (template.kind !== "fragment") {
|
|
366
|
+
continue;
|
|
367
|
+
}
|
|
368
|
+
const reconstructed = reconstructGraphql(template);
|
|
369
|
+
const headerLen = reconstructed.length - template.content.length;
|
|
370
|
+
const { preprocessed } = preprocessFragmentArgs(reconstructed);
|
|
371
|
+
try {
|
|
372
|
+
const ast = parse(preprocessed, { noLocation: false });
|
|
373
|
+
for (const def of ast.definitions) {
|
|
374
|
+
if (def.kind === "FragmentDefinition") {
|
|
375
|
+
fragments.push({
|
|
376
|
+
uri,
|
|
377
|
+
schemaName: template.schemaName,
|
|
378
|
+
fragmentName: def.name.value,
|
|
379
|
+
definition: def,
|
|
380
|
+
content: preprocessed,
|
|
381
|
+
contentRange: template.contentRange,
|
|
382
|
+
tsSource: source,
|
|
383
|
+
headerLen
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
} catch {}
|
|
388
|
+
}
|
|
389
|
+
return fragments;
|
|
390
|
+
};
|
|
391
|
+
/** Create a document manager that tracks open documents and extracts templates. */
|
|
392
|
+
const createDocumentManager = (helper, swcOptions) => {
|
|
393
|
+
let parseSyncFn = swcOptions?.parseSync !== undefined ? swcOptions.parseSync ?? null : null;
|
|
394
|
+
let swcLoadAttempted = swcOptions?.parseSync !== undefined;
|
|
395
|
+
let swcUnavailable = swcOptions?.parseSync === null;
|
|
396
|
+
const getParseSync = () => {
|
|
397
|
+
if (!swcLoadAttempted) {
|
|
398
|
+
swcLoadAttempted = true;
|
|
399
|
+
const resolveBases = swcOptions?.resolveFrom ? [swcOptions.resolveFrom, import.meta.url] : [import.meta.url];
|
|
400
|
+
for (const base of resolveBases) {
|
|
401
|
+
try {
|
|
402
|
+
const localRequire = createRequire(base);
|
|
403
|
+
const candidate = localRequire("@swc/core")?.parseSync;
|
|
404
|
+
if (typeof candidate === "function") {
|
|
405
|
+
parseSyncFn = candidate;
|
|
406
|
+
return parseSyncFn;
|
|
407
|
+
}
|
|
408
|
+
} catch {}
|
|
409
|
+
}
|
|
410
|
+
swcUnavailable = true;
|
|
411
|
+
}
|
|
412
|
+
return parseSyncFn;
|
|
413
|
+
};
|
|
414
|
+
/** Wrap SWC parseSync (which throws) to return null on failure. */
|
|
415
|
+
const safeParseSync = (source, tsx) => {
|
|
416
|
+
const parseSync = getParseSync();
|
|
417
|
+
if (!parseSync) return null;
|
|
418
|
+
try {
|
|
419
|
+
const result = parseSync(source, {
|
|
420
|
+
syntax: "typescript",
|
|
421
|
+
tsx,
|
|
422
|
+
decorators: false,
|
|
423
|
+
dynamicImport: true
|
|
424
|
+
});
|
|
425
|
+
return result.type === "Module" ? result : null;
|
|
426
|
+
} catch {
|
|
427
|
+
return null;
|
|
428
|
+
}
|
|
429
|
+
};
|
|
430
|
+
const cache = new Map();
|
|
431
|
+
const fragmentIndex = new Map();
|
|
432
|
+
const extractTemplates = (uri, source) => {
|
|
433
|
+
const isTsx = uri.endsWith(".tsx");
|
|
434
|
+
const program = safeParseSync(source, isTsx);
|
|
435
|
+
if (!program) {
|
|
436
|
+
return [];
|
|
437
|
+
}
|
|
438
|
+
const converter = createSwcSpanConverter(source);
|
|
439
|
+
const spanOffset = program.span.end - converter.byteLength + 1;
|
|
440
|
+
const filePath = uri.startsWith("file://") ? fileURLToPath(uri) : uri;
|
|
441
|
+
const gqlIdentifiers = collectGqlIdentifiers(program, filePath, helper);
|
|
442
|
+
if (gqlIdentifiers.size === 0) {
|
|
443
|
+
return [];
|
|
444
|
+
}
|
|
445
|
+
return walkAndExtract(program, gqlIdentifiers, spanOffset, converter);
|
|
446
|
+
};
|
|
447
|
+
return {
|
|
448
|
+
update: (uri, version, source) => {
|
|
449
|
+
const templates = extractTemplates(uri, source);
|
|
450
|
+
const state = {
|
|
451
|
+
uri,
|
|
452
|
+
version,
|
|
453
|
+
source,
|
|
454
|
+
templates,
|
|
455
|
+
...swcUnavailable ? { swcUnavailable: true } : {}
|
|
456
|
+
};
|
|
457
|
+
cache.set(uri, state);
|
|
458
|
+
if (swcUnavailable) {
|
|
459
|
+
fragmentIndex.delete(uri);
|
|
460
|
+
} else {
|
|
461
|
+
fragmentIndex.set(uri, indexFragments(uri, templates, source));
|
|
462
|
+
}
|
|
463
|
+
return state;
|
|
464
|
+
},
|
|
465
|
+
get: (uri) => cache.get(uri),
|
|
466
|
+
remove: (uri) => {
|
|
467
|
+
cache.delete(uri);
|
|
468
|
+
fragmentIndex.delete(uri);
|
|
469
|
+
},
|
|
470
|
+
findTemplateAtOffset: (uri, offset) => {
|
|
471
|
+
const state = cache.get(uri);
|
|
472
|
+
if (!state) {
|
|
473
|
+
return undefined;
|
|
474
|
+
}
|
|
475
|
+
return state.templates.find((t) => offset >= t.contentRange.start && offset <= t.contentRange.end);
|
|
476
|
+
},
|
|
477
|
+
getExternalFragments: (uri, schemaName) => {
|
|
478
|
+
const result = [];
|
|
479
|
+
for (const [fragmentUri, fragments] of fragmentIndex) {
|
|
480
|
+
if (fragmentUri === uri) {
|
|
481
|
+
continue;
|
|
482
|
+
}
|
|
483
|
+
for (const fragment of fragments) {
|
|
484
|
+
if (fragment.schemaName === schemaName) {
|
|
485
|
+
result.push(fragment);
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
return result;
|
|
490
|
+
},
|
|
491
|
+
getAllFragments: (schemaName) => {
|
|
492
|
+
const result = [];
|
|
493
|
+
for (const [, fragments] of fragmentIndex) {
|
|
494
|
+
for (const fragment of fragments) {
|
|
495
|
+
if (fragment.schemaName === schemaName) {
|
|
496
|
+
result.push(fragment);
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
return result;
|
|
501
|
+
},
|
|
502
|
+
findFragmentSpreadLocations: (fragmentName, schemaName) => {
|
|
503
|
+
const locations = [];
|
|
504
|
+
for (const [uri, state] of cache) {
|
|
505
|
+
for (const template of state.templates) {
|
|
506
|
+
if (template.schemaName !== schemaName) {
|
|
507
|
+
continue;
|
|
508
|
+
}
|
|
509
|
+
const reconstructed = reconstructGraphql(template);
|
|
510
|
+
const headerLen = reconstructed.length - template.content.length;
|
|
511
|
+
const { preprocessed } = preprocessFragmentArgs(reconstructed);
|
|
512
|
+
try {
|
|
513
|
+
const ast = parse(preprocessed, { noLocation: false });
|
|
514
|
+
visit(ast, { FragmentSpread(node) {
|
|
515
|
+
if (node.name.value === fragmentName && node.name.loc) {
|
|
516
|
+
locations.push({
|
|
517
|
+
uri,
|
|
518
|
+
tsSource: state.source,
|
|
519
|
+
template,
|
|
520
|
+
nameOffset: node.name.loc.start - headerLen,
|
|
521
|
+
nameLength: fragmentName.length
|
|
522
|
+
});
|
|
523
|
+
}
|
|
524
|
+
} });
|
|
525
|
+
} catch {
|
|
526
|
+
const pattern = new RegExp(`\\.\\.\\.${fragmentName}\\b`, "g");
|
|
527
|
+
let match = null;
|
|
528
|
+
while ((match = pattern.exec(preprocessed)) !== null) {
|
|
529
|
+
locations.push({
|
|
530
|
+
uri,
|
|
531
|
+
tsSource: state.source,
|
|
532
|
+
template,
|
|
533
|
+
nameOffset: match.index + 3 - headerLen,
|
|
534
|
+
nameLength: fragmentName.length
|
|
535
|
+
});
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
return locations;
|
|
541
|
+
}
|
|
542
|
+
};
|
|
543
|
+
};
|
|
544
|
+
|
|
545
|
+
//#endregion
|
|
546
|
+
//#region packages/lsp/src/errors.ts
|
|
547
|
+
/** Error constructor helpers for concise error creation. */
|
|
548
|
+
const lspErrors = {
|
|
549
|
+
configLoadFailed: (message, cause) => ({
|
|
550
|
+
code: "CONFIG_LOAD_FAILED",
|
|
551
|
+
message,
|
|
552
|
+
cause
|
|
553
|
+
}),
|
|
554
|
+
schemaLoadFailed: (schemaName, message, cause) => ({
|
|
555
|
+
code: "SCHEMA_LOAD_FAILED",
|
|
556
|
+
message: message ?? `Failed to load schema: ${schemaName}`,
|
|
557
|
+
schemaName,
|
|
558
|
+
cause
|
|
559
|
+
}),
|
|
560
|
+
schemaBuildFailed: (schemaName, message, cause) => ({
|
|
561
|
+
code: "SCHEMA_BUILD_FAILED",
|
|
562
|
+
message: message ?? `Failed to build schema: ${schemaName}`,
|
|
563
|
+
schemaName,
|
|
564
|
+
cause
|
|
565
|
+
}),
|
|
566
|
+
schemaNotConfigured: (schemaName) => ({
|
|
567
|
+
code: "SCHEMA_NOT_CONFIGURED",
|
|
568
|
+
message: `Schema "${schemaName}" is not configured in soda-gql.config`,
|
|
569
|
+
schemaName
|
|
570
|
+
}),
|
|
571
|
+
parseFailed: (uri, message, cause) => ({
|
|
572
|
+
code: "PARSE_FAILED",
|
|
573
|
+
message: message ?? `Failed to parse: ${uri}`,
|
|
574
|
+
uri,
|
|
575
|
+
cause
|
|
576
|
+
}),
|
|
577
|
+
internalInvariant: (message, context, cause) => ({
|
|
578
|
+
code: "INTERNAL_INVARIANT",
|
|
579
|
+
message,
|
|
580
|
+
context,
|
|
581
|
+
cause
|
|
582
|
+
}),
|
|
583
|
+
swcResolutionFailed: (message) => ({
|
|
584
|
+
code: "SWC_RESOLUTION_FAILED",
|
|
585
|
+
message: message ?? "@swc/core not found. Install @soda-gql/builder (which provides @swc/core) in your project and restart the LSP server to enable template extraction."
|
|
586
|
+
})
|
|
587
|
+
};
|
|
588
|
+
|
|
589
|
+
//#endregion
|
|
590
|
+
//#region packages/lsp/src/position-mapping.ts
|
|
591
|
+
/** Compute byte offsets for the start of each line in the source text. */
|
|
592
|
+
const computeLineOffsets = (source) => {
|
|
593
|
+
const offsets = [0];
|
|
594
|
+
for (let i = 0; i < source.length; i++) {
|
|
595
|
+
if (source.charCodeAt(i) === 10) {
|
|
596
|
+
offsets.push(i + 1);
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
return offsets;
|
|
600
|
+
};
|
|
601
|
+
/** Convert a Position to a byte offset within the source text. */
|
|
602
|
+
const positionToOffset$1 = (lineOffsets, position) => {
|
|
603
|
+
if (position.line < 0 || position.line >= lineOffsets.length) {
|
|
604
|
+
return -1;
|
|
605
|
+
}
|
|
606
|
+
return (lineOffsets[position.line] ?? 0) + position.character;
|
|
607
|
+
};
|
|
608
|
+
/** Convert a byte offset to a Position within the source text. */
|
|
609
|
+
const offsetToPosition = (lineOffsets, offset) => {
|
|
610
|
+
let low = 0;
|
|
611
|
+
let high = lineOffsets.length - 1;
|
|
612
|
+
while (low < high) {
|
|
613
|
+
const mid = Math.ceil((low + high) / 2);
|
|
614
|
+
if ((lineOffsets[mid] ?? 0) <= offset) {
|
|
615
|
+
low = mid;
|
|
616
|
+
} else {
|
|
617
|
+
high = mid - 1;
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
return {
|
|
621
|
+
line: low,
|
|
622
|
+
character: offset - (lineOffsets[low] ?? 0)
|
|
623
|
+
};
|
|
624
|
+
};
|
|
625
|
+
/** Convert a Position to an IPosition compatible with graphql-language-service. */
|
|
626
|
+
const toIPosition = (pos) => {
|
|
627
|
+
const p = {
|
|
628
|
+
line: pos.line,
|
|
629
|
+
character: pos.character,
|
|
630
|
+
setLine: (l) => {
|
|
631
|
+
p.line = l;
|
|
632
|
+
},
|
|
633
|
+
setCharacter: (c) => {
|
|
634
|
+
p.character = c;
|
|
635
|
+
},
|
|
636
|
+
lessThanOrEqualTo: (other) => p.line < other.line || p.line === other.line && p.character <= other.character
|
|
637
|
+
};
|
|
638
|
+
return p;
|
|
639
|
+
};
|
|
640
|
+
/** Create a bidirectional position mapper between TS file and GraphQL content. */
|
|
641
|
+
const createPositionMapper = (input) => {
|
|
642
|
+
const { tsSource, contentStartOffset, graphqlContent } = input;
|
|
643
|
+
const tsLineOffsets = computeLineOffsets(tsSource);
|
|
644
|
+
const gqlLineOffsets = computeLineOffsets(graphqlContent);
|
|
645
|
+
return {
|
|
646
|
+
tsToGraphql: (tsPosition) => {
|
|
647
|
+
const tsOffset = positionToOffset$1(tsLineOffsets, tsPosition);
|
|
648
|
+
if (tsOffset < 0) {
|
|
649
|
+
return null;
|
|
650
|
+
}
|
|
651
|
+
const gqlOffset = tsOffset - contentStartOffset;
|
|
652
|
+
if (gqlOffset < 0 || gqlOffset > graphqlContent.length) {
|
|
653
|
+
return null;
|
|
654
|
+
}
|
|
655
|
+
return offsetToPosition(gqlLineOffsets, gqlOffset);
|
|
656
|
+
},
|
|
657
|
+
graphqlToTs: (gqlPosition) => {
|
|
658
|
+
const gqlOffset = positionToOffset$1(gqlLineOffsets, gqlPosition);
|
|
659
|
+
const tsOffset = gqlOffset + contentStartOffset;
|
|
660
|
+
return offsetToPosition(tsLineOffsets, tsOffset);
|
|
661
|
+
}
|
|
662
|
+
};
|
|
663
|
+
};
|
|
664
|
+
|
|
665
|
+
//#endregion
|
|
666
|
+
//#region packages/lsp/src/schema-resolver.ts
|
|
667
|
+
/**
|
|
668
|
+
* Schema resolver: maps schema names to GraphQLSchema objects.
|
|
669
|
+
* @module
|
|
670
|
+
*/
|
|
671
|
+
/** Wrap buildASTSchema (which throws) in a Result. */
|
|
672
|
+
const safeBuildASTSchema = (schemaName, documentNode) => {
|
|
673
|
+
try {
|
|
674
|
+
return ok(buildASTSchema(documentNode));
|
|
675
|
+
} catch (e) {
|
|
676
|
+
return err(lspErrors.schemaBuildFailed(schemaName, e instanceof Error ? e.message : String(e), e));
|
|
677
|
+
}
|
|
678
|
+
};
|
|
679
|
+
const loadAndBuildSchema = (schemaName, schemaPaths) => {
|
|
680
|
+
const documents = [];
|
|
681
|
+
const files = [];
|
|
682
|
+
for (const schemaPath of schemaPaths) {
|
|
683
|
+
const resolvedPath = resolve(schemaPath);
|
|
684
|
+
try {
|
|
685
|
+
const content = readFileSync(resolvedPath, "utf8");
|
|
686
|
+
documents.push(parse(content));
|
|
687
|
+
files.push({
|
|
688
|
+
filePath: resolvedPath,
|
|
689
|
+
content
|
|
690
|
+
});
|
|
691
|
+
} catch (e) {
|
|
692
|
+
return err(lspErrors.schemaLoadFailed(schemaName, e instanceof Error ? e.message : String(e)));
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
const documentNode = concatAST(documents);
|
|
696
|
+
const hash = hashSchema(documentNode);
|
|
697
|
+
const buildResult = safeBuildASTSchema(schemaName, documentNode);
|
|
698
|
+
if (buildResult.isErr()) {
|
|
699
|
+
return err(buildResult.error);
|
|
700
|
+
}
|
|
701
|
+
return ok({
|
|
702
|
+
name: schemaName,
|
|
703
|
+
schema: buildResult.value,
|
|
704
|
+
documentNode,
|
|
705
|
+
hash,
|
|
706
|
+
files
|
|
707
|
+
});
|
|
708
|
+
};
|
|
709
|
+
/** Create a schema resolver from config. Loads all schemas eagerly. */
|
|
710
|
+
const createSchemaResolver = (config) => {
|
|
711
|
+
const cache = new Map();
|
|
712
|
+
for (const [name, schemaConfig] of Object.entries(config.schemas)) {
|
|
713
|
+
const result = loadAndBuildSchema(name, schemaConfig.schema);
|
|
714
|
+
if (result.isErr()) {
|
|
715
|
+
return err(result.error);
|
|
716
|
+
}
|
|
717
|
+
cache.set(name, result.value);
|
|
718
|
+
}
|
|
719
|
+
const resolver = {
|
|
720
|
+
getSchema: (schemaName) => cache.get(schemaName),
|
|
721
|
+
getSchemaNames: () => [...cache.keys()],
|
|
722
|
+
reloadSchema: (schemaName) => {
|
|
723
|
+
const schemaConfig = config.schemas[schemaName];
|
|
724
|
+
if (!schemaConfig) {
|
|
725
|
+
return err(lspErrors.schemaNotConfigured(schemaName));
|
|
726
|
+
}
|
|
727
|
+
const result = loadAndBuildSchema(schemaName, schemaConfig.schema);
|
|
728
|
+
if (result.isErr()) {
|
|
729
|
+
return err(result.error);
|
|
730
|
+
}
|
|
731
|
+
cache.set(schemaName, result.value);
|
|
732
|
+
return ok(result.value);
|
|
733
|
+
},
|
|
734
|
+
reloadAll: () => {
|
|
735
|
+
const errors = [];
|
|
736
|
+
for (const [name, schemaConfig] of Object.entries(config.schemas)) {
|
|
737
|
+
const result = loadAndBuildSchema(name, schemaConfig.schema);
|
|
738
|
+
if (result.isErr()) {
|
|
739
|
+
errors.push(result.error);
|
|
740
|
+
} else {
|
|
741
|
+
cache.set(name, result.value);
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
return errors.length > 0 ? err(errors) : ok(undefined);
|
|
745
|
+
}
|
|
746
|
+
};
|
|
747
|
+
return ok(resolver);
|
|
748
|
+
};
|
|
749
|
+
|
|
750
|
+
//#endregion
|
|
751
|
+
//#region packages/lsp/src/config-registry.ts
|
|
752
|
+
/**
|
|
753
|
+
* Config registry: maps document URIs to their nearest config context.
|
|
754
|
+
* Supports multiple soda-gql configs in a monorepo workspace.
|
|
755
|
+
* @module
|
|
756
|
+
*/
|
|
757
|
+
const createConfigRegistry = (configPaths) => {
|
|
758
|
+
const sortedPaths = [...configPaths].sort((a, b) => b.length - a.length);
|
|
759
|
+
const contexts = new Map();
|
|
760
|
+
for (const configPath of sortedPaths) {
|
|
761
|
+
const configResult = loadConfig(configPath);
|
|
762
|
+
if (configResult.isErr()) {
|
|
763
|
+
return err(lspErrors.configLoadFailed(`Failed to load config ${configPath}: ${configResult.error.message}`, configResult.error));
|
|
764
|
+
}
|
|
765
|
+
const config = configResult.value;
|
|
766
|
+
const helper = createGraphqlSystemIdentifyHelper(config);
|
|
767
|
+
const resolverResult = createSchemaResolver(config);
|
|
768
|
+
if (resolverResult.isErr()) {
|
|
769
|
+
return err(resolverResult.error);
|
|
770
|
+
}
|
|
771
|
+
contexts.set(configPath, {
|
|
772
|
+
configPath,
|
|
773
|
+
config,
|
|
774
|
+
helper,
|
|
775
|
+
schemaResolver: resolverResult.value,
|
|
776
|
+
documentManager: createDocumentManager(helper, { resolveFrom: configPath })
|
|
777
|
+
});
|
|
778
|
+
}
|
|
779
|
+
const uriCache = new Map();
|
|
780
|
+
const resolveConfigPath = (dirPath) => {
|
|
781
|
+
const cached = uriCache.get(dirPath);
|
|
782
|
+
if (cached !== undefined) {
|
|
783
|
+
return cached;
|
|
784
|
+
}
|
|
785
|
+
for (const configPath of sortedPaths) {
|
|
786
|
+
const configDir = dirname(configPath);
|
|
787
|
+
if (dirPath === configDir || dirPath.startsWith(`${configDir}${sep}`)) {
|
|
788
|
+
uriCache.set(dirPath, configPath);
|
|
789
|
+
return configPath;
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
uriCache.set(dirPath, null);
|
|
793
|
+
return null;
|
|
794
|
+
};
|
|
795
|
+
return ok({
|
|
796
|
+
resolveForUri: (uri) => {
|
|
797
|
+
const filePath = uri.startsWith("file://") ? fileURLToPath(uri) : uri;
|
|
798
|
+
const dirPath = dirname(filePath);
|
|
799
|
+
const configPath = resolveConfigPath(dirPath);
|
|
800
|
+
return configPath ? contexts.get(configPath) : undefined;
|
|
801
|
+
},
|
|
802
|
+
getAllContexts: () => [...contexts.values()],
|
|
803
|
+
reloadSchemas: (configPath) => {
|
|
804
|
+
const ctx = contexts.get(configPath);
|
|
805
|
+
if (!ctx) {
|
|
806
|
+
return err([lspErrors.configLoadFailed(`Config not found: ${configPath}`)]);
|
|
807
|
+
}
|
|
808
|
+
return ctx.schemaResolver.reloadAll();
|
|
809
|
+
},
|
|
810
|
+
reloadAllSchemas: () => {
|
|
811
|
+
const errors = [];
|
|
812
|
+
for (const ctx of contexts.values()) {
|
|
813
|
+
const result = ctx.schemaResolver.reloadAll();
|
|
814
|
+
if (result.isErr()) {
|
|
815
|
+
errors.push(...result.error);
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
return errors.length > 0 ? err(errors) : ok(undefined);
|
|
819
|
+
}
|
|
820
|
+
});
|
|
821
|
+
};
|
|
822
|
+
|
|
823
|
+
//#endregion
|
|
824
|
+
//#region node_modules/vscode-languageserver-types/lib/esm/main.js
|
|
825
|
+
var DocumentUri;
|
|
826
|
+
(function(DocumentUri$1) {
|
|
827
|
+
function is(value) {
|
|
828
|
+
return typeof value === "string";
|
|
829
|
+
}
|
|
830
|
+
DocumentUri$1.is = is;
|
|
831
|
+
})(DocumentUri || (DocumentUri = {}));
|
|
832
|
+
var URI;
|
|
833
|
+
(function(URI$1) {
|
|
834
|
+
function is(value) {
|
|
835
|
+
return typeof value === "string";
|
|
836
|
+
}
|
|
837
|
+
URI$1.is = is;
|
|
838
|
+
})(URI || (URI = {}));
|
|
839
|
+
var integer;
|
|
840
|
+
(function(integer$1) {
|
|
841
|
+
integer$1.MIN_VALUE = -2147483648;
|
|
842
|
+
integer$1.MAX_VALUE = 2147483647;
|
|
843
|
+
function is(value) {
|
|
844
|
+
return typeof value === "number" && integer$1.MIN_VALUE <= value && value <= integer$1.MAX_VALUE;
|
|
845
|
+
}
|
|
846
|
+
integer$1.is = is;
|
|
847
|
+
})(integer || (integer = {}));
|
|
848
|
+
var uinteger;
|
|
849
|
+
(function(uinteger$1) {
|
|
850
|
+
uinteger$1.MIN_VALUE = 0;
|
|
851
|
+
uinteger$1.MAX_VALUE = 2147483647;
|
|
852
|
+
function is(value) {
|
|
853
|
+
return typeof value === "number" && uinteger$1.MIN_VALUE <= value && value <= uinteger$1.MAX_VALUE;
|
|
854
|
+
}
|
|
855
|
+
uinteger$1.is = is;
|
|
856
|
+
})(uinteger || (uinteger = {}));
|
|
857
|
+
/**
|
|
858
|
+
* The Position namespace provides helper functions to work with
|
|
859
|
+
* {@link Position} literals.
|
|
860
|
+
*/
|
|
861
|
+
var Position;
|
|
862
|
+
(function(Position$1) {
|
|
863
|
+
/**
|
|
864
|
+
* Creates a new Position literal from the given line and character.
|
|
865
|
+
* @param line The position's line.
|
|
866
|
+
* @param character The position's character.
|
|
867
|
+
*/
|
|
868
|
+
function create(line, character) {
|
|
869
|
+
if (line === Number.MAX_VALUE) {
|
|
870
|
+
line = uinteger.MAX_VALUE;
|
|
871
|
+
}
|
|
872
|
+
if (character === Number.MAX_VALUE) {
|
|
873
|
+
character = uinteger.MAX_VALUE;
|
|
874
|
+
}
|
|
875
|
+
return {
|
|
876
|
+
line,
|
|
877
|
+
character
|
|
878
|
+
};
|
|
879
|
+
}
|
|
880
|
+
Position$1.create = create;
|
|
881
|
+
/**
|
|
882
|
+
* Checks whether the given literal conforms to the {@link Position} interface.
|
|
883
|
+
*/
|
|
884
|
+
function is(value) {
|
|
885
|
+
let candidate = value;
|
|
886
|
+
return Is.objectLiteral(candidate) && Is.uinteger(candidate.line) && Is.uinteger(candidate.character);
|
|
887
|
+
}
|
|
888
|
+
Position$1.is = is;
|
|
889
|
+
})(Position || (Position = {}));
|
|
890
|
+
/**
|
|
891
|
+
* The Range namespace provides helper functions to work with
|
|
892
|
+
* {@link Range} literals.
|
|
893
|
+
*/
|
|
894
|
+
var Range;
|
|
895
|
+
(function(Range$1) {
|
|
896
|
+
function create(one, two, three, four) {
|
|
897
|
+
if (Is.uinteger(one) && Is.uinteger(two) && Is.uinteger(three) && Is.uinteger(four)) {
|
|
898
|
+
return {
|
|
899
|
+
start: Position.create(one, two),
|
|
900
|
+
end: Position.create(three, four)
|
|
901
|
+
};
|
|
902
|
+
} else if (Position.is(one) && Position.is(two)) {
|
|
903
|
+
return {
|
|
904
|
+
start: one,
|
|
905
|
+
end: two
|
|
906
|
+
};
|
|
907
|
+
} else {
|
|
908
|
+
throw new Error(`Range#create called with invalid arguments[${one}, ${two}, ${three}, ${four}]`);
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
Range$1.create = create;
|
|
912
|
+
/**
|
|
913
|
+
* Checks whether the given literal conforms to the {@link Range} interface.
|
|
914
|
+
*/
|
|
915
|
+
function is(value) {
|
|
916
|
+
let candidate = value;
|
|
917
|
+
return Is.objectLiteral(candidate) && Position.is(candidate.start) && Position.is(candidate.end);
|
|
918
|
+
}
|
|
919
|
+
Range$1.is = is;
|
|
920
|
+
})(Range || (Range = {}));
|
|
921
|
+
/**
|
|
922
|
+
* The Location namespace provides helper functions to work with
|
|
923
|
+
* {@link Location} literals.
|
|
924
|
+
*/
|
|
925
|
+
var Location;
|
|
926
|
+
(function(Location$1) {
|
|
927
|
+
/**
|
|
928
|
+
* Creates a Location literal.
|
|
929
|
+
* @param uri The location's uri.
|
|
930
|
+
* @param range The location's range.
|
|
931
|
+
*/
|
|
932
|
+
function create(uri, range) {
|
|
933
|
+
return {
|
|
934
|
+
uri,
|
|
935
|
+
range
|
|
936
|
+
};
|
|
937
|
+
}
|
|
938
|
+
Location$1.create = create;
|
|
939
|
+
/**
|
|
940
|
+
* Checks whether the given literal conforms to the {@link Location} interface.
|
|
941
|
+
*/
|
|
942
|
+
function is(value) {
|
|
943
|
+
let candidate = value;
|
|
944
|
+
return Is.objectLiteral(candidate) && Range.is(candidate.range) && (Is.string(candidate.uri) || Is.undefined(candidate.uri));
|
|
945
|
+
}
|
|
946
|
+
Location$1.is = is;
|
|
947
|
+
})(Location || (Location = {}));
|
|
948
|
+
/**
|
|
949
|
+
* The LocationLink namespace provides helper functions to work with
|
|
950
|
+
* {@link LocationLink} literals.
|
|
951
|
+
*/
|
|
952
|
+
var LocationLink;
|
|
953
|
+
(function(LocationLink$1) {
|
|
954
|
+
/**
|
|
955
|
+
* Creates a LocationLink literal.
|
|
956
|
+
* @param targetUri The definition's uri.
|
|
957
|
+
* @param targetRange The full range of the definition.
|
|
958
|
+
* @param targetSelectionRange The span of the symbol definition at the target.
|
|
959
|
+
* @param originSelectionRange The span of the symbol being defined in the originating source file.
|
|
960
|
+
*/
|
|
961
|
+
function create(targetUri, targetRange, targetSelectionRange, originSelectionRange) {
|
|
962
|
+
return {
|
|
963
|
+
targetUri,
|
|
964
|
+
targetRange,
|
|
965
|
+
targetSelectionRange,
|
|
966
|
+
originSelectionRange
|
|
967
|
+
};
|
|
968
|
+
}
|
|
969
|
+
LocationLink$1.create = create;
|
|
970
|
+
/**
|
|
971
|
+
* Checks whether the given literal conforms to the {@link LocationLink} interface.
|
|
972
|
+
*/
|
|
973
|
+
function is(value) {
|
|
974
|
+
let candidate = value;
|
|
975
|
+
return Is.objectLiteral(candidate) && Range.is(candidate.targetRange) && Is.string(candidate.targetUri) && Range.is(candidate.targetSelectionRange) && (Range.is(candidate.originSelectionRange) || Is.undefined(candidate.originSelectionRange));
|
|
976
|
+
}
|
|
977
|
+
LocationLink$1.is = is;
|
|
978
|
+
})(LocationLink || (LocationLink = {}));
|
|
979
|
+
/**
|
|
980
|
+
* The Color namespace provides helper functions to work with
|
|
981
|
+
* {@link Color} literals.
|
|
982
|
+
*/
|
|
983
|
+
var Color;
|
|
984
|
+
(function(Color$1) {
|
|
985
|
+
/**
|
|
986
|
+
* Creates a new Color literal.
|
|
987
|
+
*/
|
|
988
|
+
function create(red, green, blue, alpha) {
|
|
989
|
+
return {
|
|
990
|
+
red,
|
|
991
|
+
green,
|
|
992
|
+
blue,
|
|
993
|
+
alpha
|
|
994
|
+
};
|
|
995
|
+
}
|
|
996
|
+
Color$1.create = create;
|
|
997
|
+
/**
|
|
998
|
+
* Checks whether the given literal conforms to the {@link Color} interface.
|
|
999
|
+
*/
|
|
1000
|
+
function is(value) {
|
|
1001
|
+
const candidate = value;
|
|
1002
|
+
return Is.objectLiteral(candidate) && Is.numberRange(candidate.red, 0, 1) && Is.numberRange(candidate.green, 0, 1) && Is.numberRange(candidate.blue, 0, 1) && Is.numberRange(candidate.alpha, 0, 1);
|
|
1003
|
+
}
|
|
1004
|
+
Color$1.is = is;
|
|
1005
|
+
})(Color || (Color = {}));
|
|
1006
|
+
/**
|
|
1007
|
+
* The ColorInformation namespace provides helper functions to work with
|
|
1008
|
+
* {@link ColorInformation} literals.
|
|
1009
|
+
*/
|
|
1010
|
+
var ColorInformation;
|
|
1011
|
+
(function(ColorInformation$1) {
|
|
1012
|
+
/**
|
|
1013
|
+
* Creates a new ColorInformation literal.
|
|
1014
|
+
*/
|
|
1015
|
+
function create(range, color) {
|
|
1016
|
+
return {
|
|
1017
|
+
range,
|
|
1018
|
+
color
|
|
1019
|
+
};
|
|
1020
|
+
}
|
|
1021
|
+
ColorInformation$1.create = create;
|
|
1022
|
+
/**
|
|
1023
|
+
* Checks whether the given literal conforms to the {@link ColorInformation} interface.
|
|
1024
|
+
*/
|
|
1025
|
+
function is(value) {
|
|
1026
|
+
const candidate = value;
|
|
1027
|
+
return Is.objectLiteral(candidate) && Range.is(candidate.range) && Color.is(candidate.color);
|
|
1028
|
+
}
|
|
1029
|
+
ColorInformation$1.is = is;
|
|
1030
|
+
})(ColorInformation || (ColorInformation = {}));
|
|
1031
|
+
/**
|
|
1032
|
+
* The Color namespace provides helper functions to work with
|
|
1033
|
+
* {@link ColorPresentation} literals.
|
|
1034
|
+
*/
|
|
1035
|
+
var ColorPresentation;
|
|
1036
|
+
(function(ColorPresentation$1) {
|
|
1037
|
+
/**
|
|
1038
|
+
* Creates a new ColorInformation literal.
|
|
1039
|
+
*/
|
|
1040
|
+
function create(label, textEdit, additionalTextEdits) {
|
|
1041
|
+
return {
|
|
1042
|
+
label,
|
|
1043
|
+
textEdit,
|
|
1044
|
+
additionalTextEdits
|
|
1045
|
+
};
|
|
1046
|
+
}
|
|
1047
|
+
ColorPresentation$1.create = create;
|
|
1048
|
+
/**
|
|
1049
|
+
* Checks whether the given literal conforms to the {@link ColorInformation} interface.
|
|
1050
|
+
*/
|
|
1051
|
+
function is(value) {
|
|
1052
|
+
const candidate = value;
|
|
1053
|
+
return Is.objectLiteral(candidate) && Is.string(candidate.label) && (Is.undefined(candidate.textEdit) || TextEdit.is(candidate)) && (Is.undefined(candidate.additionalTextEdits) || Is.typedArray(candidate.additionalTextEdits, TextEdit.is));
|
|
1054
|
+
}
|
|
1055
|
+
ColorPresentation$1.is = is;
|
|
1056
|
+
})(ColorPresentation || (ColorPresentation = {}));
|
|
1057
|
+
/**
|
|
1058
|
+
* A set of predefined range kinds.
|
|
1059
|
+
*/
|
|
1060
|
+
var FoldingRangeKind;
|
|
1061
|
+
(function(FoldingRangeKind$1) {
|
|
1062
|
+
/**
|
|
1063
|
+
* Folding range for a comment
|
|
1064
|
+
*/
|
|
1065
|
+
FoldingRangeKind$1.Comment = "comment";
|
|
1066
|
+
/**
|
|
1067
|
+
* Folding range for an import or include
|
|
1068
|
+
*/
|
|
1069
|
+
FoldingRangeKind$1.Imports = "imports";
|
|
1070
|
+
/**
|
|
1071
|
+
* Folding range for a region (e.g. `#region`)
|
|
1072
|
+
*/
|
|
1073
|
+
FoldingRangeKind$1.Region = "region";
|
|
1074
|
+
})(FoldingRangeKind || (FoldingRangeKind = {}));
|
|
1075
|
+
/**
|
|
1076
|
+
* The folding range namespace provides helper functions to work with
|
|
1077
|
+
* {@link FoldingRange} literals.
|
|
1078
|
+
*/
|
|
1079
|
+
var FoldingRange;
|
|
1080
|
+
(function(FoldingRange$1) {
|
|
1081
|
+
/**
|
|
1082
|
+
* Creates a new FoldingRange literal.
|
|
1083
|
+
*/
|
|
1084
|
+
function create(startLine, endLine, startCharacter, endCharacter, kind, collapsedText) {
|
|
1085
|
+
const result = {
|
|
1086
|
+
startLine,
|
|
1087
|
+
endLine
|
|
1088
|
+
};
|
|
1089
|
+
if (Is.defined(startCharacter)) {
|
|
1090
|
+
result.startCharacter = startCharacter;
|
|
1091
|
+
}
|
|
1092
|
+
if (Is.defined(endCharacter)) {
|
|
1093
|
+
result.endCharacter = endCharacter;
|
|
1094
|
+
}
|
|
1095
|
+
if (Is.defined(kind)) {
|
|
1096
|
+
result.kind = kind;
|
|
1097
|
+
}
|
|
1098
|
+
if (Is.defined(collapsedText)) {
|
|
1099
|
+
result.collapsedText = collapsedText;
|
|
1100
|
+
}
|
|
1101
|
+
return result;
|
|
1102
|
+
}
|
|
1103
|
+
FoldingRange$1.create = create;
|
|
1104
|
+
/**
|
|
1105
|
+
* Checks whether the given literal conforms to the {@link FoldingRange} interface.
|
|
1106
|
+
*/
|
|
1107
|
+
function is(value) {
|
|
1108
|
+
const candidate = value;
|
|
1109
|
+
return Is.objectLiteral(candidate) && Is.uinteger(candidate.startLine) && Is.uinteger(candidate.startLine) && (Is.undefined(candidate.startCharacter) || Is.uinteger(candidate.startCharacter)) && (Is.undefined(candidate.endCharacter) || Is.uinteger(candidate.endCharacter)) && (Is.undefined(candidate.kind) || Is.string(candidate.kind));
|
|
1110
|
+
}
|
|
1111
|
+
FoldingRange$1.is = is;
|
|
1112
|
+
})(FoldingRange || (FoldingRange = {}));
|
|
1113
|
+
/**
|
|
1114
|
+
* The DiagnosticRelatedInformation namespace provides helper functions to work with
|
|
1115
|
+
* {@link DiagnosticRelatedInformation} literals.
|
|
1116
|
+
*/
|
|
1117
|
+
var DiagnosticRelatedInformation;
|
|
1118
|
+
(function(DiagnosticRelatedInformation$1) {
|
|
1119
|
+
/**
|
|
1120
|
+
* Creates a new DiagnosticRelatedInformation literal.
|
|
1121
|
+
*/
|
|
1122
|
+
function create(location, message) {
|
|
1123
|
+
return {
|
|
1124
|
+
location,
|
|
1125
|
+
message
|
|
1126
|
+
};
|
|
1127
|
+
}
|
|
1128
|
+
DiagnosticRelatedInformation$1.create = create;
|
|
1129
|
+
/**
|
|
1130
|
+
* Checks whether the given literal conforms to the {@link DiagnosticRelatedInformation} interface.
|
|
1131
|
+
*/
|
|
1132
|
+
function is(value) {
|
|
1133
|
+
let candidate = value;
|
|
1134
|
+
return Is.defined(candidate) && Location.is(candidate.location) && Is.string(candidate.message);
|
|
1135
|
+
}
|
|
1136
|
+
DiagnosticRelatedInformation$1.is = is;
|
|
1137
|
+
})(DiagnosticRelatedInformation || (DiagnosticRelatedInformation = {}));
|
|
1138
|
+
/**
|
|
1139
|
+
* The diagnostic's severity.
|
|
1140
|
+
*/
|
|
1141
|
+
var DiagnosticSeverity;
|
|
1142
|
+
(function(DiagnosticSeverity$1) {
|
|
1143
|
+
/**
|
|
1144
|
+
* Reports an error.
|
|
1145
|
+
*/
|
|
1146
|
+
DiagnosticSeverity$1.Error = 1;
|
|
1147
|
+
/**
|
|
1148
|
+
* Reports a warning.
|
|
1149
|
+
*/
|
|
1150
|
+
DiagnosticSeverity$1.Warning = 2;
|
|
1151
|
+
/**
|
|
1152
|
+
* Reports an information.
|
|
1153
|
+
*/
|
|
1154
|
+
DiagnosticSeverity$1.Information = 3;
|
|
1155
|
+
/**
|
|
1156
|
+
* Reports a hint.
|
|
1157
|
+
*/
|
|
1158
|
+
DiagnosticSeverity$1.Hint = 4;
|
|
1159
|
+
})(DiagnosticSeverity || (DiagnosticSeverity = {}));
|
|
1160
|
+
/**
|
|
1161
|
+
* The diagnostic tags.
|
|
1162
|
+
*
|
|
1163
|
+
* @since 3.15.0
|
|
1164
|
+
*/
|
|
1165
|
+
var DiagnosticTag;
|
|
1166
|
+
(function(DiagnosticTag$1) {
|
|
1167
|
+
/**
|
|
1168
|
+
* Unused or unnecessary code.
|
|
1169
|
+
*
|
|
1170
|
+
* Clients are allowed to render diagnostics with this tag faded out instead of having
|
|
1171
|
+
* an error squiggle.
|
|
1172
|
+
*/
|
|
1173
|
+
DiagnosticTag$1.Unnecessary = 1;
|
|
1174
|
+
/**
|
|
1175
|
+
* Deprecated or obsolete code.
|
|
1176
|
+
*
|
|
1177
|
+
* Clients are allowed to rendered diagnostics with this tag strike through.
|
|
1178
|
+
*/
|
|
1179
|
+
DiagnosticTag$1.Deprecated = 2;
|
|
1180
|
+
})(DiagnosticTag || (DiagnosticTag = {}));
|
|
1181
|
+
/**
|
|
1182
|
+
* The CodeDescription namespace provides functions to deal with descriptions for diagnostic codes.
|
|
1183
|
+
*
|
|
1184
|
+
* @since 3.16.0
|
|
1185
|
+
*/
|
|
1186
|
+
var CodeDescription;
|
|
1187
|
+
(function(CodeDescription$1) {
|
|
1188
|
+
function is(value) {
|
|
1189
|
+
const candidate = value;
|
|
1190
|
+
return Is.objectLiteral(candidate) && Is.string(candidate.href);
|
|
1191
|
+
}
|
|
1192
|
+
CodeDescription$1.is = is;
|
|
1193
|
+
})(CodeDescription || (CodeDescription = {}));
|
|
1194
|
+
/**
|
|
1195
|
+
* The Diagnostic namespace provides helper functions to work with
|
|
1196
|
+
* {@link Diagnostic} literals.
|
|
1197
|
+
*/
|
|
1198
|
+
var Diagnostic;
|
|
1199
|
+
(function(Diagnostic$1) {
|
|
1200
|
+
/**
|
|
1201
|
+
* Creates a new Diagnostic literal.
|
|
1202
|
+
*/
|
|
1203
|
+
function create(range, message, severity, code, source, relatedInformation) {
|
|
1204
|
+
let result = {
|
|
1205
|
+
range,
|
|
1206
|
+
message
|
|
1207
|
+
};
|
|
1208
|
+
if (Is.defined(severity)) {
|
|
1209
|
+
result.severity = severity;
|
|
1210
|
+
}
|
|
1211
|
+
if (Is.defined(code)) {
|
|
1212
|
+
result.code = code;
|
|
1213
|
+
}
|
|
1214
|
+
if (Is.defined(source)) {
|
|
1215
|
+
result.source = source;
|
|
1216
|
+
}
|
|
1217
|
+
if (Is.defined(relatedInformation)) {
|
|
1218
|
+
result.relatedInformation = relatedInformation;
|
|
1219
|
+
}
|
|
1220
|
+
return result;
|
|
1221
|
+
}
|
|
1222
|
+
Diagnostic$1.create = create;
|
|
1223
|
+
/**
|
|
1224
|
+
* Checks whether the given literal conforms to the {@link Diagnostic} interface.
|
|
1225
|
+
*/
|
|
1226
|
+
function is(value) {
|
|
1227
|
+
var _a;
|
|
1228
|
+
let candidate = value;
|
|
1229
|
+
return Is.defined(candidate) && Range.is(candidate.range) && Is.string(candidate.message) && (Is.number(candidate.severity) || Is.undefined(candidate.severity)) && (Is.integer(candidate.code) || Is.string(candidate.code) || Is.undefined(candidate.code)) && (Is.undefined(candidate.codeDescription) || Is.string((_a = candidate.codeDescription) === null || _a === void 0 ? void 0 : _a.href)) && (Is.string(candidate.source) || Is.undefined(candidate.source)) && (Is.undefined(candidate.relatedInformation) || Is.typedArray(candidate.relatedInformation, DiagnosticRelatedInformation.is));
|
|
1230
|
+
}
|
|
1231
|
+
Diagnostic$1.is = is;
|
|
1232
|
+
})(Diagnostic || (Diagnostic = {}));
|
|
1233
|
+
/**
|
|
1234
|
+
* The Command namespace provides helper functions to work with
|
|
1235
|
+
* {@link Command} literals.
|
|
1236
|
+
*/
|
|
1237
|
+
var Command;
|
|
1238
|
+
(function(Command$1) {
|
|
1239
|
+
/**
|
|
1240
|
+
* Creates a new Command literal.
|
|
1241
|
+
*/
|
|
1242
|
+
function create(title, command, ...args) {
|
|
1243
|
+
let result = {
|
|
1244
|
+
title,
|
|
1245
|
+
command
|
|
1246
|
+
};
|
|
1247
|
+
if (Is.defined(args) && args.length > 0) {
|
|
1248
|
+
result.arguments = args;
|
|
1249
|
+
}
|
|
1250
|
+
return result;
|
|
1251
|
+
}
|
|
1252
|
+
Command$1.create = create;
|
|
1253
|
+
/**
|
|
1254
|
+
* Checks whether the given literal conforms to the {@link Command} interface.
|
|
1255
|
+
*/
|
|
1256
|
+
function is(value) {
|
|
1257
|
+
let candidate = value;
|
|
1258
|
+
return Is.defined(candidate) && Is.string(candidate.title) && Is.string(candidate.command);
|
|
1259
|
+
}
|
|
1260
|
+
Command$1.is = is;
|
|
1261
|
+
})(Command || (Command = {}));
|
|
1262
|
+
/**
|
|
1263
|
+
* The TextEdit namespace provides helper function to create replace,
|
|
1264
|
+
* insert and delete edits more easily.
|
|
1265
|
+
*/
|
|
1266
|
+
var TextEdit;
|
|
1267
|
+
(function(TextEdit$1) {
|
|
1268
|
+
/**
|
|
1269
|
+
* Creates a replace text edit.
|
|
1270
|
+
* @param range The range of text to be replaced.
|
|
1271
|
+
* @param newText The new text.
|
|
1272
|
+
*/
|
|
1273
|
+
function replace(range, newText) {
|
|
1274
|
+
return {
|
|
1275
|
+
range,
|
|
1276
|
+
newText
|
|
1277
|
+
};
|
|
1278
|
+
}
|
|
1279
|
+
TextEdit$1.replace = replace;
|
|
1280
|
+
/**
|
|
1281
|
+
* Creates an insert text edit.
|
|
1282
|
+
* @param position The position to insert the text at.
|
|
1283
|
+
* @param newText The text to be inserted.
|
|
1284
|
+
*/
|
|
1285
|
+
function insert(position, newText) {
|
|
1286
|
+
return {
|
|
1287
|
+
range: {
|
|
1288
|
+
start: position,
|
|
1289
|
+
end: position
|
|
1290
|
+
},
|
|
1291
|
+
newText
|
|
1292
|
+
};
|
|
1293
|
+
}
|
|
1294
|
+
TextEdit$1.insert = insert;
|
|
1295
|
+
/**
|
|
1296
|
+
* Creates a delete text edit.
|
|
1297
|
+
* @param range The range of text to be deleted.
|
|
1298
|
+
*/
|
|
1299
|
+
function del(range) {
|
|
1300
|
+
return {
|
|
1301
|
+
range,
|
|
1302
|
+
newText: ""
|
|
1303
|
+
};
|
|
1304
|
+
}
|
|
1305
|
+
TextEdit$1.del = del;
|
|
1306
|
+
function is(value) {
|
|
1307
|
+
const candidate = value;
|
|
1308
|
+
return Is.objectLiteral(candidate) && Is.string(candidate.newText) && Range.is(candidate.range);
|
|
1309
|
+
}
|
|
1310
|
+
TextEdit$1.is = is;
|
|
1311
|
+
})(TextEdit || (TextEdit = {}));
|
|
1312
|
+
var ChangeAnnotation;
|
|
1313
|
+
(function(ChangeAnnotation$1) {
|
|
1314
|
+
function create(label, needsConfirmation, description) {
|
|
1315
|
+
const result = { label };
|
|
1316
|
+
if (needsConfirmation !== undefined) {
|
|
1317
|
+
result.needsConfirmation = needsConfirmation;
|
|
1318
|
+
}
|
|
1319
|
+
if (description !== undefined) {
|
|
1320
|
+
result.description = description;
|
|
1321
|
+
}
|
|
1322
|
+
return result;
|
|
1323
|
+
}
|
|
1324
|
+
ChangeAnnotation$1.create = create;
|
|
1325
|
+
function is(value) {
|
|
1326
|
+
const candidate = value;
|
|
1327
|
+
return Is.objectLiteral(candidate) && Is.string(candidate.label) && (Is.boolean(candidate.needsConfirmation) || candidate.needsConfirmation === undefined) && (Is.string(candidate.description) || candidate.description === undefined);
|
|
1328
|
+
}
|
|
1329
|
+
ChangeAnnotation$1.is = is;
|
|
1330
|
+
})(ChangeAnnotation || (ChangeAnnotation = {}));
|
|
1331
|
+
var ChangeAnnotationIdentifier;
|
|
1332
|
+
(function(ChangeAnnotationIdentifier$1) {
|
|
1333
|
+
function is(value) {
|
|
1334
|
+
const candidate = value;
|
|
1335
|
+
return Is.string(candidate);
|
|
1336
|
+
}
|
|
1337
|
+
ChangeAnnotationIdentifier$1.is = is;
|
|
1338
|
+
})(ChangeAnnotationIdentifier || (ChangeAnnotationIdentifier = {}));
|
|
1339
|
+
var AnnotatedTextEdit;
|
|
1340
|
+
(function(AnnotatedTextEdit$1) {
|
|
1341
|
+
/**
|
|
1342
|
+
* Creates an annotated replace text edit.
|
|
1343
|
+
*
|
|
1344
|
+
* @param range The range of text to be replaced.
|
|
1345
|
+
* @param newText The new text.
|
|
1346
|
+
* @param annotation The annotation.
|
|
1347
|
+
*/
|
|
1348
|
+
function replace(range, newText, annotation) {
|
|
1349
|
+
return {
|
|
1350
|
+
range,
|
|
1351
|
+
newText,
|
|
1352
|
+
annotationId: annotation
|
|
1353
|
+
};
|
|
1354
|
+
}
|
|
1355
|
+
AnnotatedTextEdit$1.replace = replace;
|
|
1356
|
+
/**
|
|
1357
|
+
* Creates an annotated insert text edit.
|
|
1358
|
+
*
|
|
1359
|
+
* @param position The position to insert the text at.
|
|
1360
|
+
* @param newText The text to be inserted.
|
|
1361
|
+
* @param annotation The annotation.
|
|
1362
|
+
*/
|
|
1363
|
+
function insert(position, newText, annotation) {
|
|
1364
|
+
return {
|
|
1365
|
+
range: {
|
|
1366
|
+
start: position,
|
|
1367
|
+
end: position
|
|
1368
|
+
},
|
|
1369
|
+
newText,
|
|
1370
|
+
annotationId: annotation
|
|
1371
|
+
};
|
|
1372
|
+
}
|
|
1373
|
+
AnnotatedTextEdit$1.insert = insert;
|
|
1374
|
+
/**
|
|
1375
|
+
* Creates an annotated delete text edit.
|
|
1376
|
+
*
|
|
1377
|
+
* @param range The range of text to be deleted.
|
|
1378
|
+
* @param annotation The annotation.
|
|
1379
|
+
*/
|
|
1380
|
+
function del(range, annotation) {
|
|
1381
|
+
return {
|
|
1382
|
+
range,
|
|
1383
|
+
newText: "",
|
|
1384
|
+
annotationId: annotation
|
|
1385
|
+
};
|
|
1386
|
+
}
|
|
1387
|
+
AnnotatedTextEdit$1.del = del;
|
|
1388
|
+
function is(value) {
|
|
1389
|
+
const candidate = value;
|
|
1390
|
+
return TextEdit.is(candidate) && (ChangeAnnotation.is(candidate.annotationId) || ChangeAnnotationIdentifier.is(candidate.annotationId));
|
|
1391
|
+
}
|
|
1392
|
+
AnnotatedTextEdit$1.is = is;
|
|
1393
|
+
})(AnnotatedTextEdit || (AnnotatedTextEdit = {}));
|
|
1394
|
+
/**
|
|
1395
|
+
* The TextDocumentEdit namespace provides helper function to create
|
|
1396
|
+
* an edit that manipulates a text document.
|
|
1397
|
+
*/
|
|
1398
|
+
var TextDocumentEdit;
|
|
1399
|
+
(function(TextDocumentEdit$1) {
|
|
1400
|
+
/**
|
|
1401
|
+
* Creates a new `TextDocumentEdit`
|
|
1402
|
+
*/
|
|
1403
|
+
function create(textDocument, edits) {
|
|
1404
|
+
return {
|
|
1405
|
+
textDocument,
|
|
1406
|
+
edits
|
|
1407
|
+
};
|
|
1408
|
+
}
|
|
1409
|
+
TextDocumentEdit$1.create = create;
|
|
1410
|
+
function is(value) {
|
|
1411
|
+
let candidate = value;
|
|
1412
|
+
return Is.defined(candidate) && OptionalVersionedTextDocumentIdentifier.is(candidate.textDocument) && Array.isArray(candidate.edits);
|
|
1413
|
+
}
|
|
1414
|
+
TextDocumentEdit$1.is = is;
|
|
1415
|
+
})(TextDocumentEdit || (TextDocumentEdit = {}));
|
|
1416
|
+
var CreateFile;
|
|
1417
|
+
(function(CreateFile$1) {
|
|
1418
|
+
function create(uri, options, annotation) {
|
|
1419
|
+
let result = {
|
|
1420
|
+
kind: "create",
|
|
1421
|
+
uri
|
|
1422
|
+
};
|
|
1423
|
+
if (options !== undefined && (options.overwrite !== undefined || options.ignoreIfExists !== undefined)) {
|
|
1424
|
+
result.options = options;
|
|
1425
|
+
}
|
|
1426
|
+
if (annotation !== undefined) {
|
|
1427
|
+
result.annotationId = annotation;
|
|
1428
|
+
}
|
|
1429
|
+
return result;
|
|
1430
|
+
}
|
|
1431
|
+
CreateFile$1.create = create;
|
|
1432
|
+
function is(value) {
|
|
1433
|
+
let candidate = value;
|
|
1434
|
+
return candidate && candidate.kind === "create" && Is.string(candidate.uri) && (candidate.options === undefined || (candidate.options.overwrite === undefined || Is.boolean(candidate.options.overwrite)) && (candidate.options.ignoreIfExists === undefined || Is.boolean(candidate.options.ignoreIfExists))) && (candidate.annotationId === undefined || ChangeAnnotationIdentifier.is(candidate.annotationId));
|
|
1435
|
+
}
|
|
1436
|
+
CreateFile$1.is = is;
|
|
1437
|
+
})(CreateFile || (CreateFile = {}));
|
|
1438
|
+
var RenameFile;
|
|
1439
|
+
(function(RenameFile$1) {
|
|
1440
|
+
function create(oldUri, newUri, options, annotation) {
|
|
1441
|
+
let result = {
|
|
1442
|
+
kind: "rename",
|
|
1443
|
+
oldUri,
|
|
1444
|
+
newUri
|
|
1445
|
+
};
|
|
1446
|
+
if (options !== undefined && (options.overwrite !== undefined || options.ignoreIfExists !== undefined)) {
|
|
1447
|
+
result.options = options;
|
|
1448
|
+
}
|
|
1449
|
+
if (annotation !== undefined) {
|
|
1450
|
+
result.annotationId = annotation;
|
|
1451
|
+
}
|
|
1452
|
+
return result;
|
|
1453
|
+
}
|
|
1454
|
+
RenameFile$1.create = create;
|
|
1455
|
+
function is(value) {
|
|
1456
|
+
let candidate = value;
|
|
1457
|
+
return candidate && candidate.kind === "rename" && Is.string(candidate.oldUri) && Is.string(candidate.newUri) && (candidate.options === undefined || (candidate.options.overwrite === undefined || Is.boolean(candidate.options.overwrite)) && (candidate.options.ignoreIfExists === undefined || Is.boolean(candidate.options.ignoreIfExists))) && (candidate.annotationId === undefined || ChangeAnnotationIdentifier.is(candidate.annotationId));
|
|
1458
|
+
}
|
|
1459
|
+
RenameFile$1.is = is;
|
|
1460
|
+
})(RenameFile || (RenameFile = {}));
|
|
1461
|
+
var DeleteFile;
|
|
1462
|
+
(function(DeleteFile$1) {
|
|
1463
|
+
function create(uri, options, annotation) {
|
|
1464
|
+
let result = {
|
|
1465
|
+
kind: "delete",
|
|
1466
|
+
uri
|
|
1467
|
+
};
|
|
1468
|
+
if (options !== undefined && (options.recursive !== undefined || options.ignoreIfNotExists !== undefined)) {
|
|
1469
|
+
result.options = options;
|
|
1470
|
+
}
|
|
1471
|
+
if (annotation !== undefined) {
|
|
1472
|
+
result.annotationId = annotation;
|
|
1473
|
+
}
|
|
1474
|
+
return result;
|
|
1475
|
+
}
|
|
1476
|
+
DeleteFile$1.create = create;
|
|
1477
|
+
function is(value) {
|
|
1478
|
+
let candidate = value;
|
|
1479
|
+
return candidate && candidate.kind === "delete" && Is.string(candidate.uri) && (candidate.options === undefined || (candidate.options.recursive === undefined || Is.boolean(candidate.options.recursive)) && (candidate.options.ignoreIfNotExists === undefined || Is.boolean(candidate.options.ignoreIfNotExists))) && (candidate.annotationId === undefined || ChangeAnnotationIdentifier.is(candidate.annotationId));
|
|
1480
|
+
}
|
|
1481
|
+
DeleteFile$1.is = is;
|
|
1482
|
+
})(DeleteFile || (DeleteFile = {}));
|
|
1483
|
+
var WorkspaceEdit;
|
|
1484
|
+
(function(WorkspaceEdit$1) {
|
|
1485
|
+
function is(value) {
|
|
1486
|
+
let candidate = value;
|
|
1487
|
+
return candidate && (candidate.changes !== undefined || candidate.documentChanges !== undefined) && (candidate.documentChanges === undefined || candidate.documentChanges.every((change) => {
|
|
1488
|
+
if (Is.string(change.kind)) {
|
|
1489
|
+
return CreateFile.is(change) || RenameFile.is(change) || DeleteFile.is(change);
|
|
1490
|
+
} else {
|
|
1491
|
+
return TextDocumentEdit.is(change);
|
|
1492
|
+
}
|
|
1493
|
+
}));
|
|
1494
|
+
}
|
|
1495
|
+
WorkspaceEdit$1.is = is;
|
|
1496
|
+
})(WorkspaceEdit || (WorkspaceEdit = {}));
|
|
1497
|
+
var TextEditChangeImpl = class {
|
|
1498
|
+
constructor(edits, changeAnnotations) {
|
|
1499
|
+
this.edits = edits;
|
|
1500
|
+
this.changeAnnotations = changeAnnotations;
|
|
1501
|
+
}
|
|
1502
|
+
insert(position, newText, annotation) {
|
|
1503
|
+
let edit;
|
|
1504
|
+
let id;
|
|
1505
|
+
if (annotation === undefined) {
|
|
1506
|
+
edit = TextEdit.insert(position, newText);
|
|
1507
|
+
} else if (ChangeAnnotationIdentifier.is(annotation)) {
|
|
1508
|
+
id = annotation;
|
|
1509
|
+
edit = AnnotatedTextEdit.insert(position, newText, annotation);
|
|
1510
|
+
} else {
|
|
1511
|
+
this.assertChangeAnnotations(this.changeAnnotations);
|
|
1512
|
+
id = this.changeAnnotations.manage(annotation);
|
|
1513
|
+
edit = AnnotatedTextEdit.insert(position, newText, id);
|
|
1514
|
+
}
|
|
1515
|
+
this.edits.push(edit);
|
|
1516
|
+
if (id !== undefined) {
|
|
1517
|
+
return id;
|
|
1518
|
+
}
|
|
1519
|
+
}
|
|
1520
|
+
replace(range, newText, annotation) {
|
|
1521
|
+
let edit;
|
|
1522
|
+
let id;
|
|
1523
|
+
if (annotation === undefined) {
|
|
1524
|
+
edit = TextEdit.replace(range, newText);
|
|
1525
|
+
} else if (ChangeAnnotationIdentifier.is(annotation)) {
|
|
1526
|
+
id = annotation;
|
|
1527
|
+
edit = AnnotatedTextEdit.replace(range, newText, annotation);
|
|
1528
|
+
} else {
|
|
1529
|
+
this.assertChangeAnnotations(this.changeAnnotations);
|
|
1530
|
+
id = this.changeAnnotations.manage(annotation);
|
|
1531
|
+
edit = AnnotatedTextEdit.replace(range, newText, id);
|
|
1532
|
+
}
|
|
1533
|
+
this.edits.push(edit);
|
|
1534
|
+
if (id !== undefined) {
|
|
1535
|
+
return id;
|
|
1536
|
+
}
|
|
1537
|
+
}
|
|
1538
|
+
delete(range, annotation) {
|
|
1539
|
+
let edit;
|
|
1540
|
+
let id;
|
|
1541
|
+
if (annotation === undefined) {
|
|
1542
|
+
edit = TextEdit.del(range);
|
|
1543
|
+
} else if (ChangeAnnotationIdentifier.is(annotation)) {
|
|
1544
|
+
id = annotation;
|
|
1545
|
+
edit = AnnotatedTextEdit.del(range, annotation);
|
|
1546
|
+
} else {
|
|
1547
|
+
this.assertChangeAnnotations(this.changeAnnotations);
|
|
1548
|
+
id = this.changeAnnotations.manage(annotation);
|
|
1549
|
+
edit = AnnotatedTextEdit.del(range, id);
|
|
1550
|
+
}
|
|
1551
|
+
this.edits.push(edit);
|
|
1552
|
+
if (id !== undefined) {
|
|
1553
|
+
return id;
|
|
1554
|
+
}
|
|
1555
|
+
}
|
|
1556
|
+
add(edit) {
|
|
1557
|
+
this.edits.push(edit);
|
|
1558
|
+
}
|
|
1559
|
+
all() {
|
|
1560
|
+
return this.edits;
|
|
1561
|
+
}
|
|
1562
|
+
clear() {
|
|
1563
|
+
this.edits.splice(0, this.edits.length);
|
|
1564
|
+
}
|
|
1565
|
+
assertChangeAnnotations(value) {
|
|
1566
|
+
if (value === undefined) {
|
|
1567
|
+
throw new Error(`Text edit change is not configured to manage change annotations.`);
|
|
1568
|
+
}
|
|
1569
|
+
}
|
|
1570
|
+
};
|
|
1571
|
+
/**
|
|
1572
|
+
* A helper class
|
|
1573
|
+
*/
|
|
1574
|
+
var ChangeAnnotations = class {
|
|
1575
|
+
constructor(annotations) {
|
|
1576
|
+
this._annotations = annotations === undefined ? Object.create(null) : annotations;
|
|
1577
|
+
this._counter = 0;
|
|
1578
|
+
this._size = 0;
|
|
1579
|
+
}
|
|
1580
|
+
all() {
|
|
1581
|
+
return this._annotations;
|
|
1582
|
+
}
|
|
1583
|
+
get size() {
|
|
1584
|
+
return this._size;
|
|
1585
|
+
}
|
|
1586
|
+
manage(idOrAnnotation, annotation) {
|
|
1587
|
+
let id;
|
|
1588
|
+
if (ChangeAnnotationIdentifier.is(idOrAnnotation)) {
|
|
1589
|
+
id = idOrAnnotation;
|
|
1590
|
+
} else {
|
|
1591
|
+
id = this.nextId();
|
|
1592
|
+
annotation = idOrAnnotation;
|
|
1593
|
+
}
|
|
1594
|
+
if (this._annotations[id] !== undefined) {
|
|
1595
|
+
throw new Error(`Id ${id} is already in use.`);
|
|
1596
|
+
}
|
|
1597
|
+
if (annotation === undefined) {
|
|
1598
|
+
throw new Error(`No annotation provided for id ${id}`);
|
|
1599
|
+
}
|
|
1600
|
+
this._annotations[id] = annotation;
|
|
1601
|
+
this._size++;
|
|
1602
|
+
return id;
|
|
1603
|
+
}
|
|
1604
|
+
nextId() {
|
|
1605
|
+
this._counter++;
|
|
1606
|
+
return this._counter.toString();
|
|
1607
|
+
}
|
|
1608
|
+
};
|
|
1609
|
+
/**
|
|
1610
|
+
* A workspace change helps constructing changes to a workspace.
|
|
1611
|
+
*/
|
|
1612
|
+
var WorkspaceChange = class {
|
|
1613
|
+
constructor(workspaceEdit) {
|
|
1614
|
+
this._textEditChanges = Object.create(null);
|
|
1615
|
+
if (workspaceEdit !== undefined) {
|
|
1616
|
+
this._workspaceEdit = workspaceEdit;
|
|
1617
|
+
if (workspaceEdit.documentChanges) {
|
|
1618
|
+
this._changeAnnotations = new ChangeAnnotations(workspaceEdit.changeAnnotations);
|
|
1619
|
+
workspaceEdit.changeAnnotations = this._changeAnnotations.all();
|
|
1620
|
+
workspaceEdit.documentChanges.forEach((change) => {
|
|
1621
|
+
if (TextDocumentEdit.is(change)) {
|
|
1622
|
+
const textEditChange = new TextEditChangeImpl(change.edits, this._changeAnnotations);
|
|
1623
|
+
this._textEditChanges[change.textDocument.uri] = textEditChange;
|
|
1624
|
+
}
|
|
1625
|
+
});
|
|
1626
|
+
} else if (workspaceEdit.changes) {
|
|
1627
|
+
Object.keys(workspaceEdit.changes).forEach((key) => {
|
|
1628
|
+
const textEditChange = new TextEditChangeImpl(workspaceEdit.changes[key]);
|
|
1629
|
+
this._textEditChanges[key] = textEditChange;
|
|
1630
|
+
});
|
|
1631
|
+
}
|
|
1632
|
+
} else {
|
|
1633
|
+
this._workspaceEdit = {};
|
|
1634
|
+
}
|
|
1635
|
+
}
|
|
1636
|
+
/**
|
|
1637
|
+
* Returns the underlying {@link WorkspaceEdit} literal
|
|
1638
|
+
* use to be returned from a workspace edit operation like rename.
|
|
1639
|
+
*/
|
|
1640
|
+
get edit() {
|
|
1641
|
+
this.initDocumentChanges();
|
|
1642
|
+
if (this._changeAnnotations !== undefined) {
|
|
1643
|
+
if (this._changeAnnotations.size === 0) {
|
|
1644
|
+
this._workspaceEdit.changeAnnotations = undefined;
|
|
1645
|
+
} else {
|
|
1646
|
+
this._workspaceEdit.changeAnnotations = this._changeAnnotations.all();
|
|
1647
|
+
}
|
|
1648
|
+
}
|
|
1649
|
+
return this._workspaceEdit;
|
|
1650
|
+
}
|
|
1651
|
+
getTextEditChange(key) {
|
|
1652
|
+
if (OptionalVersionedTextDocumentIdentifier.is(key)) {
|
|
1653
|
+
this.initDocumentChanges();
|
|
1654
|
+
if (this._workspaceEdit.documentChanges === undefined) {
|
|
1655
|
+
throw new Error("Workspace edit is not configured for document changes.");
|
|
1656
|
+
}
|
|
1657
|
+
const textDocument = {
|
|
1658
|
+
uri: key.uri,
|
|
1659
|
+
version: key.version
|
|
1660
|
+
};
|
|
1661
|
+
let result = this._textEditChanges[textDocument.uri];
|
|
1662
|
+
if (!result) {
|
|
1663
|
+
const edits = [];
|
|
1664
|
+
const textDocumentEdit = {
|
|
1665
|
+
textDocument,
|
|
1666
|
+
edits
|
|
1667
|
+
};
|
|
1668
|
+
this._workspaceEdit.documentChanges.push(textDocumentEdit);
|
|
1669
|
+
result = new TextEditChangeImpl(edits, this._changeAnnotations);
|
|
1670
|
+
this._textEditChanges[textDocument.uri] = result;
|
|
1671
|
+
}
|
|
1672
|
+
return result;
|
|
1673
|
+
} else {
|
|
1674
|
+
this.initChanges();
|
|
1675
|
+
if (this._workspaceEdit.changes === undefined) {
|
|
1676
|
+
throw new Error("Workspace edit is not configured for normal text edit changes.");
|
|
1677
|
+
}
|
|
1678
|
+
let result = this._textEditChanges[key];
|
|
1679
|
+
if (!result) {
|
|
1680
|
+
let edits = [];
|
|
1681
|
+
this._workspaceEdit.changes[key] = edits;
|
|
1682
|
+
result = new TextEditChangeImpl(edits);
|
|
1683
|
+
this._textEditChanges[key] = result;
|
|
1684
|
+
}
|
|
1685
|
+
return result;
|
|
1686
|
+
}
|
|
1687
|
+
}
|
|
1688
|
+
initDocumentChanges() {
|
|
1689
|
+
if (this._workspaceEdit.documentChanges === undefined && this._workspaceEdit.changes === undefined) {
|
|
1690
|
+
this._changeAnnotations = new ChangeAnnotations();
|
|
1691
|
+
this._workspaceEdit.documentChanges = [];
|
|
1692
|
+
this._workspaceEdit.changeAnnotations = this._changeAnnotations.all();
|
|
1693
|
+
}
|
|
1694
|
+
}
|
|
1695
|
+
initChanges() {
|
|
1696
|
+
if (this._workspaceEdit.documentChanges === undefined && this._workspaceEdit.changes === undefined) {
|
|
1697
|
+
this._workspaceEdit.changes = Object.create(null);
|
|
1698
|
+
}
|
|
1699
|
+
}
|
|
1700
|
+
createFile(uri, optionsOrAnnotation, options) {
|
|
1701
|
+
this.initDocumentChanges();
|
|
1702
|
+
if (this._workspaceEdit.documentChanges === undefined) {
|
|
1703
|
+
throw new Error("Workspace edit is not configured for document changes.");
|
|
1704
|
+
}
|
|
1705
|
+
let annotation;
|
|
1706
|
+
if (ChangeAnnotation.is(optionsOrAnnotation) || ChangeAnnotationIdentifier.is(optionsOrAnnotation)) {
|
|
1707
|
+
annotation = optionsOrAnnotation;
|
|
1708
|
+
} else {
|
|
1709
|
+
options = optionsOrAnnotation;
|
|
1710
|
+
}
|
|
1711
|
+
let operation;
|
|
1712
|
+
let id;
|
|
1713
|
+
if (annotation === undefined) {
|
|
1714
|
+
operation = CreateFile.create(uri, options);
|
|
1715
|
+
} else {
|
|
1716
|
+
id = ChangeAnnotationIdentifier.is(annotation) ? annotation : this._changeAnnotations.manage(annotation);
|
|
1717
|
+
operation = CreateFile.create(uri, options, id);
|
|
1718
|
+
}
|
|
1719
|
+
this._workspaceEdit.documentChanges.push(operation);
|
|
1720
|
+
if (id !== undefined) {
|
|
1721
|
+
return id;
|
|
1722
|
+
}
|
|
1723
|
+
}
|
|
1724
|
+
renameFile(oldUri, newUri, optionsOrAnnotation, options) {
|
|
1725
|
+
this.initDocumentChanges();
|
|
1726
|
+
if (this._workspaceEdit.documentChanges === undefined) {
|
|
1727
|
+
throw new Error("Workspace edit is not configured for document changes.");
|
|
1728
|
+
}
|
|
1729
|
+
let annotation;
|
|
1730
|
+
if (ChangeAnnotation.is(optionsOrAnnotation) || ChangeAnnotationIdentifier.is(optionsOrAnnotation)) {
|
|
1731
|
+
annotation = optionsOrAnnotation;
|
|
1732
|
+
} else {
|
|
1733
|
+
options = optionsOrAnnotation;
|
|
1734
|
+
}
|
|
1735
|
+
let operation;
|
|
1736
|
+
let id;
|
|
1737
|
+
if (annotation === undefined) {
|
|
1738
|
+
operation = RenameFile.create(oldUri, newUri, options);
|
|
1739
|
+
} else {
|
|
1740
|
+
id = ChangeAnnotationIdentifier.is(annotation) ? annotation : this._changeAnnotations.manage(annotation);
|
|
1741
|
+
operation = RenameFile.create(oldUri, newUri, options, id);
|
|
1742
|
+
}
|
|
1743
|
+
this._workspaceEdit.documentChanges.push(operation);
|
|
1744
|
+
if (id !== undefined) {
|
|
1745
|
+
return id;
|
|
1746
|
+
}
|
|
1747
|
+
}
|
|
1748
|
+
deleteFile(uri, optionsOrAnnotation, options) {
|
|
1749
|
+
this.initDocumentChanges();
|
|
1750
|
+
if (this._workspaceEdit.documentChanges === undefined) {
|
|
1751
|
+
throw new Error("Workspace edit is not configured for document changes.");
|
|
1752
|
+
}
|
|
1753
|
+
let annotation;
|
|
1754
|
+
if (ChangeAnnotation.is(optionsOrAnnotation) || ChangeAnnotationIdentifier.is(optionsOrAnnotation)) {
|
|
1755
|
+
annotation = optionsOrAnnotation;
|
|
1756
|
+
} else {
|
|
1757
|
+
options = optionsOrAnnotation;
|
|
1758
|
+
}
|
|
1759
|
+
let operation;
|
|
1760
|
+
let id;
|
|
1761
|
+
if (annotation === undefined) {
|
|
1762
|
+
operation = DeleteFile.create(uri, options);
|
|
1763
|
+
} else {
|
|
1764
|
+
id = ChangeAnnotationIdentifier.is(annotation) ? annotation : this._changeAnnotations.manage(annotation);
|
|
1765
|
+
operation = DeleteFile.create(uri, options, id);
|
|
1766
|
+
}
|
|
1767
|
+
this._workspaceEdit.documentChanges.push(operation);
|
|
1768
|
+
if (id !== undefined) {
|
|
1769
|
+
return id;
|
|
1770
|
+
}
|
|
1771
|
+
}
|
|
1772
|
+
};
|
|
1773
|
+
/**
|
|
1774
|
+
* The TextDocumentIdentifier namespace provides helper functions to work with
|
|
1775
|
+
* {@link TextDocumentIdentifier} literals.
|
|
1776
|
+
*/
|
|
1777
|
+
var TextDocumentIdentifier;
|
|
1778
|
+
(function(TextDocumentIdentifier$1) {
|
|
1779
|
+
/**
|
|
1780
|
+
* Creates a new TextDocumentIdentifier literal.
|
|
1781
|
+
* @param uri The document's uri.
|
|
1782
|
+
*/
|
|
1783
|
+
function create(uri) {
|
|
1784
|
+
return { uri };
|
|
1785
|
+
}
|
|
1786
|
+
TextDocumentIdentifier$1.create = create;
|
|
1787
|
+
/**
|
|
1788
|
+
* Checks whether the given literal conforms to the {@link TextDocumentIdentifier} interface.
|
|
1789
|
+
*/
|
|
1790
|
+
function is(value) {
|
|
1791
|
+
let candidate = value;
|
|
1792
|
+
return Is.defined(candidate) && Is.string(candidate.uri);
|
|
1793
|
+
}
|
|
1794
|
+
TextDocumentIdentifier$1.is = is;
|
|
1795
|
+
})(TextDocumentIdentifier || (TextDocumentIdentifier = {}));
|
|
1796
|
+
/**
|
|
1797
|
+
* The VersionedTextDocumentIdentifier namespace provides helper functions to work with
|
|
1798
|
+
* {@link VersionedTextDocumentIdentifier} literals.
|
|
1799
|
+
*/
|
|
1800
|
+
var VersionedTextDocumentIdentifier;
|
|
1801
|
+
(function(VersionedTextDocumentIdentifier$1) {
|
|
1802
|
+
/**
|
|
1803
|
+
* Creates a new VersionedTextDocumentIdentifier literal.
|
|
1804
|
+
* @param uri The document's uri.
|
|
1805
|
+
* @param version The document's version.
|
|
1806
|
+
*/
|
|
1807
|
+
function create(uri, version) {
|
|
1808
|
+
return {
|
|
1809
|
+
uri,
|
|
1810
|
+
version
|
|
1811
|
+
};
|
|
1812
|
+
}
|
|
1813
|
+
VersionedTextDocumentIdentifier$1.create = create;
|
|
1814
|
+
/**
|
|
1815
|
+
* Checks whether the given literal conforms to the {@link VersionedTextDocumentIdentifier} interface.
|
|
1816
|
+
*/
|
|
1817
|
+
function is(value) {
|
|
1818
|
+
let candidate = value;
|
|
1819
|
+
return Is.defined(candidate) && Is.string(candidate.uri) && Is.integer(candidate.version);
|
|
1820
|
+
}
|
|
1821
|
+
VersionedTextDocumentIdentifier$1.is = is;
|
|
1822
|
+
})(VersionedTextDocumentIdentifier || (VersionedTextDocumentIdentifier = {}));
|
|
1823
|
+
/**
|
|
1824
|
+
* The OptionalVersionedTextDocumentIdentifier namespace provides helper functions to work with
|
|
1825
|
+
* {@link OptionalVersionedTextDocumentIdentifier} literals.
|
|
1826
|
+
*/
|
|
1827
|
+
var OptionalVersionedTextDocumentIdentifier;
|
|
1828
|
+
(function(OptionalVersionedTextDocumentIdentifier$1) {
|
|
1829
|
+
/**
|
|
1830
|
+
* Creates a new OptionalVersionedTextDocumentIdentifier literal.
|
|
1831
|
+
* @param uri The document's uri.
|
|
1832
|
+
* @param version The document's version.
|
|
1833
|
+
*/
|
|
1834
|
+
function create(uri, version) {
|
|
1835
|
+
return {
|
|
1836
|
+
uri,
|
|
1837
|
+
version
|
|
1838
|
+
};
|
|
1839
|
+
}
|
|
1840
|
+
OptionalVersionedTextDocumentIdentifier$1.create = create;
|
|
1841
|
+
/**
|
|
1842
|
+
* Checks whether the given literal conforms to the {@link OptionalVersionedTextDocumentIdentifier} interface.
|
|
1843
|
+
*/
|
|
1844
|
+
function is(value) {
|
|
1845
|
+
let candidate = value;
|
|
1846
|
+
return Is.defined(candidate) && Is.string(candidate.uri) && (candidate.version === null || Is.integer(candidate.version));
|
|
1847
|
+
}
|
|
1848
|
+
OptionalVersionedTextDocumentIdentifier$1.is = is;
|
|
1849
|
+
})(OptionalVersionedTextDocumentIdentifier || (OptionalVersionedTextDocumentIdentifier = {}));
|
|
1850
|
+
/**
|
|
1851
|
+
* The TextDocumentItem namespace provides helper functions to work with
|
|
1852
|
+
* {@link TextDocumentItem} literals.
|
|
1853
|
+
*/
|
|
1854
|
+
var TextDocumentItem;
|
|
1855
|
+
(function(TextDocumentItem$1) {
|
|
1856
|
+
/**
|
|
1857
|
+
* Creates a new TextDocumentItem literal.
|
|
1858
|
+
* @param uri The document's uri.
|
|
1859
|
+
* @param languageId The document's language identifier.
|
|
1860
|
+
* @param version The document's version number.
|
|
1861
|
+
* @param text The document's text.
|
|
1862
|
+
*/
|
|
1863
|
+
function create(uri, languageId, version, text) {
|
|
1864
|
+
return {
|
|
1865
|
+
uri,
|
|
1866
|
+
languageId,
|
|
1867
|
+
version,
|
|
1868
|
+
text
|
|
1869
|
+
};
|
|
1870
|
+
}
|
|
1871
|
+
TextDocumentItem$1.create = create;
|
|
1872
|
+
/**
|
|
1873
|
+
* Checks whether the given literal conforms to the {@link TextDocumentItem} interface.
|
|
1874
|
+
*/
|
|
1875
|
+
function is(value) {
|
|
1876
|
+
let candidate = value;
|
|
1877
|
+
return Is.defined(candidate) && Is.string(candidate.uri) && Is.string(candidate.languageId) && Is.integer(candidate.version) && Is.string(candidate.text);
|
|
1878
|
+
}
|
|
1879
|
+
TextDocumentItem$1.is = is;
|
|
1880
|
+
})(TextDocumentItem || (TextDocumentItem = {}));
|
|
1881
|
+
/**
|
|
1882
|
+
* Describes the content type that a client supports in various
|
|
1883
|
+
* result literals like `Hover`, `ParameterInfo` or `CompletionItem`.
|
|
1884
|
+
*
|
|
1885
|
+
* Please note that `MarkupKinds` must not start with a `$`. This kinds
|
|
1886
|
+
* are reserved for internal usage.
|
|
1887
|
+
*/
|
|
1888
|
+
var MarkupKind;
|
|
1889
|
+
(function(MarkupKind$1) {
|
|
1890
|
+
/**
|
|
1891
|
+
* Plain text is supported as a content format
|
|
1892
|
+
*/
|
|
1893
|
+
MarkupKind$1.PlainText = "plaintext";
|
|
1894
|
+
/**
|
|
1895
|
+
* Markdown is supported as a content format
|
|
1896
|
+
*/
|
|
1897
|
+
MarkupKind$1.Markdown = "markdown";
|
|
1898
|
+
/**
|
|
1899
|
+
* Checks whether the given value is a value of the {@link MarkupKind} type.
|
|
1900
|
+
*/
|
|
1901
|
+
function is(value) {
|
|
1902
|
+
const candidate = value;
|
|
1903
|
+
return candidate === MarkupKind$1.PlainText || candidate === MarkupKind$1.Markdown;
|
|
1904
|
+
}
|
|
1905
|
+
MarkupKind$1.is = is;
|
|
1906
|
+
})(MarkupKind || (MarkupKind = {}));
|
|
1907
|
+
var MarkupContent;
|
|
1908
|
+
(function(MarkupContent$1) {
|
|
1909
|
+
/**
|
|
1910
|
+
* Checks whether the given value conforms to the {@link MarkupContent} interface.
|
|
1911
|
+
*/
|
|
1912
|
+
function is(value) {
|
|
1913
|
+
const candidate = value;
|
|
1914
|
+
return Is.objectLiteral(value) && MarkupKind.is(candidate.kind) && Is.string(candidate.value);
|
|
1915
|
+
}
|
|
1916
|
+
MarkupContent$1.is = is;
|
|
1917
|
+
})(MarkupContent || (MarkupContent = {}));
|
|
1918
|
+
/**
|
|
1919
|
+
* The kind of a completion entry.
|
|
1920
|
+
*/
|
|
1921
|
+
var CompletionItemKind;
|
|
1922
|
+
(function(CompletionItemKind$1) {
|
|
1923
|
+
CompletionItemKind$1.Text = 1;
|
|
1924
|
+
CompletionItemKind$1.Method = 2;
|
|
1925
|
+
CompletionItemKind$1.Function = 3;
|
|
1926
|
+
CompletionItemKind$1.Constructor = 4;
|
|
1927
|
+
CompletionItemKind$1.Field = 5;
|
|
1928
|
+
CompletionItemKind$1.Variable = 6;
|
|
1929
|
+
CompletionItemKind$1.Class = 7;
|
|
1930
|
+
CompletionItemKind$1.Interface = 8;
|
|
1931
|
+
CompletionItemKind$1.Module = 9;
|
|
1932
|
+
CompletionItemKind$1.Property = 10;
|
|
1933
|
+
CompletionItemKind$1.Unit = 11;
|
|
1934
|
+
CompletionItemKind$1.Value = 12;
|
|
1935
|
+
CompletionItemKind$1.Enum = 13;
|
|
1936
|
+
CompletionItemKind$1.Keyword = 14;
|
|
1937
|
+
CompletionItemKind$1.Snippet = 15;
|
|
1938
|
+
CompletionItemKind$1.Color = 16;
|
|
1939
|
+
CompletionItemKind$1.File = 17;
|
|
1940
|
+
CompletionItemKind$1.Reference = 18;
|
|
1941
|
+
CompletionItemKind$1.Folder = 19;
|
|
1942
|
+
CompletionItemKind$1.EnumMember = 20;
|
|
1943
|
+
CompletionItemKind$1.Constant = 21;
|
|
1944
|
+
CompletionItemKind$1.Struct = 22;
|
|
1945
|
+
CompletionItemKind$1.Event = 23;
|
|
1946
|
+
CompletionItemKind$1.Operator = 24;
|
|
1947
|
+
CompletionItemKind$1.TypeParameter = 25;
|
|
1948
|
+
})(CompletionItemKind || (CompletionItemKind = {}));
|
|
1949
|
+
/**
|
|
1950
|
+
* Defines whether the insert text in a completion item should be interpreted as
|
|
1951
|
+
* plain text or a snippet.
|
|
1952
|
+
*/
|
|
1953
|
+
var InsertTextFormat;
|
|
1954
|
+
(function(InsertTextFormat$1) {
|
|
1955
|
+
/**
|
|
1956
|
+
* The primary text to be inserted is treated as a plain string.
|
|
1957
|
+
*/
|
|
1958
|
+
InsertTextFormat$1.PlainText = 1;
|
|
1959
|
+
/**
|
|
1960
|
+
* The primary text to be inserted is treated as a snippet.
|
|
1961
|
+
*
|
|
1962
|
+
* A snippet can define tab stops and placeholders with `$1`, `$2`
|
|
1963
|
+
* and `${3:foo}`. `$0` defines the final tab stop, it defaults to
|
|
1964
|
+
* the end of the snippet. Placeholders with equal identifiers are linked,
|
|
1965
|
+
* that is typing in one will update others too.
|
|
1966
|
+
*
|
|
1967
|
+
* See also: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#snippet_syntax
|
|
1968
|
+
*/
|
|
1969
|
+
InsertTextFormat$1.Snippet = 2;
|
|
1970
|
+
})(InsertTextFormat || (InsertTextFormat = {}));
|
|
1971
|
+
/**
|
|
1972
|
+
* Completion item tags are extra annotations that tweak the rendering of a completion
|
|
1973
|
+
* item.
|
|
1974
|
+
*
|
|
1975
|
+
* @since 3.15.0
|
|
1976
|
+
*/
|
|
1977
|
+
var CompletionItemTag;
|
|
1978
|
+
(function(CompletionItemTag$1) {
|
|
1979
|
+
/**
|
|
1980
|
+
* Render a completion as obsolete, usually using a strike-out.
|
|
1981
|
+
*/
|
|
1982
|
+
CompletionItemTag$1.Deprecated = 1;
|
|
1983
|
+
})(CompletionItemTag || (CompletionItemTag = {}));
|
|
1984
|
+
/**
|
|
1985
|
+
* The InsertReplaceEdit namespace provides functions to deal with insert / replace edits.
|
|
1986
|
+
*
|
|
1987
|
+
* @since 3.16.0
|
|
1988
|
+
*/
|
|
1989
|
+
var InsertReplaceEdit;
|
|
1990
|
+
(function(InsertReplaceEdit$1) {
|
|
1991
|
+
/**
|
|
1992
|
+
* Creates a new insert / replace edit
|
|
1993
|
+
*/
|
|
1994
|
+
function create(newText, insert, replace) {
|
|
1995
|
+
return {
|
|
1996
|
+
newText,
|
|
1997
|
+
insert,
|
|
1998
|
+
replace
|
|
1999
|
+
};
|
|
2000
|
+
}
|
|
2001
|
+
InsertReplaceEdit$1.create = create;
|
|
2002
|
+
/**
|
|
2003
|
+
* Checks whether the given literal conforms to the {@link InsertReplaceEdit} interface.
|
|
2004
|
+
*/
|
|
2005
|
+
function is(value) {
|
|
2006
|
+
const candidate = value;
|
|
2007
|
+
return candidate && Is.string(candidate.newText) && Range.is(candidate.insert) && Range.is(candidate.replace);
|
|
2008
|
+
}
|
|
2009
|
+
InsertReplaceEdit$1.is = is;
|
|
2010
|
+
})(InsertReplaceEdit || (InsertReplaceEdit = {}));
|
|
2011
|
+
/**
|
|
2012
|
+
* How whitespace and indentation is handled during completion
|
|
2013
|
+
* item insertion.
|
|
2014
|
+
*
|
|
2015
|
+
* @since 3.16.0
|
|
2016
|
+
*/
|
|
2017
|
+
var InsertTextMode;
|
|
2018
|
+
(function(InsertTextMode$1) {
|
|
2019
|
+
/**
|
|
2020
|
+
* The insertion or replace strings is taken as it is. If the
|
|
2021
|
+
* value is multi line the lines below the cursor will be
|
|
2022
|
+
* inserted using the indentation defined in the string value.
|
|
2023
|
+
* The client will not apply any kind of adjustments to the
|
|
2024
|
+
* string.
|
|
2025
|
+
*/
|
|
2026
|
+
InsertTextMode$1.asIs = 1;
|
|
2027
|
+
/**
|
|
2028
|
+
* The editor adjusts leading whitespace of new lines so that
|
|
2029
|
+
* they match the indentation up to the cursor of the line for
|
|
2030
|
+
* which the item is accepted.
|
|
2031
|
+
*
|
|
2032
|
+
* Consider a line like this: <2tabs><cursor><3tabs>foo. Accepting a
|
|
2033
|
+
* multi line completion item is indented using 2 tabs and all
|
|
2034
|
+
* following lines inserted will be indented using 2 tabs as well.
|
|
2035
|
+
*/
|
|
2036
|
+
InsertTextMode$1.adjustIndentation = 2;
|
|
2037
|
+
})(InsertTextMode || (InsertTextMode = {}));
|
|
2038
|
+
var CompletionItemLabelDetails;
|
|
2039
|
+
(function(CompletionItemLabelDetails$1) {
|
|
2040
|
+
function is(value) {
|
|
2041
|
+
const candidate = value;
|
|
2042
|
+
return candidate && (Is.string(candidate.detail) || candidate.detail === undefined) && (Is.string(candidate.description) || candidate.description === undefined);
|
|
2043
|
+
}
|
|
2044
|
+
CompletionItemLabelDetails$1.is = is;
|
|
2045
|
+
})(CompletionItemLabelDetails || (CompletionItemLabelDetails = {}));
|
|
2046
|
+
/**
|
|
2047
|
+
* The CompletionItem namespace provides functions to deal with
|
|
2048
|
+
* completion items.
|
|
2049
|
+
*/
|
|
2050
|
+
var CompletionItem;
|
|
2051
|
+
(function(CompletionItem$1) {
|
|
2052
|
+
/**
|
|
2053
|
+
* Create a completion item and seed it with a label.
|
|
2054
|
+
* @param label The completion item's label
|
|
2055
|
+
*/
|
|
2056
|
+
function create(label) {
|
|
2057
|
+
return { label };
|
|
2058
|
+
}
|
|
2059
|
+
CompletionItem$1.create = create;
|
|
2060
|
+
})(CompletionItem || (CompletionItem = {}));
|
|
2061
|
+
/**
|
|
2062
|
+
* The CompletionList namespace provides functions to deal with
|
|
2063
|
+
* completion lists.
|
|
2064
|
+
*/
|
|
2065
|
+
var CompletionList;
|
|
2066
|
+
(function(CompletionList$1) {
|
|
2067
|
+
/**
|
|
2068
|
+
* Creates a new completion list.
|
|
2069
|
+
*
|
|
2070
|
+
* @param items The completion items.
|
|
2071
|
+
* @param isIncomplete The list is not complete.
|
|
2072
|
+
*/
|
|
2073
|
+
function create(items, isIncomplete) {
|
|
2074
|
+
return {
|
|
2075
|
+
items: items ? items : [],
|
|
2076
|
+
isIncomplete: !!isIncomplete
|
|
2077
|
+
};
|
|
2078
|
+
}
|
|
2079
|
+
CompletionList$1.create = create;
|
|
2080
|
+
})(CompletionList || (CompletionList = {}));
|
|
2081
|
+
var MarkedString;
|
|
2082
|
+
(function(MarkedString$1) {
|
|
2083
|
+
/**
|
|
2084
|
+
* Creates a marked string from plain text.
|
|
2085
|
+
*
|
|
2086
|
+
* @param plainText The plain text.
|
|
2087
|
+
*/
|
|
2088
|
+
function fromPlainText(plainText) {
|
|
2089
|
+
return plainText.replace(/[\\`*_{}[\]()#+\-.!]/g, "\\$&");
|
|
2090
|
+
}
|
|
2091
|
+
MarkedString$1.fromPlainText = fromPlainText;
|
|
2092
|
+
/**
|
|
2093
|
+
* Checks whether the given value conforms to the {@link MarkedString} type.
|
|
2094
|
+
*/
|
|
2095
|
+
function is(value) {
|
|
2096
|
+
const candidate = value;
|
|
2097
|
+
return Is.string(candidate) || Is.objectLiteral(candidate) && Is.string(candidate.language) && Is.string(candidate.value);
|
|
2098
|
+
}
|
|
2099
|
+
MarkedString$1.is = is;
|
|
2100
|
+
})(MarkedString || (MarkedString = {}));
|
|
2101
|
+
var Hover;
|
|
2102
|
+
(function(Hover$1) {
|
|
2103
|
+
/**
|
|
2104
|
+
* Checks whether the given value conforms to the {@link Hover} interface.
|
|
2105
|
+
*/
|
|
2106
|
+
function is(value) {
|
|
2107
|
+
let candidate = value;
|
|
2108
|
+
return !!candidate && Is.objectLiteral(candidate) && (MarkupContent.is(candidate.contents) || MarkedString.is(candidate.contents) || Is.typedArray(candidate.contents, MarkedString.is)) && (value.range === undefined || Range.is(value.range));
|
|
2109
|
+
}
|
|
2110
|
+
Hover$1.is = is;
|
|
2111
|
+
})(Hover || (Hover = {}));
|
|
2112
|
+
/**
|
|
2113
|
+
* The ParameterInformation namespace provides helper functions to work with
|
|
2114
|
+
* {@link ParameterInformation} literals.
|
|
2115
|
+
*/
|
|
2116
|
+
var ParameterInformation;
|
|
2117
|
+
(function(ParameterInformation$1) {
|
|
2118
|
+
/**
|
|
2119
|
+
* Creates a new parameter information literal.
|
|
2120
|
+
*
|
|
2121
|
+
* @param label A label string.
|
|
2122
|
+
* @param documentation A doc string.
|
|
2123
|
+
*/
|
|
2124
|
+
function create(label, documentation) {
|
|
2125
|
+
return documentation ? {
|
|
2126
|
+
label,
|
|
2127
|
+
documentation
|
|
2128
|
+
} : { label };
|
|
2129
|
+
}
|
|
2130
|
+
ParameterInformation$1.create = create;
|
|
2131
|
+
})(ParameterInformation || (ParameterInformation = {}));
|
|
2132
|
+
/**
|
|
2133
|
+
* The SignatureInformation namespace provides helper functions to work with
|
|
2134
|
+
* {@link SignatureInformation} literals.
|
|
2135
|
+
*/
|
|
2136
|
+
var SignatureInformation;
|
|
2137
|
+
(function(SignatureInformation$1) {
|
|
2138
|
+
function create(label, documentation, ...parameters) {
|
|
2139
|
+
let result = { label };
|
|
2140
|
+
if (Is.defined(documentation)) {
|
|
2141
|
+
result.documentation = documentation;
|
|
2142
|
+
}
|
|
2143
|
+
if (Is.defined(parameters)) {
|
|
2144
|
+
result.parameters = parameters;
|
|
2145
|
+
} else {
|
|
2146
|
+
result.parameters = [];
|
|
2147
|
+
}
|
|
2148
|
+
return result;
|
|
2149
|
+
}
|
|
2150
|
+
SignatureInformation$1.create = create;
|
|
2151
|
+
})(SignatureInformation || (SignatureInformation = {}));
|
|
2152
|
+
/**
|
|
2153
|
+
* A document highlight kind.
|
|
2154
|
+
*/
|
|
2155
|
+
var DocumentHighlightKind;
|
|
2156
|
+
(function(DocumentHighlightKind$1) {
|
|
2157
|
+
/**
|
|
2158
|
+
* A textual occurrence.
|
|
2159
|
+
*/
|
|
2160
|
+
DocumentHighlightKind$1.Text = 1;
|
|
2161
|
+
/**
|
|
2162
|
+
* Read-access of a symbol, like reading a variable.
|
|
2163
|
+
*/
|
|
2164
|
+
DocumentHighlightKind$1.Read = 2;
|
|
2165
|
+
/**
|
|
2166
|
+
* Write-access of a symbol, like writing to a variable.
|
|
2167
|
+
*/
|
|
2168
|
+
DocumentHighlightKind$1.Write = 3;
|
|
2169
|
+
})(DocumentHighlightKind || (DocumentHighlightKind = {}));
|
|
2170
|
+
/**
|
|
2171
|
+
* DocumentHighlight namespace to provide helper functions to work with
|
|
2172
|
+
* {@link DocumentHighlight} literals.
|
|
2173
|
+
*/
|
|
2174
|
+
var DocumentHighlight;
|
|
2175
|
+
(function(DocumentHighlight$1) {
|
|
2176
|
+
/**
|
|
2177
|
+
* Create a DocumentHighlight object.
|
|
2178
|
+
* @param range The range the highlight applies to.
|
|
2179
|
+
* @param kind The highlight kind
|
|
2180
|
+
*/
|
|
2181
|
+
function create(range, kind) {
|
|
2182
|
+
let result = { range };
|
|
2183
|
+
if (Is.number(kind)) {
|
|
2184
|
+
result.kind = kind;
|
|
2185
|
+
}
|
|
2186
|
+
return result;
|
|
2187
|
+
}
|
|
2188
|
+
DocumentHighlight$1.create = create;
|
|
2189
|
+
})(DocumentHighlight || (DocumentHighlight = {}));
|
|
2190
|
+
/**
|
|
2191
|
+
* A symbol kind.
|
|
2192
|
+
*/
|
|
2193
|
+
var SymbolKind;
|
|
2194
|
+
(function(SymbolKind$1) {
|
|
2195
|
+
SymbolKind$1.File = 1;
|
|
2196
|
+
SymbolKind$1.Module = 2;
|
|
2197
|
+
SymbolKind$1.Namespace = 3;
|
|
2198
|
+
SymbolKind$1.Package = 4;
|
|
2199
|
+
SymbolKind$1.Class = 5;
|
|
2200
|
+
SymbolKind$1.Method = 6;
|
|
2201
|
+
SymbolKind$1.Property = 7;
|
|
2202
|
+
SymbolKind$1.Field = 8;
|
|
2203
|
+
SymbolKind$1.Constructor = 9;
|
|
2204
|
+
SymbolKind$1.Enum = 10;
|
|
2205
|
+
SymbolKind$1.Interface = 11;
|
|
2206
|
+
SymbolKind$1.Function = 12;
|
|
2207
|
+
SymbolKind$1.Variable = 13;
|
|
2208
|
+
SymbolKind$1.Constant = 14;
|
|
2209
|
+
SymbolKind$1.String = 15;
|
|
2210
|
+
SymbolKind$1.Number = 16;
|
|
2211
|
+
SymbolKind$1.Boolean = 17;
|
|
2212
|
+
SymbolKind$1.Array = 18;
|
|
2213
|
+
SymbolKind$1.Object = 19;
|
|
2214
|
+
SymbolKind$1.Key = 20;
|
|
2215
|
+
SymbolKind$1.Null = 21;
|
|
2216
|
+
SymbolKind$1.EnumMember = 22;
|
|
2217
|
+
SymbolKind$1.Struct = 23;
|
|
2218
|
+
SymbolKind$1.Event = 24;
|
|
2219
|
+
SymbolKind$1.Operator = 25;
|
|
2220
|
+
SymbolKind$1.TypeParameter = 26;
|
|
2221
|
+
})(SymbolKind || (SymbolKind = {}));
|
|
2222
|
+
/**
|
|
2223
|
+
* Symbol tags are extra annotations that tweak the rendering of a symbol.
|
|
2224
|
+
*
|
|
2225
|
+
* @since 3.16
|
|
2226
|
+
*/
|
|
2227
|
+
var SymbolTag;
|
|
2228
|
+
(function(SymbolTag$1) {
|
|
2229
|
+
/**
|
|
2230
|
+
* Render a symbol as obsolete, usually using a strike-out.
|
|
2231
|
+
*/
|
|
2232
|
+
SymbolTag$1.Deprecated = 1;
|
|
2233
|
+
})(SymbolTag || (SymbolTag = {}));
|
|
2234
|
+
var SymbolInformation;
|
|
2235
|
+
(function(SymbolInformation$1) {
|
|
2236
|
+
/**
|
|
2237
|
+
* Creates a new symbol information literal.
|
|
2238
|
+
*
|
|
2239
|
+
* @param name The name of the symbol.
|
|
2240
|
+
* @param kind The kind of the symbol.
|
|
2241
|
+
* @param range The range of the location of the symbol.
|
|
2242
|
+
* @param uri The resource of the location of symbol.
|
|
2243
|
+
* @param containerName The name of the symbol containing the symbol.
|
|
2244
|
+
*/
|
|
2245
|
+
function create(name, kind, range, uri, containerName) {
|
|
2246
|
+
let result = {
|
|
2247
|
+
name,
|
|
2248
|
+
kind,
|
|
2249
|
+
location: {
|
|
2250
|
+
uri,
|
|
2251
|
+
range
|
|
2252
|
+
}
|
|
2253
|
+
};
|
|
2254
|
+
if (containerName) {
|
|
2255
|
+
result.containerName = containerName;
|
|
2256
|
+
}
|
|
2257
|
+
return result;
|
|
2258
|
+
}
|
|
2259
|
+
SymbolInformation$1.create = create;
|
|
2260
|
+
})(SymbolInformation || (SymbolInformation = {}));
|
|
2261
|
+
var WorkspaceSymbol;
|
|
2262
|
+
(function(WorkspaceSymbol$1) {
|
|
2263
|
+
/**
|
|
2264
|
+
* Create a new workspace symbol.
|
|
2265
|
+
*
|
|
2266
|
+
* @param name The name of the symbol.
|
|
2267
|
+
* @param kind The kind of the symbol.
|
|
2268
|
+
* @param uri The resource of the location of the symbol.
|
|
2269
|
+
* @param range An options range of the location.
|
|
2270
|
+
* @returns A WorkspaceSymbol.
|
|
2271
|
+
*/
|
|
2272
|
+
function create(name, kind, uri, range) {
|
|
2273
|
+
return range !== undefined ? {
|
|
2274
|
+
name,
|
|
2275
|
+
kind,
|
|
2276
|
+
location: {
|
|
2277
|
+
uri,
|
|
2278
|
+
range
|
|
2279
|
+
}
|
|
2280
|
+
} : {
|
|
2281
|
+
name,
|
|
2282
|
+
kind,
|
|
2283
|
+
location: { uri }
|
|
2284
|
+
};
|
|
2285
|
+
}
|
|
2286
|
+
WorkspaceSymbol$1.create = create;
|
|
2287
|
+
})(WorkspaceSymbol || (WorkspaceSymbol = {}));
|
|
2288
|
+
var DocumentSymbol;
|
|
2289
|
+
(function(DocumentSymbol$1) {
|
|
2290
|
+
/**
|
|
2291
|
+
* Creates a new symbol information literal.
|
|
2292
|
+
*
|
|
2293
|
+
* @param name The name of the symbol.
|
|
2294
|
+
* @param detail The detail of the symbol.
|
|
2295
|
+
* @param kind The kind of the symbol.
|
|
2296
|
+
* @param range The range of the symbol.
|
|
2297
|
+
* @param selectionRange The selectionRange of the symbol.
|
|
2298
|
+
* @param children Children of the symbol.
|
|
2299
|
+
*/
|
|
2300
|
+
function create(name, detail, kind, range, selectionRange, children) {
|
|
2301
|
+
let result = {
|
|
2302
|
+
name,
|
|
2303
|
+
detail,
|
|
2304
|
+
kind,
|
|
2305
|
+
range,
|
|
2306
|
+
selectionRange
|
|
2307
|
+
};
|
|
2308
|
+
if (children !== undefined) {
|
|
2309
|
+
result.children = children;
|
|
2310
|
+
}
|
|
2311
|
+
return result;
|
|
2312
|
+
}
|
|
2313
|
+
DocumentSymbol$1.create = create;
|
|
2314
|
+
/**
|
|
2315
|
+
* Checks whether the given literal conforms to the {@link DocumentSymbol} interface.
|
|
2316
|
+
*/
|
|
2317
|
+
function is(value) {
|
|
2318
|
+
let candidate = value;
|
|
2319
|
+
return candidate && Is.string(candidate.name) && Is.number(candidate.kind) && Range.is(candidate.range) && Range.is(candidate.selectionRange) && (candidate.detail === undefined || Is.string(candidate.detail)) && (candidate.deprecated === undefined || Is.boolean(candidate.deprecated)) && (candidate.children === undefined || Array.isArray(candidate.children)) && (candidate.tags === undefined || Array.isArray(candidate.tags));
|
|
2320
|
+
}
|
|
2321
|
+
DocumentSymbol$1.is = is;
|
|
2322
|
+
})(DocumentSymbol || (DocumentSymbol = {}));
|
|
2323
|
+
/**
|
|
2324
|
+
* A set of predefined code action kinds
|
|
2325
|
+
*/
|
|
2326
|
+
var CodeActionKind;
|
|
2327
|
+
(function(CodeActionKind$1) {
|
|
2328
|
+
/**
|
|
2329
|
+
* Empty kind.
|
|
2330
|
+
*/
|
|
2331
|
+
CodeActionKind$1.Empty = "";
|
|
2332
|
+
/**
|
|
2333
|
+
* Base kind for quickfix actions: 'quickfix'
|
|
2334
|
+
*/
|
|
2335
|
+
CodeActionKind$1.QuickFix = "quickfix";
|
|
2336
|
+
/**
|
|
2337
|
+
* Base kind for refactoring actions: 'refactor'
|
|
2338
|
+
*/
|
|
2339
|
+
CodeActionKind$1.Refactor = "refactor";
|
|
2340
|
+
/**
|
|
2341
|
+
* Base kind for refactoring extraction actions: 'refactor.extract'
|
|
2342
|
+
*
|
|
2343
|
+
* Example extract actions:
|
|
2344
|
+
*
|
|
2345
|
+
* - Extract method
|
|
2346
|
+
* - Extract function
|
|
2347
|
+
* - Extract variable
|
|
2348
|
+
* - Extract interface from class
|
|
2349
|
+
* - ...
|
|
2350
|
+
*/
|
|
2351
|
+
CodeActionKind$1.RefactorExtract = "refactor.extract";
|
|
2352
|
+
/**
|
|
2353
|
+
* Base kind for refactoring inline actions: 'refactor.inline'
|
|
2354
|
+
*
|
|
2355
|
+
* Example inline actions:
|
|
2356
|
+
*
|
|
2357
|
+
* - Inline function
|
|
2358
|
+
* - Inline variable
|
|
2359
|
+
* - Inline constant
|
|
2360
|
+
* - ...
|
|
2361
|
+
*/
|
|
2362
|
+
CodeActionKind$1.RefactorInline = "refactor.inline";
|
|
2363
|
+
/**
|
|
2364
|
+
* Base kind for refactoring rewrite actions: 'refactor.rewrite'
|
|
2365
|
+
*
|
|
2366
|
+
* Example rewrite actions:
|
|
2367
|
+
*
|
|
2368
|
+
* - Convert JavaScript function to class
|
|
2369
|
+
* - Add or remove parameter
|
|
2370
|
+
* - Encapsulate field
|
|
2371
|
+
* - Make method static
|
|
2372
|
+
* - Move method to base class
|
|
2373
|
+
* - ...
|
|
2374
|
+
*/
|
|
2375
|
+
CodeActionKind$1.RefactorRewrite = "refactor.rewrite";
|
|
2376
|
+
/**
|
|
2377
|
+
* Base kind for source actions: `source`
|
|
2378
|
+
*
|
|
2379
|
+
* Source code actions apply to the entire file.
|
|
2380
|
+
*/
|
|
2381
|
+
CodeActionKind$1.Source = "source";
|
|
2382
|
+
/**
|
|
2383
|
+
* Base kind for an organize imports source action: `source.organizeImports`
|
|
2384
|
+
*/
|
|
2385
|
+
CodeActionKind$1.SourceOrganizeImports = "source.organizeImports";
|
|
2386
|
+
/**
|
|
2387
|
+
* Base kind for auto-fix source actions: `source.fixAll`.
|
|
2388
|
+
*
|
|
2389
|
+
* Fix all actions automatically fix errors that have a clear fix that do not require user input.
|
|
2390
|
+
* They should not suppress errors or perform unsafe fixes such as generating new types or classes.
|
|
2391
|
+
*
|
|
2392
|
+
* @since 3.15.0
|
|
2393
|
+
*/
|
|
2394
|
+
CodeActionKind$1.SourceFixAll = "source.fixAll";
|
|
2395
|
+
})(CodeActionKind || (CodeActionKind = {}));
|
|
2396
|
+
/**
|
|
2397
|
+
* The reason why code actions were requested.
|
|
2398
|
+
*
|
|
2399
|
+
* @since 3.17.0
|
|
2400
|
+
*/
|
|
2401
|
+
var CodeActionTriggerKind;
|
|
2402
|
+
(function(CodeActionTriggerKind$1) {
|
|
2403
|
+
/**
|
|
2404
|
+
* Code actions were explicitly requested by the user or by an extension.
|
|
2405
|
+
*/
|
|
2406
|
+
CodeActionTriggerKind$1.Invoked = 1;
|
|
2407
|
+
/**
|
|
2408
|
+
* Code actions were requested automatically.
|
|
2409
|
+
*
|
|
2410
|
+
* This typically happens when current selection in a file changes, but can
|
|
2411
|
+
* also be triggered when file content changes.
|
|
2412
|
+
*/
|
|
2413
|
+
CodeActionTriggerKind$1.Automatic = 2;
|
|
2414
|
+
})(CodeActionTriggerKind || (CodeActionTriggerKind = {}));
|
|
2415
|
+
/**
|
|
2416
|
+
* The CodeActionContext namespace provides helper functions to work with
|
|
2417
|
+
* {@link CodeActionContext} literals.
|
|
2418
|
+
*/
|
|
2419
|
+
var CodeActionContext;
|
|
2420
|
+
(function(CodeActionContext$1) {
|
|
2421
|
+
/**
|
|
2422
|
+
* Creates a new CodeActionContext literal.
|
|
2423
|
+
*/
|
|
2424
|
+
function create(diagnostics, only, triggerKind) {
|
|
2425
|
+
let result = { diagnostics };
|
|
2426
|
+
if (only !== undefined && only !== null) {
|
|
2427
|
+
result.only = only;
|
|
2428
|
+
}
|
|
2429
|
+
if (triggerKind !== undefined && triggerKind !== null) {
|
|
2430
|
+
result.triggerKind = triggerKind;
|
|
2431
|
+
}
|
|
2432
|
+
return result;
|
|
2433
|
+
}
|
|
2434
|
+
CodeActionContext$1.create = create;
|
|
2435
|
+
/**
|
|
2436
|
+
* Checks whether the given literal conforms to the {@link CodeActionContext} interface.
|
|
2437
|
+
*/
|
|
2438
|
+
function is(value) {
|
|
2439
|
+
let candidate = value;
|
|
2440
|
+
return Is.defined(candidate) && Is.typedArray(candidate.diagnostics, Diagnostic.is) && (candidate.only === undefined || Is.typedArray(candidate.only, Is.string)) && (candidate.triggerKind === undefined || candidate.triggerKind === CodeActionTriggerKind.Invoked || candidate.triggerKind === CodeActionTriggerKind.Automatic);
|
|
2441
|
+
}
|
|
2442
|
+
CodeActionContext$1.is = is;
|
|
2443
|
+
})(CodeActionContext || (CodeActionContext = {}));
|
|
2444
|
+
var CodeAction;
|
|
2445
|
+
(function(CodeAction$1) {
|
|
2446
|
+
function create(title, kindOrCommandOrEdit, kind) {
|
|
2447
|
+
let result = { title };
|
|
2448
|
+
let checkKind = true;
|
|
2449
|
+
if (typeof kindOrCommandOrEdit === "string") {
|
|
2450
|
+
checkKind = false;
|
|
2451
|
+
result.kind = kindOrCommandOrEdit;
|
|
2452
|
+
} else if (Command.is(kindOrCommandOrEdit)) {
|
|
2453
|
+
result.command = kindOrCommandOrEdit;
|
|
2454
|
+
} else {
|
|
2455
|
+
result.edit = kindOrCommandOrEdit;
|
|
2456
|
+
}
|
|
2457
|
+
if (checkKind && kind !== undefined) {
|
|
2458
|
+
result.kind = kind;
|
|
2459
|
+
}
|
|
2460
|
+
return result;
|
|
2461
|
+
}
|
|
2462
|
+
CodeAction$1.create = create;
|
|
2463
|
+
function is(value) {
|
|
2464
|
+
let candidate = value;
|
|
2465
|
+
return candidate && Is.string(candidate.title) && (candidate.diagnostics === undefined || Is.typedArray(candidate.diagnostics, Diagnostic.is)) && (candidate.kind === undefined || Is.string(candidate.kind)) && (candidate.edit !== undefined || candidate.command !== undefined) && (candidate.command === undefined || Command.is(candidate.command)) && (candidate.isPreferred === undefined || Is.boolean(candidate.isPreferred)) && (candidate.edit === undefined || WorkspaceEdit.is(candidate.edit));
|
|
2466
|
+
}
|
|
2467
|
+
CodeAction$1.is = is;
|
|
2468
|
+
})(CodeAction || (CodeAction = {}));
|
|
2469
|
+
/**
|
|
2470
|
+
* The CodeLens namespace provides helper functions to work with
|
|
2471
|
+
* {@link CodeLens} literals.
|
|
2472
|
+
*/
|
|
2473
|
+
var CodeLens;
|
|
2474
|
+
(function(CodeLens$1) {
|
|
2475
|
+
/**
|
|
2476
|
+
* Creates a new CodeLens literal.
|
|
2477
|
+
*/
|
|
2478
|
+
function create(range, data) {
|
|
2479
|
+
let result = { range };
|
|
2480
|
+
if (Is.defined(data)) {
|
|
2481
|
+
result.data = data;
|
|
2482
|
+
}
|
|
2483
|
+
return result;
|
|
2484
|
+
}
|
|
2485
|
+
CodeLens$1.create = create;
|
|
2486
|
+
/**
|
|
2487
|
+
* Checks whether the given literal conforms to the {@link CodeLens} interface.
|
|
2488
|
+
*/
|
|
2489
|
+
function is(value) {
|
|
2490
|
+
let candidate = value;
|
|
2491
|
+
return Is.defined(candidate) && Range.is(candidate.range) && (Is.undefined(candidate.command) || Command.is(candidate.command));
|
|
2492
|
+
}
|
|
2493
|
+
CodeLens$1.is = is;
|
|
2494
|
+
})(CodeLens || (CodeLens = {}));
|
|
2495
|
+
/**
|
|
2496
|
+
* The FormattingOptions namespace provides helper functions to work with
|
|
2497
|
+
* {@link FormattingOptions} literals.
|
|
2498
|
+
*/
|
|
2499
|
+
var FormattingOptions;
|
|
2500
|
+
(function(FormattingOptions$1) {
|
|
2501
|
+
/**
|
|
2502
|
+
* Creates a new FormattingOptions literal.
|
|
2503
|
+
*/
|
|
2504
|
+
function create(tabSize, insertSpaces) {
|
|
2505
|
+
return {
|
|
2506
|
+
tabSize,
|
|
2507
|
+
insertSpaces
|
|
2508
|
+
};
|
|
2509
|
+
}
|
|
2510
|
+
FormattingOptions$1.create = create;
|
|
2511
|
+
/**
|
|
2512
|
+
* Checks whether the given literal conforms to the {@link FormattingOptions} interface.
|
|
2513
|
+
*/
|
|
2514
|
+
function is(value) {
|
|
2515
|
+
let candidate = value;
|
|
2516
|
+
return Is.defined(candidate) && Is.uinteger(candidate.tabSize) && Is.boolean(candidate.insertSpaces);
|
|
2517
|
+
}
|
|
2518
|
+
FormattingOptions$1.is = is;
|
|
2519
|
+
})(FormattingOptions || (FormattingOptions = {}));
|
|
2520
|
+
/**
|
|
2521
|
+
* The DocumentLink namespace provides helper functions to work with
|
|
2522
|
+
* {@link DocumentLink} literals.
|
|
2523
|
+
*/
|
|
2524
|
+
var DocumentLink;
|
|
2525
|
+
(function(DocumentLink$1) {
|
|
2526
|
+
/**
|
|
2527
|
+
* Creates a new DocumentLink literal.
|
|
2528
|
+
*/
|
|
2529
|
+
function create(range, target, data) {
|
|
2530
|
+
return {
|
|
2531
|
+
range,
|
|
2532
|
+
target,
|
|
2533
|
+
data
|
|
2534
|
+
};
|
|
2535
|
+
}
|
|
2536
|
+
DocumentLink$1.create = create;
|
|
2537
|
+
/**
|
|
2538
|
+
* Checks whether the given literal conforms to the {@link DocumentLink} interface.
|
|
2539
|
+
*/
|
|
2540
|
+
function is(value) {
|
|
2541
|
+
let candidate = value;
|
|
2542
|
+
return Is.defined(candidate) && Range.is(candidate.range) && (Is.undefined(candidate.target) || Is.string(candidate.target));
|
|
2543
|
+
}
|
|
2544
|
+
DocumentLink$1.is = is;
|
|
2545
|
+
})(DocumentLink || (DocumentLink = {}));
|
|
2546
|
+
/**
|
|
2547
|
+
* The SelectionRange namespace provides helper function to work with
|
|
2548
|
+
* SelectionRange literals.
|
|
2549
|
+
*/
|
|
2550
|
+
var SelectionRange;
|
|
2551
|
+
(function(SelectionRange$1) {
|
|
2552
|
+
/**
|
|
2553
|
+
* Creates a new SelectionRange
|
|
2554
|
+
* @param range the range.
|
|
2555
|
+
* @param parent an optional parent.
|
|
2556
|
+
*/
|
|
2557
|
+
function create(range, parent) {
|
|
2558
|
+
return {
|
|
2559
|
+
range,
|
|
2560
|
+
parent
|
|
2561
|
+
};
|
|
2562
|
+
}
|
|
2563
|
+
SelectionRange$1.create = create;
|
|
2564
|
+
function is(value) {
|
|
2565
|
+
let candidate = value;
|
|
2566
|
+
return Is.objectLiteral(candidate) && Range.is(candidate.range) && (candidate.parent === undefined || SelectionRange$1.is(candidate.parent));
|
|
2567
|
+
}
|
|
2568
|
+
SelectionRange$1.is = is;
|
|
2569
|
+
})(SelectionRange || (SelectionRange = {}));
|
|
2570
|
+
/**
|
|
2571
|
+
* A set of predefined token types. This set is not fixed
|
|
2572
|
+
* an clients can specify additional token types via the
|
|
2573
|
+
* corresponding client capabilities.
|
|
2574
|
+
*
|
|
2575
|
+
* @since 3.16.0
|
|
2576
|
+
*/
|
|
2577
|
+
var SemanticTokenTypes;
|
|
2578
|
+
(function(SemanticTokenTypes$1) {
|
|
2579
|
+
SemanticTokenTypes$1["namespace"] = "namespace";
|
|
2580
|
+
/**
|
|
2581
|
+
* Represents a generic type. Acts as a fallback for types which can't be mapped to
|
|
2582
|
+
* a specific type like class or enum.
|
|
2583
|
+
*/
|
|
2584
|
+
SemanticTokenTypes$1["type"] = "type";
|
|
2585
|
+
SemanticTokenTypes$1["class"] = "class";
|
|
2586
|
+
SemanticTokenTypes$1["enum"] = "enum";
|
|
2587
|
+
SemanticTokenTypes$1["interface"] = "interface";
|
|
2588
|
+
SemanticTokenTypes$1["struct"] = "struct";
|
|
2589
|
+
SemanticTokenTypes$1["typeParameter"] = "typeParameter";
|
|
2590
|
+
SemanticTokenTypes$1["parameter"] = "parameter";
|
|
2591
|
+
SemanticTokenTypes$1["variable"] = "variable";
|
|
2592
|
+
SemanticTokenTypes$1["property"] = "property";
|
|
2593
|
+
SemanticTokenTypes$1["enumMember"] = "enumMember";
|
|
2594
|
+
SemanticTokenTypes$1["event"] = "event";
|
|
2595
|
+
SemanticTokenTypes$1["function"] = "function";
|
|
2596
|
+
SemanticTokenTypes$1["method"] = "method";
|
|
2597
|
+
SemanticTokenTypes$1["macro"] = "macro";
|
|
2598
|
+
SemanticTokenTypes$1["keyword"] = "keyword";
|
|
2599
|
+
SemanticTokenTypes$1["modifier"] = "modifier";
|
|
2600
|
+
SemanticTokenTypes$1["comment"] = "comment";
|
|
2601
|
+
SemanticTokenTypes$1["string"] = "string";
|
|
2602
|
+
SemanticTokenTypes$1["number"] = "number";
|
|
2603
|
+
SemanticTokenTypes$1["regexp"] = "regexp";
|
|
2604
|
+
SemanticTokenTypes$1["operator"] = "operator";
|
|
2605
|
+
/**
|
|
2606
|
+
* @since 3.17.0
|
|
2607
|
+
*/
|
|
2608
|
+
SemanticTokenTypes$1["decorator"] = "decorator";
|
|
2609
|
+
})(SemanticTokenTypes || (SemanticTokenTypes = {}));
|
|
2610
|
+
/**
|
|
2611
|
+
* A set of predefined token modifiers. This set is not fixed
|
|
2612
|
+
* an clients can specify additional token types via the
|
|
2613
|
+
* corresponding client capabilities.
|
|
2614
|
+
*
|
|
2615
|
+
* @since 3.16.0
|
|
2616
|
+
*/
|
|
2617
|
+
var SemanticTokenModifiers;
|
|
2618
|
+
(function(SemanticTokenModifiers$1) {
|
|
2619
|
+
SemanticTokenModifiers$1["declaration"] = "declaration";
|
|
2620
|
+
SemanticTokenModifiers$1["definition"] = "definition";
|
|
2621
|
+
SemanticTokenModifiers$1["readonly"] = "readonly";
|
|
2622
|
+
SemanticTokenModifiers$1["static"] = "static";
|
|
2623
|
+
SemanticTokenModifiers$1["deprecated"] = "deprecated";
|
|
2624
|
+
SemanticTokenModifiers$1["abstract"] = "abstract";
|
|
2625
|
+
SemanticTokenModifiers$1["async"] = "async";
|
|
2626
|
+
SemanticTokenModifiers$1["modification"] = "modification";
|
|
2627
|
+
SemanticTokenModifiers$1["documentation"] = "documentation";
|
|
2628
|
+
SemanticTokenModifiers$1["defaultLibrary"] = "defaultLibrary";
|
|
2629
|
+
})(SemanticTokenModifiers || (SemanticTokenModifiers = {}));
|
|
2630
|
+
/**
|
|
2631
|
+
* @since 3.16.0
|
|
2632
|
+
*/
|
|
2633
|
+
var SemanticTokens;
|
|
2634
|
+
(function(SemanticTokens$1) {
|
|
2635
|
+
function is(value) {
|
|
2636
|
+
const candidate = value;
|
|
2637
|
+
return Is.objectLiteral(candidate) && (candidate.resultId === undefined || typeof candidate.resultId === "string") && Array.isArray(candidate.data) && (candidate.data.length === 0 || typeof candidate.data[0] === "number");
|
|
2638
|
+
}
|
|
2639
|
+
SemanticTokens$1.is = is;
|
|
2640
|
+
})(SemanticTokens || (SemanticTokens = {}));
|
|
2641
|
+
/**
|
|
2642
|
+
* The InlineValueText namespace provides functions to deal with InlineValueTexts.
|
|
2643
|
+
*
|
|
2644
|
+
* @since 3.17.0
|
|
2645
|
+
*/
|
|
2646
|
+
var InlineValueText;
|
|
2647
|
+
(function(InlineValueText$1) {
|
|
2648
|
+
/**
|
|
2649
|
+
* Creates a new InlineValueText literal.
|
|
2650
|
+
*/
|
|
2651
|
+
function create(range, text) {
|
|
2652
|
+
return {
|
|
2653
|
+
range,
|
|
2654
|
+
text
|
|
2655
|
+
};
|
|
2656
|
+
}
|
|
2657
|
+
InlineValueText$1.create = create;
|
|
2658
|
+
function is(value) {
|
|
2659
|
+
const candidate = value;
|
|
2660
|
+
return candidate !== undefined && candidate !== null && Range.is(candidate.range) && Is.string(candidate.text);
|
|
2661
|
+
}
|
|
2662
|
+
InlineValueText$1.is = is;
|
|
2663
|
+
})(InlineValueText || (InlineValueText = {}));
|
|
2664
|
+
/**
|
|
2665
|
+
* The InlineValueVariableLookup namespace provides functions to deal with InlineValueVariableLookups.
|
|
2666
|
+
*
|
|
2667
|
+
* @since 3.17.0
|
|
2668
|
+
*/
|
|
2669
|
+
var InlineValueVariableLookup;
|
|
2670
|
+
(function(InlineValueVariableLookup$1) {
|
|
2671
|
+
/**
|
|
2672
|
+
* Creates a new InlineValueText literal.
|
|
2673
|
+
*/
|
|
2674
|
+
function create(range, variableName, caseSensitiveLookup) {
|
|
2675
|
+
return {
|
|
2676
|
+
range,
|
|
2677
|
+
variableName,
|
|
2678
|
+
caseSensitiveLookup
|
|
2679
|
+
};
|
|
2680
|
+
}
|
|
2681
|
+
InlineValueVariableLookup$1.create = create;
|
|
2682
|
+
function is(value) {
|
|
2683
|
+
const candidate = value;
|
|
2684
|
+
return candidate !== undefined && candidate !== null && Range.is(candidate.range) && Is.boolean(candidate.caseSensitiveLookup) && (Is.string(candidate.variableName) || candidate.variableName === undefined);
|
|
2685
|
+
}
|
|
2686
|
+
InlineValueVariableLookup$1.is = is;
|
|
2687
|
+
})(InlineValueVariableLookup || (InlineValueVariableLookup = {}));
|
|
2688
|
+
/**
|
|
2689
|
+
* The InlineValueEvaluatableExpression namespace provides functions to deal with InlineValueEvaluatableExpression.
|
|
2690
|
+
*
|
|
2691
|
+
* @since 3.17.0
|
|
2692
|
+
*/
|
|
2693
|
+
var InlineValueEvaluatableExpression;
|
|
2694
|
+
(function(InlineValueEvaluatableExpression$1) {
|
|
2695
|
+
/**
|
|
2696
|
+
* Creates a new InlineValueEvaluatableExpression literal.
|
|
2697
|
+
*/
|
|
2698
|
+
function create(range, expression) {
|
|
2699
|
+
return {
|
|
2700
|
+
range,
|
|
2701
|
+
expression
|
|
2702
|
+
};
|
|
2703
|
+
}
|
|
2704
|
+
InlineValueEvaluatableExpression$1.create = create;
|
|
2705
|
+
function is(value) {
|
|
2706
|
+
const candidate = value;
|
|
2707
|
+
return candidate !== undefined && candidate !== null && Range.is(candidate.range) && (Is.string(candidate.expression) || candidate.expression === undefined);
|
|
2708
|
+
}
|
|
2709
|
+
InlineValueEvaluatableExpression$1.is = is;
|
|
2710
|
+
})(InlineValueEvaluatableExpression || (InlineValueEvaluatableExpression = {}));
|
|
2711
|
+
/**
|
|
2712
|
+
* The InlineValueContext namespace provides helper functions to work with
|
|
2713
|
+
* {@link InlineValueContext} literals.
|
|
2714
|
+
*
|
|
2715
|
+
* @since 3.17.0
|
|
2716
|
+
*/
|
|
2717
|
+
var InlineValueContext;
|
|
2718
|
+
(function(InlineValueContext$1) {
|
|
2719
|
+
/**
|
|
2720
|
+
* Creates a new InlineValueContext literal.
|
|
2721
|
+
*/
|
|
2722
|
+
function create(frameId, stoppedLocation) {
|
|
2723
|
+
return {
|
|
2724
|
+
frameId,
|
|
2725
|
+
stoppedLocation
|
|
2726
|
+
};
|
|
2727
|
+
}
|
|
2728
|
+
InlineValueContext$1.create = create;
|
|
2729
|
+
/**
|
|
2730
|
+
* Checks whether the given literal conforms to the {@link InlineValueContext} interface.
|
|
2731
|
+
*/
|
|
2732
|
+
function is(value) {
|
|
2733
|
+
const candidate = value;
|
|
2734
|
+
return Is.defined(candidate) && Range.is(value.stoppedLocation);
|
|
2735
|
+
}
|
|
2736
|
+
InlineValueContext$1.is = is;
|
|
2737
|
+
})(InlineValueContext || (InlineValueContext = {}));
|
|
2738
|
+
/**
|
|
2739
|
+
* Inlay hint kinds.
|
|
2740
|
+
*
|
|
2741
|
+
* @since 3.17.0
|
|
2742
|
+
*/
|
|
2743
|
+
var InlayHintKind;
|
|
2744
|
+
(function(InlayHintKind$1) {
|
|
2745
|
+
/**
|
|
2746
|
+
* An inlay hint that for a type annotation.
|
|
2747
|
+
*/
|
|
2748
|
+
InlayHintKind$1.Type = 1;
|
|
2749
|
+
/**
|
|
2750
|
+
* An inlay hint that is for a parameter.
|
|
2751
|
+
*/
|
|
2752
|
+
InlayHintKind$1.Parameter = 2;
|
|
2753
|
+
function is(value) {
|
|
2754
|
+
return value === 1 || value === 2;
|
|
2755
|
+
}
|
|
2756
|
+
InlayHintKind$1.is = is;
|
|
2757
|
+
})(InlayHintKind || (InlayHintKind = {}));
|
|
2758
|
+
var InlayHintLabelPart;
|
|
2759
|
+
(function(InlayHintLabelPart$1) {
|
|
2760
|
+
function create(value) {
|
|
2761
|
+
return { value };
|
|
2762
|
+
}
|
|
2763
|
+
InlayHintLabelPart$1.create = create;
|
|
2764
|
+
function is(value) {
|
|
2765
|
+
const candidate = value;
|
|
2766
|
+
return Is.objectLiteral(candidate) && (candidate.tooltip === undefined || Is.string(candidate.tooltip) || MarkupContent.is(candidate.tooltip)) && (candidate.location === undefined || Location.is(candidate.location)) && (candidate.command === undefined || Command.is(candidate.command));
|
|
2767
|
+
}
|
|
2768
|
+
InlayHintLabelPart$1.is = is;
|
|
2769
|
+
})(InlayHintLabelPart || (InlayHintLabelPart = {}));
|
|
2770
|
+
var InlayHint;
|
|
2771
|
+
(function(InlayHint$1) {
|
|
2772
|
+
function create(position, label, kind) {
|
|
2773
|
+
const result = {
|
|
2774
|
+
position,
|
|
2775
|
+
label
|
|
2776
|
+
};
|
|
2777
|
+
if (kind !== undefined) {
|
|
2778
|
+
result.kind = kind;
|
|
2779
|
+
}
|
|
2780
|
+
return result;
|
|
2781
|
+
}
|
|
2782
|
+
InlayHint$1.create = create;
|
|
2783
|
+
function is(value) {
|
|
2784
|
+
const candidate = value;
|
|
2785
|
+
return Is.objectLiteral(candidate) && Position.is(candidate.position) && (Is.string(candidate.label) || Is.typedArray(candidate.label, InlayHintLabelPart.is)) && (candidate.kind === undefined || InlayHintKind.is(candidate.kind)) && candidate.textEdits === undefined || Is.typedArray(candidate.textEdits, TextEdit.is) && (candidate.tooltip === undefined || Is.string(candidate.tooltip) || MarkupContent.is(candidate.tooltip)) && (candidate.paddingLeft === undefined || Is.boolean(candidate.paddingLeft)) && (candidate.paddingRight === undefined || Is.boolean(candidate.paddingRight));
|
|
2786
|
+
}
|
|
2787
|
+
InlayHint$1.is = is;
|
|
2788
|
+
})(InlayHint || (InlayHint = {}));
|
|
2789
|
+
var StringValue;
|
|
2790
|
+
(function(StringValue$1) {
|
|
2791
|
+
function createSnippet(value) {
|
|
2792
|
+
return {
|
|
2793
|
+
kind: "snippet",
|
|
2794
|
+
value
|
|
2795
|
+
};
|
|
2796
|
+
}
|
|
2797
|
+
StringValue$1.createSnippet = createSnippet;
|
|
2798
|
+
})(StringValue || (StringValue = {}));
|
|
2799
|
+
var InlineCompletionItem;
|
|
2800
|
+
(function(InlineCompletionItem$1) {
|
|
2801
|
+
function create(insertText, filterText, range, command) {
|
|
2802
|
+
return {
|
|
2803
|
+
insertText,
|
|
2804
|
+
filterText,
|
|
2805
|
+
range,
|
|
2806
|
+
command
|
|
2807
|
+
};
|
|
2808
|
+
}
|
|
2809
|
+
InlineCompletionItem$1.create = create;
|
|
2810
|
+
})(InlineCompletionItem || (InlineCompletionItem = {}));
|
|
2811
|
+
var InlineCompletionList;
|
|
2812
|
+
(function(InlineCompletionList$1) {
|
|
2813
|
+
function create(items) {
|
|
2814
|
+
return { items };
|
|
2815
|
+
}
|
|
2816
|
+
InlineCompletionList$1.create = create;
|
|
2817
|
+
})(InlineCompletionList || (InlineCompletionList = {}));
|
|
2818
|
+
/**
|
|
2819
|
+
* Describes how an {@link InlineCompletionItemProvider inline completion provider} was triggered.
|
|
2820
|
+
*
|
|
2821
|
+
* @since 3.18.0
|
|
2822
|
+
* @proposed
|
|
2823
|
+
*/
|
|
2824
|
+
var InlineCompletionTriggerKind;
|
|
2825
|
+
(function(InlineCompletionTriggerKind$1) {
|
|
2826
|
+
/**
|
|
2827
|
+
* Completion was triggered explicitly by a user gesture.
|
|
2828
|
+
*/
|
|
2829
|
+
InlineCompletionTriggerKind$1.Invoked = 0;
|
|
2830
|
+
/**
|
|
2831
|
+
* Completion was triggered automatically while editing.
|
|
2832
|
+
*/
|
|
2833
|
+
InlineCompletionTriggerKind$1.Automatic = 1;
|
|
2834
|
+
})(InlineCompletionTriggerKind || (InlineCompletionTriggerKind = {}));
|
|
2835
|
+
var SelectedCompletionInfo;
|
|
2836
|
+
(function(SelectedCompletionInfo$1) {
|
|
2837
|
+
function create(range, text) {
|
|
2838
|
+
return {
|
|
2839
|
+
range,
|
|
2840
|
+
text
|
|
2841
|
+
};
|
|
2842
|
+
}
|
|
2843
|
+
SelectedCompletionInfo$1.create = create;
|
|
2844
|
+
})(SelectedCompletionInfo || (SelectedCompletionInfo = {}));
|
|
2845
|
+
var InlineCompletionContext;
|
|
2846
|
+
(function(InlineCompletionContext$1) {
|
|
2847
|
+
function create(triggerKind, selectedCompletionInfo) {
|
|
2848
|
+
return {
|
|
2849
|
+
triggerKind,
|
|
2850
|
+
selectedCompletionInfo
|
|
2851
|
+
};
|
|
2852
|
+
}
|
|
2853
|
+
InlineCompletionContext$1.create = create;
|
|
2854
|
+
})(InlineCompletionContext || (InlineCompletionContext = {}));
|
|
2855
|
+
var WorkspaceFolder;
|
|
2856
|
+
(function(WorkspaceFolder$1) {
|
|
2857
|
+
function is(value) {
|
|
2858
|
+
const candidate = value;
|
|
2859
|
+
return Is.objectLiteral(candidate) && URI.is(candidate.uri) && Is.string(candidate.name);
|
|
2860
|
+
}
|
|
2861
|
+
WorkspaceFolder$1.is = is;
|
|
2862
|
+
})(WorkspaceFolder || (WorkspaceFolder = {}));
|
|
2863
|
+
const EOL = [
|
|
2864
|
+
"\n",
|
|
2865
|
+
"\r\n",
|
|
2866
|
+
"\r"
|
|
2867
|
+
];
|
|
2868
|
+
/**
|
|
2869
|
+
* @deprecated Use the text document from the new vscode-languageserver-textdocument package.
|
|
2870
|
+
*/
|
|
2871
|
+
var TextDocument$1;
|
|
2872
|
+
(function(TextDocument$2) {
|
|
2873
|
+
/**
|
|
2874
|
+
* Creates a new ITextDocument literal from the given uri and content.
|
|
2875
|
+
* @param uri The document's uri.
|
|
2876
|
+
* @param languageId The document's language Id.
|
|
2877
|
+
* @param version The document's version.
|
|
2878
|
+
* @param content The document's content.
|
|
2879
|
+
*/
|
|
2880
|
+
function create(uri, languageId, version, content) {
|
|
2881
|
+
return new FullTextDocument(uri, languageId, version, content);
|
|
2882
|
+
}
|
|
2883
|
+
TextDocument$2.create = create;
|
|
2884
|
+
/**
|
|
2885
|
+
* Checks whether the given literal conforms to the {@link ITextDocument} interface.
|
|
2886
|
+
*/
|
|
2887
|
+
function is(value) {
|
|
2888
|
+
let candidate = value;
|
|
2889
|
+
return Is.defined(candidate) && Is.string(candidate.uri) && (Is.undefined(candidate.languageId) || Is.string(candidate.languageId)) && Is.uinteger(candidate.lineCount) && Is.func(candidate.getText) && Is.func(candidate.positionAt) && Is.func(candidate.offsetAt) ? true : false;
|
|
2890
|
+
}
|
|
2891
|
+
TextDocument$2.is = is;
|
|
2892
|
+
function applyEdits(document, edits) {
|
|
2893
|
+
let text = document.getText();
|
|
2894
|
+
let sortedEdits = mergeSort(edits, (a, b) => {
|
|
2895
|
+
let diff = a.range.start.line - b.range.start.line;
|
|
2896
|
+
if (diff === 0) {
|
|
2897
|
+
return a.range.start.character - b.range.start.character;
|
|
2898
|
+
}
|
|
2899
|
+
return diff;
|
|
2900
|
+
});
|
|
2901
|
+
let lastModifiedOffset = text.length;
|
|
2902
|
+
for (let i = sortedEdits.length - 1; i >= 0; i--) {
|
|
2903
|
+
let e = sortedEdits[i];
|
|
2904
|
+
let startOffset = document.offsetAt(e.range.start);
|
|
2905
|
+
let endOffset = document.offsetAt(e.range.end);
|
|
2906
|
+
if (endOffset <= lastModifiedOffset) {
|
|
2907
|
+
text = text.substring(0, startOffset) + e.newText + text.substring(endOffset, text.length);
|
|
2908
|
+
} else {
|
|
2909
|
+
throw new Error("Overlapping edit");
|
|
2910
|
+
}
|
|
2911
|
+
lastModifiedOffset = startOffset;
|
|
2912
|
+
}
|
|
2913
|
+
return text;
|
|
2914
|
+
}
|
|
2915
|
+
TextDocument$2.applyEdits = applyEdits;
|
|
2916
|
+
function mergeSort(data, compare) {
|
|
2917
|
+
if (data.length <= 1) {
|
|
2918
|
+
return data;
|
|
2919
|
+
}
|
|
2920
|
+
const p = data.length / 2 | 0;
|
|
2921
|
+
const left = data.slice(0, p);
|
|
2922
|
+
const right = data.slice(p);
|
|
2923
|
+
mergeSort(left, compare);
|
|
2924
|
+
mergeSort(right, compare);
|
|
2925
|
+
let leftIdx = 0;
|
|
2926
|
+
let rightIdx = 0;
|
|
2927
|
+
let i = 0;
|
|
2928
|
+
while (leftIdx < left.length && rightIdx < right.length) {
|
|
2929
|
+
let ret = compare(left[leftIdx], right[rightIdx]);
|
|
2930
|
+
if (ret <= 0) {
|
|
2931
|
+
data[i++] = left[leftIdx++];
|
|
2932
|
+
} else {
|
|
2933
|
+
data[i++] = right[rightIdx++];
|
|
2934
|
+
}
|
|
2935
|
+
}
|
|
2936
|
+
while (leftIdx < left.length) {
|
|
2937
|
+
data[i++] = left[leftIdx++];
|
|
2938
|
+
}
|
|
2939
|
+
while (rightIdx < right.length) {
|
|
2940
|
+
data[i++] = right[rightIdx++];
|
|
2941
|
+
}
|
|
2942
|
+
return data;
|
|
2943
|
+
}
|
|
2944
|
+
})(TextDocument$1 || (TextDocument$1 = {}));
|
|
2945
|
+
/**
|
|
2946
|
+
* @deprecated Use the text document from the new vscode-languageserver-textdocument package.
|
|
2947
|
+
*/
|
|
2948
|
+
var FullTextDocument = class {
|
|
2949
|
+
constructor(uri, languageId, version, content) {
|
|
2950
|
+
this._uri = uri;
|
|
2951
|
+
this._languageId = languageId;
|
|
2952
|
+
this._version = version;
|
|
2953
|
+
this._content = content;
|
|
2954
|
+
this._lineOffsets = undefined;
|
|
2955
|
+
}
|
|
2956
|
+
get uri() {
|
|
2957
|
+
return this._uri;
|
|
2958
|
+
}
|
|
2959
|
+
get languageId() {
|
|
2960
|
+
return this._languageId;
|
|
2961
|
+
}
|
|
2962
|
+
get version() {
|
|
2963
|
+
return this._version;
|
|
2964
|
+
}
|
|
2965
|
+
getText(range) {
|
|
2966
|
+
if (range) {
|
|
2967
|
+
let start = this.offsetAt(range.start);
|
|
2968
|
+
let end = this.offsetAt(range.end);
|
|
2969
|
+
return this._content.substring(start, end);
|
|
2970
|
+
}
|
|
2971
|
+
return this._content;
|
|
2972
|
+
}
|
|
2973
|
+
update(event, version) {
|
|
2974
|
+
this._content = event.text;
|
|
2975
|
+
this._version = version;
|
|
2976
|
+
this._lineOffsets = undefined;
|
|
2977
|
+
}
|
|
2978
|
+
getLineOffsets() {
|
|
2979
|
+
if (this._lineOffsets === undefined) {
|
|
2980
|
+
let lineOffsets = [];
|
|
2981
|
+
let text = this._content;
|
|
2982
|
+
let isLineStart = true;
|
|
2983
|
+
for (let i = 0; i < text.length; i++) {
|
|
2984
|
+
if (isLineStart) {
|
|
2985
|
+
lineOffsets.push(i);
|
|
2986
|
+
isLineStart = false;
|
|
2987
|
+
}
|
|
2988
|
+
let ch = text.charAt(i);
|
|
2989
|
+
isLineStart = ch === "\r" || ch === "\n";
|
|
2990
|
+
if (ch === "\r" && i + 1 < text.length && text.charAt(i + 1) === "\n") {
|
|
2991
|
+
i++;
|
|
2992
|
+
}
|
|
2993
|
+
}
|
|
2994
|
+
if (isLineStart && text.length > 0) {
|
|
2995
|
+
lineOffsets.push(text.length);
|
|
2996
|
+
}
|
|
2997
|
+
this._lineOffsets = lineOffsets;
|
|
2998
|
+
}
|
|
2999
|
+
return this._lineOffsets;
|
|
3000
|
+
}
|
|
3001
|
+
positionAt(offset) {
|
|
3002
|
+
offset = Math.max(Math.min(offset, this._content.length), 0);
|
|
3003
|
+
let lineOffsets = this.getLineOffsets();
|
|
3004
|
+
let low = 0, high = lineOffsets.length;
|
|
3005
|
+
if (high === 0) {
|
|
3006
|
+
return Position.create(0, offset);
|
|
3007
|
+
}
|
|
3008
|
+
while (low < high) {
|
|
3009
|
+
let mid = Math.floor((low + high) / 2);
|
|
3010
|
+
if (lineOffsets[mid] > offset) {
|
|
3011
|
+
high = mid;
|
|
3012
|
+
} else {
|
|
3013
|
+
low = mid + 1;
|
|
3014
|
+
}
|
|
3015
|
+
}
|
|
3016
|
+
let line = low - 1;
|
|
3017
|
+
return Position.create(line, offset - lineOffsets[line]);
|
|
3018
|
+
}
|
|
3019
|
+
offsetAt(position) {
|
|
3020
|
+
let lineOffsets = this.getLineOffsets();
|
|
3021
|
+
if (position.line >= lineOffsets.length) {
|
|
3022
|
+
return this._content.length;
|
|
3023
|
+
} else if (position.line < 0) {
|
|
3024
|
+
return 0;
|
|
3025
|
+
}
|
|
3026
|
+
let lineOffset = lineOffsets[position.line];
|
|
3027
|
+
let nextLineOffset = position.line + 1 < lineOffsets.length ? lineOffsets[position.line + 1] : this._content.length;
|
|
3028
|
+
return Math.max(Math.min(lineOffset + position.character, nextLineOffset), lineOffset);
|
|
3029
|
+
}
|
|
3030
|
+
get lineCount() {
|
|
3031
|
+
return this.getLineOffsets().length;
|
|
3032
|
+
}
|
|
3033
|
+
};
|
|
3034
|
+
var Is;
|
|
3035
|
+
(function(Is$1) {
|
|
3036
|
+
const toString = Object.prototype.toString;
|
|
3037
|
+
function defined(value) {
|
|
3038
|
+
return typeof value !== "undefined";
|
|
3039
|
+
}
|
|
3040
|
+
Is$1.defined = defined;
|
|
3041
|
+
function undefined$1(value) {
|
|
3042
|
+
return typeof value === "undefined";
|
|
3043
|
+
}
|
|
3044
|
+
Is$1.undefined = undefined$1;
|
|
3045
|
+
function boolean(value) {
|
|
3046
|
+
return value === true || value === false;
|
|
3047
|
+
}
|
|
3048
|
+
Is$1.boolean = boolean;
|
|
3049
|
+
function string(value) {
|
|
3050
|
+
return toString.call(value) === "[object String]";
|
|
3051
|
+
}
|
|
3052
|
+
Is$1.string = string;
|
|
3053
|
+
function number(value) {
|
|
3054
|
+
return toString.call(value) === "[object Number]";
|
|
3055
|
+
}
|
|
3056
|
+
Is$1.number = number;
|
|
3057
|
+
function numberRange(value, min, max) {
|
|
3058
|
+
return toString.call(value) === "[object Number]" && min <= value && value <= max;
|
|
3059
|
+
}
|
|
3060
|
+
Is$1.numberRange = numberRange;
|
|
3061
|
+
function integer$1(value) {
|
|
3062
|
+
return toString.call(value) === "[object Number]" && -2147483648 <= value && value <= 2147483647;
|
|
3063
|
+
}
|
|
3064
|
+
Is$1.integer = integer$1;
|
|
3065
|
+
function uinteger$1(value) {
|
|
3066
|
+
return toString.call(value) === "[object Number]" && 0 <= value && value <= 2147483647;
|
|
3067
|
+
}
|
|
3068
|
+
Is$1.uinteger = uinteger$1;
|
|
3069
|
+
function func(value) {
|
|
3070
|
+
return toString.call(value) === "[object Function]";
|
|
3071
|
+
}
|
|
3072
|
+
Is$1.func = func;
|
|
3073
|
+
function objectLiteral(value) {
|
|
3074
|
+
return value !== null && typeof value === "object";
|
|
3075
|
+
}
|
|
3076
|
+
Is$1.objectLiteral = objectLiteral;
|
|
3077
|
+
function typedArray(value, check) {
|
|
3078
|
+
return Array.isArray(value) && value.every(check);
|
|
3079
|
+
}
|
|
3080
|
+
Is$1.typedArray = typedArray;
|
|
3081
|
+
})(Is || (Is = {}));
|
|
3082
|
+
|
|
3083
|
+
//#endregion
|
|
3084
|
+
//#region packages/lsp/src/handlers/code-action.ts
|
|
3085
|
+
/** Handle a code action request for a GraphQL template. */
|
|
3086
|
+
const handleCodeAction = (input) => {
|
|
3087
|
+
const { template, schema, tsSource, uri, selectionRange } = input;
|
|
3088
|
+
if (template.kind === "fragment") {
|
|
3089
|
+
return [];
|
|
3090
|
+
}
|
|
3091
|
+
const { preprocessed } = preprocessFragmentArgs(template.content);
|
|
3092
|
+
const mapper = createPositionMapper({
|
|
3093
|
+
tsSource,
|
|
3094
|
+
contentStartOffset: template.contentRange.start,
|
|
3095
|
+
graphqlContent: template.content
|
|
3096
|
+
});
|
|
3097
|
+
const gqlStart = mapper.tsToGraphql(selectionRange.start);
|
|
3098
|
+
const gqlEnd = mapper.tsToGraphql(selectionRange.end);
|
|
3099
|
+
if (!gqlStart || !gqlEnd) {
|
|
3100
|
+
return [];
|
|
3101
|
+
}
|
|
3102
|
+
const preprocessedLineOffsets = computeLineOffsets(preprocessed);
|
|
3103
|
+
const startOffset = positionToOffset$1(preprocessedLineOffsets, gqlStart);
|
|
3104
|
+
const endOffset = positionToOffset$1(preprocessedLineOffsets, gqlEnd);
|
|
3105
|
+
let ast;
|
|
3106
|
+
try {
|
|
3107
|
+
ast = parse(preprocessed, { noLocation: false });
|
|
3108
|
+
} catch {
|
|
3109
|
+
return [];
|
|
3110
|
+
}
|
|
3111
|
+
const typeInfo = new TypeInfo(schema);
|
|
3112
|
+
const extractResult = findExtractableSelections(ast, typeInfo, startOffset, endOffset);
|
|
3113
|
+
if (!extractResult) {
|
|
3114
|
+
return [];
|
|
3115
|
+
}
|
|
3116
|
+
const { selections: matchedSelections, parentTypeName } = extractResult;
|
|
3117
|
+
const firstSel = matchedSelections[0];
|
|
3118
|
+
const lastSel = matchedSelections[matchedSelections.length - 1];
|
|
3119
|
+
if (!firstSel?.loc || !lastSel?.loc) {
|
|
3120
|
+
return [];
|
|
3121
|
+
}
|
|
3122
|
+
const selectedText = template.content.slice(firstSel.loc.start, lastSel.loc.end);
|
|
3123
|
+
const escapedText = selectedText.replace(/`/g, "\\`").replace(/\$\{/g, "\\${");
|
|
3124
|
+
const fragmentName = "ExtractedFragment";
|
|
3125
|
+
const fragmentDef = `fragment ${fragmentName} on ${parentTypeName} {\n ${escapedText.trim()}\n}`;
|
|
3126
|
+
const newGqlExpr = `export const ${fragmentName} = gql.${template.schemaName}(({ fragment }) => fragment\`\n ${fragmentDef}\n\`);\n\n`;
|
|
3127
|
+
const insertionOffset = findStatementStart(tsSource, template.contentRange.start);
|
|
3128
|
+
const tsLineOffsets = computeLineOffsets(tsSource);
|
|
3129
|
+
const gqlLineOffsets = computeLineOffsets(preprocessed);
|
|
3130
|
+
const replaceStart = mapper.graphqlToTs(offsetToPosition(gqlLineOffsets, firstSel.loc.start));
|
|
3131
|
+
const replaceEnd = mapper.graphqlToTs(offsetToPosition(gqlLineOffsets, lastSel.loc.end));
|
|
3132
|
+
const replaceEdit = {
|
|
3133
|
+
range: {
|
|
3134
|
+
start: replaceStart,
|
|
3135
|
+
end: replaceEnd
|
|
3136
|
+
},
|
|
3137
|
+
newText: `...${fragmentName}`
|
|
3138
|
+
};
|
|
3139
|
+
const insertPos = offsetToPosition(tsLineOffsets, insertionOffset);
|
|
3140
|
+
const insertEdit = {
|
|
3141
|
+
range: {
|
|
3142
|
+
start: insertPos,
|
|
3143
|
+
end: insertPos
|
|
3144
|
+
},
|
|
3145
|
+
newText: newGqlExpr
|
|
3146
|
+
};
|
|
3147
|
+
return [{
|
|
3148
|
+
title: `Extract Fragment "${fragmentName}"`,
|
|
3149
|
+
kind: CodeActionKind.RefactorExtract,
|
|
3150
|
+
edit: { changes: { [uri]: [insertEdit, replaceEdit] } }
|
|
3151
|
+
}];
|
|
3152
|
+
};
|
|
3153
|
+
/** Find selections within the user's range that can be extracted into a fragment. */
|
|
3154
|
+
const findExtractableSelections = (ast, typeInfo, startOffset, endOffset) => {
|
|
3155
|
+
let result = null;
|
|
3156
|
+
visit(ast, visitWithTypeInfo(typeInfo, { SelectionSet(node) {
|
|
3157
|
+
if (!node.loc || result) {
|
|
3158
|
+
return;
|
|
3159
|
+
}
|
|
3160
|
+
const selected = node.selections.filter((sel) => {
|
|
3161
|
+
if (!sel.loc) {
|
|
3162
|
+
return false;
|
|
3163
|
+
}
|
|
3164
|
+
return sel.loc.start >= startOffset && sel.loc.end <= endOffset;
|
|
3165
|
+
});
|
|
3166
|
+
if (selected.length > 0) {
|
|
3167
|
+
const typeName = typeInfo.getParentType()?.name;
|
|
3168
|
+
if (typeName) {
|
|
3169
|
+
result = {
|
|
3170
|
+
selections: selected,
|
|
3171
|
+
parentTypeName: typeName
|
|
3172
|
+
};
|
|
3173
|
+
}
|
|
3174
|
+
}
|
|
3175
|
+
} }));
|
|
3176
|
+
return result;
|
|
3177
|
+
};
|
|
3178
|
+
/**
|
|
3179
|
+
* Compute brace depth at a given offset using TypeScript scanner.
|
|
3180
|
+
* Correctly handles strings, comments, regex, and template literals.
|
|
3181
|
+
*/
|
|
3182
|
+
const braceDepthAt = (source, offset) => {
|
|
3183
|
+
const scanner = ts.createScanner(ts.ScriptTarget.Latest, false, ts.LanguageVariant.Standard, source);
|
|
3184
|
+
let depth = 0;
|
|
3185
|
+
let lastToken = ts.SyntaxKind.Unknown;
|
|
3186
|
+
while (true) {
|
|
3187
|
+
let token = scanner.scan();
|
|
3188
|
+
if (token === ts.SyntaxKind.EndOfFileToken) break;
|
|
3189
|
+
if (token === ts.SyntaxKind.SlashToken || token === ts.SyntaxKind.SlashEqualsToken) {
|
|
3190
|
+
if (lastToken === ts.SyntaxKind.FirstAssignment || lastToken === ts.SyntaxKind.EqualsEqualsToken || lastToken === ts.SyntaxKind.EqualsEqualsEqualsToken || lastToken === ts.SyntaxKind.ExclamationEqualsToken || lastToken === ts.SyntaxKind.ExclamationEqualsEqualsToken || lastToken === ts.SyntaxKind.OpenParenToken || lastToken === ts.SyntaxKind.CommaToken || lastToken === ts.SyntaxKind.OpenBracketToken || lastToken === ts.SyntaxKind.ColonToken || lastToken === ts.SyntaxKind.SemicolonToken || lastToken === ts.SyntaxKind.OpenBraceToken || lastToken === ts.SyntaxKind.QuestionToken || lastToken === ts.SyntaxKind.BarBarToken || lastToken === ts.SyntaxKind.AmpersandAmpersandToken || lastToken === ts.SyntaxKind.ExclamationToken || lastToken === ts.SyntaxKind.ReturnKeyword || lastToken === ts.SyntaxKind.CaseKeyword || lastToken === ts.SyntaxKind.NewKeyword) {
|
|
3191
|
+
token = scanner.reScanSlashToken();
|
|
3192
|
+
}
|
|
3193
|
+
}
|
|
3194
|
+
const tokenStart = scanner.getTokenStart();
|
|
3195
|
+
if (tokenStart >= offset) break;
|
|
3196
|
+
if (token === ts.SyntaxKind.OpenBraceToken) {
|
|
3197
|
+
depth++;
|
|
3198
|
+
} else if (token === ts.SyntaxKind.CloseBraceToken) {
|
|
3199
|
+
depth--;
|
|
3200
|
+
}
|
|
3201
|
+
if (token !== ts.SyntaxKind.WhitespaceTrivia && token !== ts.SyntaxKind.NewLineTrivia && token !== ts.SyntaxKind.SingleLineCommentTrivia && token !== ts.SyntaxKind.MultiLineCommentTrivia) {
|
|
3202
|
+
lastToken = token;
|
|
3203
|
+
}
|
|
3204
|
+
}
|
|
3205
|
+
return depth;
|
|
3206
|
+
};
|
|
3207
|
+
/** Find the start of the top-level statement containing the given offset. */
|
|
3208
|
+
const findStatementStart = (source, offset) => {
|
|
3209
|
+
let pos = offset;
|
|
3210
|
+
while (pos > 0 && source.charCodeAt(pos - 1) !== 10) {
|
|
3211
|
+
pos--;
|
|
3212
|
+
}
|
|
3213
|
+
while (pos > 0) {
|
|
3214
|
+
const lineStart = pos;
|
|
3215
|
+
const lineText = source.slice(lineStart, source.indexOf("\n", lineStart)).trimStart();
|
|
3216
|
+
const depth = braceDepthAt(source, lineStart);
|
|
3217
|
+
if (depth === 0 && (lineText.startsWith("export ") || lineText.startsWith("const ") || lineText.startsWith("let ") || lineText.startsWith("var ") || lineText.startsWith("function ") || lineText.startsWith("async "))) {
|
|
3218
|
+
return lineStart;
|
|
3219
|
+
}
|
|
3220
|
+
pos--;
|
|
3221
|
+
while (pos > 0 && source.charCodeAt(pos - 1) !== 10) {
|
|
3222
|
+
pos--;
|
|
3223
|
+
}
|
|
3224
|
+
if (depth === 0) {
|
|
3225
|
+
const prevLine = source.slice(pos, lineStart - 1).trim();
|
|
3226
|
+
if (prevLine.endsWith(";") || prevLine.endsWith("}")) {
|
|
3227
|
+
return lineStart;
|
|
3228
|
+
}
|
|
3229
|
+
}
|
|
3230
|
+
}
|
|
3231
|
+
return pos;
|
|
3232
|
+
};
|
|
3233
|
+
|
|
3234
|
+
//#endregion
|
|
3235
|
+
//#region packages/lsp/src/handlers/completion.ts
|
|
3236
|
+
/** Handle a completion request for a GraphQL template. */
|
|
3237
|
+
const handleCompletion = (input) => {
|
|
3238
|
+
const { template, schema, tsSource, tsPosition } = input;
|
|
3239
|
+
const reconstructed = reconstructGraphql(template);
|
|
3240
|
+
const headerLen = reconstructed.length - template.content.length;
|
|
3241
|
+
const { preprocessed } = preprocessFragmentArgs(reconstructed);
|
|
3242
|
+
const mapper = createPositionMapper({
|
|
3243
|
+
tsSource,
|
|
3244
|
+
contentStartOffset: template.contentRange.start,
|
|
3245
|
+
graphqlContent: template.content
|
|
3246
|
+
});
|
|
3247
|
+
const contentPos = mapper.tsToGraphql(tsPosition);
|
|
3248
|
+
if (!contentPos) {
|
|
3249
|
+
return [];
|
|
3250
|
+
}
|
|
3251
|
+
const contentLineOffsets = computeLineOffsets(template.content);
|
|
3252
|
+
const contentOffset = positionToOffset$1(contentLineOffsets, contentPos);
|
|
3253
|
+
const reconstructedOffset = contentOffset + headerLen;
|
|
3254
|
+
const reconstructedLineOffsets = computeLineOffsets(preprocessed);
|
|
3255
|
+
const gqlPosition = offsetToPosition(reconstructedLineOffsets, reconstructedOffset);
|
|
3256
|
+
const suggestions = getAutocompleteSuggestions(schema, preprocessed, toIPosition(gqlPosition), undefined, input.externalFragments);
|
|
3257
|
+
return suggestions;
|
|
3258
|
+
};
|
|
3259
|
+
|
|
3260
|
+
//#endregion
|
|
3261
|
+
//#region packages/lsp/src/handlers/_utils.ts
|
|
3262
|
+
/**
|
|
3263
|
+
* Find the fragment spread node at the given GraphQL offset using AST.
|
|
3264
|
+
* Returns the FragmentSpreadNode if cursor is on a `...FragmentName` pattern.
|
|
3265
|
+
*/
|
|
3266
|
+
const findFragmentSpreadAtOffset = (preprocessed, offset) => {
|
|
3267
|
+
try {
|
|
3268
|
+
const ast = parse(preprocessed, { noLocation: false });
|
|
3269
|
+
let found = null;
|
|
3270
|
+
visit(ast, { FragmentSpread(node) {
|
|
3271
|
+
if (!node.loc) {
|
|
3272
|
+
return;
|
|
3273
|
+
}
|
|
3274
|
+
if (offset >= node.loc.start && offset < node.loc.end) {
|
|
3275
|
+
found = node;
|
|
3276
|
+
}
|
|
3277
|
+
} });
|
|
3278
|
+
return found;
|
|
3279
|
+
} catch {
|
|
3280
|
+
return findFragmentSpreadByText(preprocessed, offset);
|
|
3281
|
+
}
|
|
3282
|
+
};
|
|
3283
|
+
/**
|
|
3284
|
+
* Text-based fallback: find fragment spread name at offset.
|
|
3285
|
+
* Handles documents with parse errors.
|
|
3286
|
+
*/
|
|
3287
|
+
const findFragmentSpreadByText = (text, offset) => {
|
|
3288
|
+
const spreadPattern = /\.\.\.([A-Za-z_]\w*)/g;
|
|
3289
|
+
let match = null;
|
|
3290
|
+
while ((match = spreadPattern.exec(text)) !== null) {
|
|
3291
|
+
const start = match.index;
|
|
3292
|
+
const end = start + match[0].length;
|
|
3293
|
+
if (offset >= start && offset < end) {
|
|
3294
|
+
return {
|
|
3295
|
+
kind: "FragmentSpread",
|
|
3296
|
+
name: {
|
|
3297
|
+
kind: "Name",
|
|
3298
|
+
value: match[1] ?? ""
|
|
3299
|
+
}
|
|
3300
|
+
};
|
|
3301
|
+
}
|
|
3302
|
+
}
|
|
3303
|
+
return null;
|
|
3304
|
+
};
|
|
3305
|
+
/**
|
|
3306
|
+
* Find a FragmentDefinition at a given offset.
|
|
3307
|
+
* Returns the name and location, or null.
|
|
3308
|
+
*/
|
|
3309
|
+
const findFragmentDefinitionAtOffset = (preprocessed, offset) => {
|
|
3310
|
+
try {
|
|
3311
|
+
const ast = parse(preprocessed, { noLocation: false });
|
|
3312
|
+
for (const def of ast.definitions) {
|
|
3313
|
+
if (def.kind === "FragmentDefinition" && def.name.loc) {
|
|
3314
|
+
if (offset >= def.name.loc.start && offset < def.name.loc.end) {
|
|
3315
|
+
return {
|
|
3316
|
+
name: def.name.value,
|
|
3317
|
+
loc: {
|
|
3318
|
+
start: def.name.loc.start,
|
|
3319
|
+
end: def.name.loc.end
|
|
3320
|
+
}
|
|
3321
|
+
};
|
|
3322
|
+
}
|
|
3323
|
+
}
|
|
3324
|
+
}
|
|
3325
|
+
} catch {}
|
|
3326
|
+
return null;
|
|
3327
|
+
};
|
|
3328
|
+
/**
|
|
3329
|
+
* Resolve the fragment name at a given offset, checking both definitions and spreads.
|
|
3330
|
+
*/
|
|
3331
|
+
const resolveFragmentNameAtOffset = (preprocessed, offset) => {
|
|
3332
|
+
const def = findFragmentDefinitionAtOffset(preprocessed, offset);
|
|
3333
|
+
if (def) {
|
|
3334
|
+
return def.name;
|
|
3335
|
+
}
|
|
3336
|
+
const spread = findFragmentSpreadAtOffset(preprocessed, offset);
|
|
3337
|
+
if (spread) {
|
|
3338
|
+
return spread.name.value;
|
|
3339
|
+
}
|
|
3340
|
+
return null;
|
|
3341
|
+
};
|
|
3342
|
+
/** Compute TS ranges for all definitions of a named fragment. */
|
|
3343
|
+
const computeFragmentDefinitionRanges = (fragmentName, allFragments) => {
|
|
3344
|
+
const ranges = [];
|
|
3345
|
+
for (const frag of allFragments) {
|
|
3346
|
+
if (frag.fragmentName !== fragmentName) {
|
|
3347
|
+
continue;
|
|
3348
|
+
}
|
|
3349
|
+
if (!frag.definition.name.loc) {
|
|
3350
|
+
continue;
|
|
3351
|
+
}
|
|
3352
|
+
const defMapper = createPositionMapper({
|
|
3353
|
+
tsSource: frag.tsSource,
|
|
3354
|
+
contentStartOffset: frag.contentRange.start,
|
|
3355
|
+
graphqlContent: frag.content
|
|
3356
|
+
});
|
|
3357
|
+
const defGqlLineOffsets = computeLineOffsets(frag.content);
|
|
3358
|
+
const nameStart = offsetToPosition(defGqlLineOffsets, frag.definition.name.loc.start);
|
|
3359
|
+
const nameEnd = offsetToPosition(defGqlLineOffsets, frag.definition.name.loc.end);
|
|
3360
|
+
ranges.push({
|
|
3361
|
+
uri: frag.uri,
|
|
3362
|
+
range: {
|
|
3363
|
+
start: defMapper.graphqlToTs(nameStart),
|
|
3364
|
+
end: defMapper.graphqlToTs(nameEnd)
|
|
3365
|
+
}
|
|
3366
|
+
});
|
|
3367
|
+
}
|
|
3368
|
+
return ranges;
|
|
3369
|
+
};
|
|
3370
|
+
/** Compute TS ranges for all fragment spread locations. */
|
|
3371
|
+
const computeSpreadLocationRanges = (spreadLocations) => {
|
|
3372
|
+
const ranges = [];
|
|
3373
|
+
for (const loc of spreadLocations) {
|
|
3374
|
+
const spreadMapper = createPositionMapper({
|
|
3375
|
+
tsSource: loc.tsSource,
|
|
3376
|
+
contentStartOffset: loc.template.contentRange.start,
|
|
3377
|
+
graphqlContent: loc.template.content
|
|
3378
|
+
});
|
|
3379
|
+
const spreadGqlLineOffsets = computeLineOffsets(loc.template.content);
|
|
3380
|
+
const spreadStart = offsetToPosition(spreadGqlLineOffsets, loc.nameOffset);
|
|
3381
|
+
const spreadEnd = offsetToPosition(spreadGqlLineOffsets, loc.nameOffset + loc.nameLength);
|
|
3382
|
+
ranges.push({
|
|
3383
|
+
uri: loc.uri,
|
|
3384
|
+
range: {
|
|
3385
|
+
start: spreadMapper.graphqlToTs(spreadStart),
|
|
3386
|
+
end: spreadMapper.graphqlToTs(spreadEnd)
|
|
3387
|
+
}
|
|
3388
|
+
});
|
|
3389
|
+
}
|
|
3390
|
+
return ranges;
|
|
3391
|
+
};
|
|
3392
|
+
|
|
3393
|
+
//#endregion
|
|
3394
|
+
//#region packages/lsp/src/handlers/definition.ts
|
|
3395
|
+
/**
|
|
3396
|
+
* Definition handler: provides go-to-definition for fragment spreads and schema fields/types.
|
|
3397
|
+
* @module
|
|
3398
|
+
*/
|
|
3399
|
+
/** Build ObjectTypeInfo[] from schema file info for graphql-language-service definition APIs. */
|
|
3400
|
+
const buildObjectTypeInfos = (files) => {
|
|
3401
|
+
const result = [];
|
|
3402
|
+
for (const file of files) {
|
|
3403
|
+
const doc = parse(file.content);
|
|
3404
|
+
for (const def of doc.definitions) {
|
|
3405
|
+
if (isTypeDefinitionNode(def)) {
|
|
3406
|
+
result.push({
|
|
3407
|
+
filePath: pathToFileURL(file.filePath).href,
|
|
3408
|
+
content: file.content,
|
|
3409
|
+
definition: def
|
|
3410
|
+
});
|
|
3411
|
+
}
|
|
3412
|
+
}
|
|
3413
|
+
}
|
|
3414
|
+
return result;
|
|
3415
|
+
};
|
|
3416
|
+
/** Handle a definition request for a GraphQL template. */
|
|
3417
|
+
const handleDefinition = async (input) => {
|
|
3418
|
+
const { template, tsSource, tsPosition, externalFragments } = input;
|
|
3419
|
+
const reconstructed = reconstructGraphql(template);
|
|
3420
|
+
const headerLen = reconstructed.length - template.content.length;
|
|
3421
|
+
const { preprocessed } = preprocessFragmentArgs(reconstructed);
|
|
3422
|
+
const mapper = createPositionMapper({
|
|
3423
|
+
tsSource,
|
|
3424
|
+
contentStartOffset: template.contentRange.start,
|
|
3425
|
+
graphqlContent: template.content
|
|
3426
|
+
});
|
|
3427
|
+
const gqlPosition = mapper.tsToGraphql(tsPosition);
|
|
3428
|
+
if (!gqlPosition) {
|
|
3429
|
+
return [];
|
|
3430
|
+
}
|
|
3431
|
+
const contentLineOffsets = computeLineOffsets(template.content);
|
|
3432
|
+
const contentOffset = positionToOffset$1(contentLineOffsets, gqlPosition);
|
|
3433
|
+
const reconstructedOffset = contentOffset + headerLen;
|
|
3434
|
+
const fragmentSpread = findFragmentSpreadAtOffset(preprocessed, reconstructedOffset);
|
|
3435
|
+
if (fragmentSpread) {
|
|
3436
|
+
return resolveFragmentSpreadDefinition(preprocessed, fragmentSpread, externalFragments);
|
|
3437
|
+
}
|
|
3438
|
+
if (input.schema && input.schemaFiles && input.schemaFiles.length > 0) {
|
|
3439
|
+
const reconstructedLineOffsets = computeLineOffsets(preprocessed);
|
|
3440
|
+
const reconstructedPosition = offsetToPosition(reconstructedLineOffsets, reconstructedOffset);
|
|
3441
|
+
return resolveSchemaDefinition(preprocessed, reconstructedPosition, input.schema, input.schemaFiles);
|
|
3442
|
+
}
|
|
3443
|
+
return [];
|
|
3444
|
+
};
|
|
3445
|
+
/** Resolve fragment spread to its definition in an external TypeScript file. */
|
|
3446
|
+
const resolveFragmentSpreadDefinition = async (preprocessed, fragmentSpread, externalFragments) => {
|
|
3447
|
+
const fragmentInfos = externalFragments.map((f) => ({
|
|
3448
|
+
filePath: f.uri,
|
|
3449
|
+
content: f.content,
|
|
3450
|
+
definition: f.definition
|
|
3451
|
+
}));
|
|
3452
|
+
try {
|
|
3453
|
+
const result = await getDefinitionQueryResultForFragmentSpread(preprocessed, fragmentSpread, fragmentInfos);
|
|
3454
|
+
return result.definitions.map((def) => {
|
|
3455
|
+
const defPosition = toIPosition(def.position);
|
|
3456
|
+
const endLine = def.range?.end?.line ?? defPosition.line;
|
|
3457
|
+
const endChar = def.range?.end?.character ?? defPosition.character;
|
|
3458
|
+
const targetFragment = externalFragments.find((f) => f.uri === def.path);
|
|
3459
|
+
if (targetFragment) {
|
|
3460
|
+
const targetReconstructedLineOffsets = computeLineOffsets(targetFragment.content);
|
|
3461
|
+
const targetContentLineOffsets = computeLineOffsets(targetFragment.content.slice(targetFragment.headerLen));
|
|
3462
|
+
const toOriginalPos = (pos) => {
|
|
3463
|
+
const offset = positionToOffset$1(targetReconstructedLineOffsets, pos);
|
|
3464
|
+
const originalOffset = Math.max(0, offset - targetFragment.headerLen);
|
|
3465
|
+
return offsetToPosition(targetContentLineOffsets, originalOffset);
|
|
3466
|
+
};
|
|
3467
|
+
const targetMapper = createPositionMapper({
|
|
3468
|
+
tsSource: targetFragment.tsSource,
|
|
3469
|
+
contentStartOffset: targetFragment.contentRange.start,
|
|
3470
|
+
graphqlContent: targetFragment.content.slice(targetFragment.headerLen)
|
|
3471
|
+
});
|
|
3472
|
+
const tsStart = targetMapper.graphqlToTs(toOriginalPos({
|
|
3473
|
+
line: defPosition.line,
|
|
3474
|
+
character: defPosition.character
|
|
3475
|
+
}));
|
|
3476
|
+
const tsEnd = targetMapper.graphqlToTs(toOriginalPos({
|
|
3477
|
+
line: endLine,
|
|
3478
|
+
character: endChar
|
|
3479
|
+
}));
|
|
3480
|
+
return {
|
|
3481
|
+
uri: def.path,
|
|
3482
|
+
range: {
|
|
3483
|
+
start: tsStart,
|
|
3484
|
+
end: tsEnd
|
|
3485
|
+
}
|
|
3486
|
+
};
|
|
3487
|
+
}
|
|
3488
|
+
return {
|
|
3489
|
+
uri: def.path,
|
|
3490
|
+
range: {
|
|
3491
|
+
start: {
|
|
3492
|
+
line: defPosition.line,
|
|
3493
|
+
character: defPosition.character
|
|
3494
|
+
},
|
|
3495
|
+
end: {
|
|
3496
|
+
line: endLine,
|
|
3497
|
+
character: endChar
|
|
3498
|
+
}
|
|
3499
|
+
}
|
|
3500
|
+
};
|
|
3501
|
+
});
|
|
3502
|
+
} catch {
|
|
3503
|
+
return [];
|
|
3504
|
+
}
|
|
3505
|
+
};
|
|
3506
|
+
/** Resolve field or type name to its definition in a schema .graphql file. */
|
|
3507
|
+
const resolveSchemaDefinition = (preprocessed, position, schema, schemaFiles) => {
|
|
3508
|
+
const context = getContextAtPosition(preprocessed, toIPosition(position), schema);
|
|
3509
|
+
if (!context) {
|
|
3510
|
+
return Promise.resolve([]);
|
|
3511
|
+
}
|
|
3512
|
+
const { typeInfo } = context;
|
|
3513
|
+
if (typeInfo.fieldDef && typeInfo.parentType) {
|
|
3514
|
+
const fieldName = typeInfo.fieldDef.name;
|
|
3515
|
+
const namedParentType = getNamedType(typeInfo.parentType);
|
|
3516
|
+
if (!namedParentType) {
|
|
3517
|
+
return Promise.resolve([]);
|
|
3518
|
+
}
|
|
3519
|
+
const parentTypeName = namedParentType.name;
|
|
3520
|
+
const objectTypeInfos = buildObjectTypeInfos(schemaFiles);
|
|
3521
|
+
return getDefinitionQueryResultForField(fieldName, parentTypeName, objectTypeInfos).then((result) => result.definitions.map((def) => ({
|
|
3522
|
+
uri: def.path ?? "",
|
|
3523
|
+
range: {
|
|
3524
|
+
start: {
|
|
3525
|
+
line: def.position.line,
|
|
3526
|
+
character: def.position.character
|
|
3527
|
+
},
|
|
3528
|
+
end: {
|
|
3529
|
+
line: def.range?.end?.line ?? def.position.line,
|
|
3530
|
+
character: def.range?.end?.character ?? def.position.character
|
|
3531
|
+
}
|
|
3532
|
+
}
|
|
3533
|
+
})));
|
|
3534
|
+
}
|
|
3535
|
+
return Promise.resolve([]);
|
|
3536
|
+
};
|
|
3537
|
+
|
|
3538
|
+
//#endregion
|
|
3539
|
+
//#region packages/lsp/src/handlers/diagnostics.ts
|
|
3540
|
+
/** Compute LSP diagnostics for a single GraphQL template. */
|
|
3541
|
+
const computeTemplateDiagnostics = (input) => {
|
|
3542
|
+
const { template, schema, tsSource } = input;
|
|
3543
|
+
const reconstructed = reconstructGraphql(template);
|
|
3544
|
+
const headerLen = reconstructed.length - template.content.length;
|
|
3545
|
+
const { preprocessed } = preprocessFragmentArgs(reconstructed);
|
|
3546
|
+
const mapper = createPositionMapper({
|
|
3547
|
+
tsSource,
|
|
3548
|
+
contentStartOffset: template.contentRange.start,
|
|
3549
|
+
graphqlContent: template.content
|
|
3550
|
+
});
|
|
3551
|
+
const gqlDiagnostics = getDiagnostics(preprocessed, schema, undefined, undefined, input.externalFragments);
|
|
3552
|
+
const placeholderPattern = /__FRAG_SPREAD_\d+__/;
|
|
3553
|
+
const reconstructedLineOffsets = computeLineOffsets(preprocessed);
|
|
3554
|
+
const contentLineOffsets = computeLineOffsets(template.content);
|
|
3555
|
+
const toContentPosition = (pos) => {
|
|
3556
|
+
const offset = positionToOffset$1(reconstructedLineOffsets, pos);
|
|
3557
|
+
const contentOffset = Math.max(0, offset - headerLen);
|
|
3558
|
+
return offsetToPosition(contentLineOffsets, contentOffset);
|
|
3559
|
+
};
|
|
3560
|
+
return gqlDiagnostics.filter((diag) => {
|
|
3561
|
+
if (placeholderPattern.test(diag.message)) {
|
|
3562
|
+
return false;
|
|
3563
|
+
}
|
|
3564
|
+
const offset = positionToOffset$1(reconstructedLineOffsets, diag.range.start);
|
|
3565
|
+
if (offset < headerLen) {
|
|
3566
|
+
return false;
|
|
3567
|
+
}
|
|
3568
|
+
return true;
|
|
3569
|
+
}).map((diag) => {
|
|
3570
|
+
const startContent = toContentPosition(diag.range.start);
|
|
3571
|
+
const endContent = toContentPosition(diag.range.end);
|
|
3572
|
+
const startTs = mapper.graphqlToTs(startContent);
|
|
3573
|
+
const endTs = mapper.graphqlToTs(endContent);
|
|
3574
|
+
return {
|
|
3575
|
+
range: {
|
|
3576
|
+
start: {
|
|
3577
|
+
line: startTs.line,
|
|
3578
|
+
character: startTs.character
|
|
3579
|
+
},
|
|
3580
|
+
end: {
|
|
3581
|
+
line: endTs.line,
|
|
3582
|
+
character: endTs.character
|
|
3583
|
+
}
|
|
3584
|
+
},
|
|
3585
|
+
message: diag.message,
|
|
3586
|
+
severity: diag.severity,
|
|
3587
|
+
source: "soda-gql"
|
|
3588
|
+
};
|
|
3589
|
+
});
|
|
3590
|
+
};
|
|
3591
|
+
|
|
3592
|
+
//#endregion
|
|
3593
|
+
//#region packages/lsp/src/handlers/document-symbol.ts
|
|
3594
|
+
/**
|
|
3595
|
+
* Document symbol handler: provides outline view for GraphQL templates.
|
|
3596
|
+
* @module
|
|
3597
|
+
*/
|
|
3598
|
+
const KIND_MAP = {
|
|
3599
|
+
OperationDefinition: SymbolKind.Function,
|
|
3600
|
+
FragmentDefinition: SymbolKind.Class,
|
|
3601
|
+
Field: SymbolKind.Field,
|
|
3602
|
+
FragmentSpread: SymbolKind.Constant,
|
|
3603
|
+
InlineFragment: SymbolKind.Struct,
|
|
3604
|
+
EnumValueDefinition: SymbolKind.EnumMember,
|
|
3605
|
+
InputValueDefinition: SymbolKind.Property,
|
|
3606
|
+
FieldDefinition: SymbolKind.Field,
|
|
3607
|
+
ObjectTypeDefinition: SymbolKind.Class,
|
|
3608
|
+
InputObjectTypeDefinition: SymbolKind.Class,
|
|
3609
|
+
InterfaceTypeDefinition: SymbolKind.Interface,
|
|
3610
|
+
EnumTypeDefinition: SymbolKind.Enum
|
|
3611
|
+
};
|
|
3612
|
+
const getSymbolName = (tree) => {
|
|
3613
|
+
if (tree.representativeName) {
|
|
3614
|
+
return tree.representativeName;
|
|
3615
|
+
}
|
|
3616
|
+
if (tree.tokenizedText) {
|
|
3617
|
+
return tree.tokenizedText.map((t) => t.value).join("");
|
|
3618
|
+
}
|
|
3619
|
+
return tree.kind;
|
|
3620
|
+
};
|
|
3621
|
+
const convertTree = (tree, toContentPos, mapper) => {
|
|
3622
|
+
const name = getSymbolName(tree);
|
|
3623
|
+
const kind = KIND_MAP[tree.kind] ?? SymbolKind.Variable;
|
|
3624
|
+
const startTs = mapper.graphqlToTs(toContentPos(tree.startPosition));
|
|
3625
|
+
const endTs = tree.endPosition ? mapper.graphqlToTs(toContentPos(tree.endPosition)) : startTs;
|
|
3626
|
+
const range = {
|
|
3627
|
+
start: {
|
|
3628
|
+
line: startTs.line,
|
|
3629
|
+
character: startTs.character
|
|
3630
|
+
},
|
|
3631
|
+
end: {
|
|
3632
|
+
line: endTs.line,
|
|
3633
|
+
character: endTs.character
|
|
3634
|
+
}
|
|
3635
|
+
};
|
|
3636
|
+
const children = [];
|
|
3637
|
+
for (const child of tree.children) {
|
|
3638
|
+
const converted = convertTree(child, toContentPos, mapper);
|
|
3639
|
+
if (converted) {
|
|
3640
|
+
children.push(converted);
|
|
3641
|
+
}
|
|
3642
|
+
}
|
|
3643
|
+
return {
|
|
3644
|
+
name,
|
|
3645
|
+
kind,
|
|
3646
|
+
range,
|
|
3647
|
+
selectionRange: range,
|
|
3648
|
+
children: children.length > 0 ? children : undefined
|
|
3649
|
+
};
|
|
3650
|
+
};
|
|
3651
|
+
/** Handle a documentSymbol request for all GraphQL templates in a document. */
|
|
3652
|
+
const handleDocumentSymbol = (input) => {
|
|
3653
|
+
const { templates, tsSource } = input;
|
|
3654
|
+
const symbols = [];
|
|
3655
|
+
for (const template of templates) {
|
|
3656
|
+
const reconstructed = reconstructGraphql(template);
|
|
3657
|
+
const headerLen = reconstructed.length - template.content.length;
|
|
3658
|
+
const { preprocessed } = preprocessFragmentArgs(reconstructed);
|
|
3659
|
+
const outline = getOutline(preprocessed);
|
|
3660
|
+
if (!outline) {
|
|
3661
|
+
continue;
|
|
3662
|
+
}
|
|
3663
|
+
const mapper = createPositionMapper({
|
|
3664
|
+
tsSource,
|
|
3665
|
+
contentStartOffset: template.contentRange.start,
|
|
3666
|
+
graphqlContent: template.content
|
|
3667
|
+
});
|
|
3668
|
+
const reconstructedLineOffsets = computeLineOffsets(preprocessed);
|
|
3669
|
+
const contentLineOffsets = computeLineOffsets(template.content);
|
|
3670
|
+
const toContentPos = (pos) => {
|
|
3671
|
+
const offset = positionToOffset$1(reconstructedLineOffsets, pos);
|
|
3672
|
+
const contentOffset = Math.max(0, offset - headerLen);
|
|
3673
|
+
return offsetToPosition(contentLineOffsets, contentOffset);
|
|
3674
|
+
};
|
|
3675
|
+
for (const tree of outline.outlineTrees) {
|
|
3676
|
+
const symbol = convertTree(tree, toContentPos, mapper);
|
|
3677
|
+
if (symbol) {
|
|
3678
|
+
symbols.push(symbol);
|
|
3679
|
+
}
|
|
3680
|
+
}
|
|
3681
|
+
}
|
|
3682
|
+
return symbols;
|
|
3683
|
+
};
|
|
3684
|
+
|
|
3685
|
+
//#endregion
|
|
3686
|
+
//#region packages/lsp/src/handlers/formatting.ts
|
|
3687
|
+
/**
|
|
3688
|
+
* Formatting handler: format GraphQL content within tagged templates.
|
|
3689
|
+
* @module
|
|
3690
|
+
*/
|
|
3691
|
+
const defaultFormatGraphql = (source) => {
|
|
3692
|
+
const ast = parse(source, { noLocation: false });
|
|
3693
|
+
return print(ast);
|
|
3694
|
+
};
|
|
3695
|
+
/** Handle a document formatting request for GraphQL templates. */
|
|
3696
|
+
const handleFormatting = (input) => {
|
|
3697
|
+
const { templates, tsSource, formatGraphql } = input;
|
|
3698
|
+
const format = formatGraphql ?? defaultFormatGraphql;
|
|
3699
|
+
const tsLineOffsets = computeLineOffsets(tsSource);
|
|
3700
|
+
const edits = [];
|
|
3701
|
+
for (const template of templates) {
|
|
3702
|
+
let formatted;
|
|
3703
|
+
try {
|
|
3704
|
+
formatted = format(template.content);
|
|
3705
|
+
} catch {
|
|
3706
|
+
continue;
|
|
3707
|
+
}
|
|
3708
|
+
if (formatted === template.content) {
|
|
3709
|
+
continue;
|
|
3710
|
+
}
|
|
3711
|
+
const baseIndent = detectBaseIndent(tsSource, template.contentRange.start);
|
|
3712
|
+
const reindented = reindent(formatted, baseIndent, template.content);
|
|
3713
|
+
if (reindented === template.content) {
|
|
3714
|
+
continue;
|
|
3715
|
+
}
|
|
3716
|
+
const start = offsetToPosition(tsLineOffsets, template.contentRange.start);
|
|
3717
|
+
const end = offsetToPosition(tsLineOffsets, template.contentRange.end);
|
|
3718
|
+
edits.push({
|
|
3719
|
+
range: {
|
|
3720
|
+
start,
|
|
3721
|
+
end
|
|
3722
|
+
},
|
|
3723
|
+
newText: reindented
|
|
3724
|
+
});
|
|
3725
|
+
}
|
|
3726
|
+
return edits;
|
|
3727
|
+
};
|
|
3728
|
+
/**
|
|
3729
|
+
* Detect the base indentation for a template by looking at the line
|
|
3730
|
+
* containing the opening backtick.
|
|
3731
|
+
*/
|
|
3732
|
+
const detectBaseIndent = (tsSource, contentStartOffset) => {
|
|
3733
|
+
let lineStart = contentStartOffset;
|
|
3734
|
+
while (lineStart > 0 && tsSource.charCodeAt(lineStart - 1) !== 10) {
|
|
3735
|
+
lineStart--;
|
|
3736
|
+
}
|
|
3737
|
+
let i = lineStart;
|
|
3738
|
+
while (i < tsSource.length && (tsSource.charCodeAt(i) === 32 || tsSource.charCodeAt(i) === 9)) {
|
|
3739
|
+
i++;
|
|
3740
|
+
}
|
|
3741
|
+
return tsSource.slice(lineStart, i);
|
|
3742
|
+
};
|
|
3743
|
+
/**
|
|
3744
|
+
* Re-indent formatted GraphQL to match the embedding context.
|
|
3745
|
+
*
|
|
3746
|
+
* The original template may start with a newline (common for multi-line templates)
|
|
3747
|
+
* or be inline. We match the original pattern:
|
|
3748
|
+
* - If original starts with newline, formatted output gets newline + indented lines
|
|
3749
|
+
* - If original is single-line, keep formatted as single-line if it fits
|
|
3750
|
+
*/
|
|
3751
|
+
const reindent = (formatted, baseIndent, originalContent) => {
|
|
3752
|
+
const trimmedFormatted = formatted.trim();
|
|
3753
|
+
if (!originalContent.includes("\n") && !trimmedFormatted.includes("\n")) {
|
|
3754
|
+
return trimmedFormatted;
|
|
3755
|
+
}
|
|
3756
|
+
const indent = `${baseIndent} `;
|
|
3757
|
+
const lines = trimmedFormatted.split("\n");
|
|
3758
|
+
const indentedLines = lines.map((line) => line.trim() === "" ? "" : indent + line);
|
|
3759
|
+
const startsWithNewline = originalContent.startsWith("\n");
|
|
3760
|
+
const endsWithNewline = originalContent.endsWith("\n");
|
|
3761
|
+
let result = indentedLines.join("\n");
|
|
3762
|
+
if (startsWithNewline) {
|
|
3763
|
+
result = `\n${result}`;
|
|
3764
|
+
}
|
|
3765
|
+
if (endsWithNewline) {
|
|
3766
|
+
result = `${result}\n${baseIndent}`;
|
|
3767
|
+
}
|
|
3768
|
+
return result;
|
|
3769
|
+
};
|
|
3770
|
+
|
|
3771
|
+
//#endregion
|
|
3772
|
+
//#region packages/lsp/src/handlers/hover.ts
|
|
3773
|
+
/** Handle a hover request for a GraphQL template. */
|
|
3774
|
+
const handleHover = (input) => {
|
|
3775
|
+
const { template, schema, tsSource, tsPosition } = input;
|
|
3776
|
+
const reconstructed = reconstructGraphql(template);
|
|
3777
|
+
const headerLen = reconstructed.length - template.content.length;
|
|
3778
|
+
const { preprocessed } = preprocessFragmentArgs(reconstructed);
|
|
3779
|
+
const mapper = createPositionMapper({
|
|
3780
|
+
tsSource,
|
|
3781
|
+
contentStartOffset: template.contentRange.start,
|
|
3782
|
+
graphqlContent: template.content
|
|
3783
|
+
});
|
|
3784
|
+
const contentPos = mapper.tsToGraphql(tsPosition);
|
|
3785
|
+
if (!contentPos) {
|
|
3786
|
+
return null;
|
|
3787
|
+
}
|
|
3788
|
+
const contentLineOffsets = computeLineOffsets(template.content);
|
|
3789
|
+
const contentOffset = positionToOffset$1(contentLineOffsets, contentPos);
|
|
3790
|
+
const reconstructedOffset = contentOffset + headerLen;
|
|
3791
|
+
const reconstructedLineOffsets = computeLineOffsets(preprocessed);
|
|
3792
|
+
const gqlPosition = offsetToPosition(reconstructedLineOffsets, reconstructedOffset);
|
|
3793
|
+
const hoverInfo = getHoverInformation(schema, preprocessed, toIPosition(gqlPosition), undefined, { useMarkdown: true });
|
|
3794
|
+
if (!hoverInfo || hoverInfo === "" || Array.isArray(hoverInfo) && hoverInfo.length === 0) {
|
|
3795
|
+
return null;
|
|
3796
|
+
}
|
|
3797
|
+
let contents;
|
|
3798
|
+
if (typeof hoverInfo === "string") {
|
|
3799
|
+
contents = {
|
|
3800
|
+
kind: "markdown",
|
|
3801
|
+
value: hoverInfo
|
|
3802
|
+
};
|
|
3803
|
+
} else if (Array.isArray(hoverInfo)) {
|
|
3804
|
+
const parts = hoverInfo.map((item) => typeof item === "string" ? item : item.value);
|
|
3805
|
+
contents = {
|
|
3806
|
+
kind: "markdown",
|
|
3807
|
+
value: parts.join("\n\n")
|
|
3808
|
+
};
|
|
3809
|
+
} else {
|
|
3810
|
+
contents = hoverInfo;
|
|
3811
|
+
}
|
|
3812
|
+
return { contents };
|
|
3813
|
+
};
|
|
3814
|
+
|
|
3815
|
+
//#endregion
|
|
3816
|
+
//#region packages/lsp/src/handlers/references.ts
|
|
3817
|
+
/** Handle a references request for a GraphQL template. */
|
|
3818
|
+
const handleReferences = (input) => {
|
|
3819
|
+
const { template, tsSource, tsPosition, allFragments, findSpreadLocations } = input;
|
|
3820
|
+
const { preprocessed } = preprocessFragmentArgs(template.content);
|
|
3821
|
+
const mapper = createPositionMapper({
|
|
3822
|
+
tsSource,
|
|
3823
|
+
contentStartOffset: template.contentRange.start,
|
|
3824
|
+
graphqlContent: template.content
|
|
3825
|
+
});
|
|
3826
|
+
const gqlPosition = mapper.tsToGraphql(tsPosition);
|
|
3827
|
+
if (!gqlPosition) {
|
|
3828
|
+
return [];
|
|
3829
|
+
}
|
|
3830
|
+
const offset = positionToOffset$1(computeLineOffsets(preprocessed), gqlPosition);
|
|
3831
|
+
const fragmentName = resolveFragmentNameAtOffset(preprocessed, offset);
|
|
3832
|
+
if (!fragmentName) {
|
|
3833
|
+
return [];
|
|
3834
|
+
}
|
|
3835
|
+
const locations = [];
|
|
3836
|
+
for (const r of computeFragmentDefinitionRanges(fragmentName, allFragments)) {
|
|
3837
|
+
locations.push({
|
|
3838
|
+
uri: r.uri,
|
|
3839
|
+
range: r.range
|
|
3840
|
+
});
|
|
3841
|
+
}
|
|
3842
|
+
for (const r of computeSpreadLocationRanges(findSpreadLocations(fragmentName))) {
|
|
3843
|
+
locations.push({
|
|
3844
|
+
uri: r.uri,
|
|
3845
|
+
range: r.range
|
|
3846
|
+
});
|
|
3847
|
+
}
|
|
3848
|
+
return locations;
|
|
3849
|
+
};
|
|
3850
|
+
|
|
3851
|
+
//#endregion
|
|
3852
|
+
//#region packages/lsp/src/handlers/rename.ts
|
|
3853
|
+
/** Validate and return the range of the symbol to be renamed. */
|
|
3854
|
+
const handlePrepareRename = (input) => {
|
|
3855
|
+
const { template, tsSource, tsPosition } = input;
|
|
3856
|
+
const { preprocessed } = preprocessFragmentArgs(template.content);
|
|
3857
|
+
const mapper = createPositionMapper({
|
|
3858
|
+
tsSource,
|
|
3859
|
+
contentStartOffset: template.contentRange.start,
|
|
3860
|
+
graphqlContent: template.content
|
|
3861
|
+
});
|
|
3862
|
+
const gqlPosition = mapper.tsToGraphql(tsPosition);
|
|
3863
|
+
if (!gqlPosition) {
|
|
3864
|
+
return null;
|
|
3865
|
+
}
|
|
3866
|
+
const offset = positionToOffset$1(computeLineOffsets(preprocessed), gqlPosition);
|
|
3867
|
+
const defResult = findFragmentDefinitionAtOffset(preprocessed, offset);
|
|
3868
|
+
if (defResult) {
|
|
3869
|
+
const gqlLineOffsets = computeLineOffsets(preprocessed);
|
|
3870
|
+
const start = mapper.graphqlToTs(offsetToPosition(gqlLineOffsets, defResult.loc.start));
|
|
3871
|
+
const end = mapper.graphqlToTs(offsetToPosition(gqlLineOffsets, defResult.loc.end));
|
|
3872
|
+
return {
|
|
3873
|
+
range: {
|
|
3874
|
+
start,
|
|
3875
|
+
end
|
|
3876
|
+
},
|
|
3877
|
+
placeholder: defResult.name
|
|
3878
|
+
};
|
|
3879
|
+
}
|
|
3880
|
+
const spread = findFragmentSpreadAtOffset(preprocessed, offset);
|
|
3881
|
+
if (spread?.name.value && spread.name.loc) {
|
|
3882
|
+
const gqlLineOffsets = computeLineOffsets(preprocessed);
|
|
3883
|
+
const start = mapper.graphqlToTs(offsetToPosition(gqlLineOffsets, spread.name.loc.start));
|
|
3884
|
+
const end = mapper.graphqlToTs(offsetToPosition(gqlLineOffsets, spread.name.loc.end));
|
|
3885
|
+
return {
|
|
3886
|
+
range: {
|
|
3887
|
+
start,
|
|
3888
|
+
end
|
|
3889
|
+
},
|
|
3890
|
+
placeholder: spread.name.value
|
|
3891
|
+
};
|
|
3892
|
+
}
|
|
3893
|
+
return null;
|
|
3894
|
+
};
|
|
3895
|
+
/** Perform a rename across the workspace. */
|
|
3896
|
+
const handleRename = (input) => {
|
|
3897
|
+
const { template, tsSource, tsPosition, newName, allFragments, findSpreadLocations } = input;
|
|
3898
|
+
const { preprocessed } = preprocessFragmentArgs(template.content);
|
|
3899
|
+
const mapper = createPositionMapper({
|
|
3900
|
+
tsSource,
|
|
3901
|
+
contentStartOffset: template.contentRange.start,
|
|
3902
|
+
graphqlContent: template.content
|
|
3903
|
+
});
|
|
3904
|
+
const gqlPosition = mapper.tsToGraphql(tsPosition);
|
|
3905
|
+
if (!gqlPosition) {
|
|
3906
|
+
return null;
|
|
3907
|
+
}
|
|
3908
|
+
const offset = positionToOffset$1(computeLineOffsets(preprocessed), gqlPosition);
|
|
3909
|
+
const fragmentName = resolveFragmentNameAtOffset(preprocessed, offset);
|
|
3910
|
+
if (!fragmentName) {
|
|
3911
|
+
return null;
|
|
3912
|
+
}
|
|
3913
|
+
const changes = {};
|
|
3914
|
+
const addEdit = (uri, range, text) => {
|
|
3915
|
+
if (!changes[uri]) {
|
|
3916
|
+
changes[uri] = [];
|
|
3917
|
+
}
|
|
3918
|
+
changes[uri].push({
|
|
3919
|
+
range,
|
|
3920
|
+
newText: text
|
|
3921
|
+
});
|
|
3922
|
+
};
|
|
3923
|
+
for (const r of computeFragmentDefinitionRanges(fragmentName, allFragments)) {
|
|
3924
|
+
addEdit(r.uri, r.range, newName);
|
|
3925
|
+
}
|
|
3926
|
+
for (const r of computeSpreadLocationRanges(findSpreadLocations(fragmentName))) {
|
|
3927
|
+
addEdit(r.uri, r.range, newName);
|
|
3928
|
+
}
|
|
3929
|
+
if (Object.keys(changes).length === 0) {
|
|
3930
|
+
return null;
|
|
3931
|
+
}
|
|
3932
|
+
return { changes };
|
|
3933
|
+
};
|
|
3934
|
+
|
|
3935
|
+
//#endregion
|
|
3936
|
+
//#region packages/lsp/src/server.ts
|
|
3937
|
+
/**
|
|
3938
|
+
* LSP server: wires all components together via vscode-languageserver.
|
|
3939
|
+
* @module
|
|
3940
|
+
*/
|
|
3941
|
+
const createLspServer = (options) => {
|
|
3942
|
+
const connection = options?.connection ?? createConnection(ProposedFeatures.all);
|
|
3943
|
+
const documents = new TextDocuments(TextDocument);
|
|
3944
|
+
let registry;
|
|
3945
|
+
const swcNotification = { shown: false };
|
|
3946
|
+
const publishDiagnosticsForDocument = (uri) => {
|
|
3947
|
+
if (!registry) {
|
|
3948
|
+
return;
|
|
3949
|
+
}
|
|
3950
|
+
const ctx = registry.resolveForUri(uri);
|
|
3951
|
+
if (!ctx) {
|
|
3952
|
+
connection.sendDiagnostics({
|
|
3953
|
+
uri,
|
|
3954
|
+
diagnostics: []
|
|
3955
|
+
});
|
|
3956
|
+
return;
|
|
3957
|
+
}
|
|
3958
|
+
const state = ctx.documentManager.get(uri);
|
|
3959
|
+
if (!state) {
|
|
3960
|
+
connection.sendDiagnostics({
|
|
3961
|
+
uri,
|
|
3962
|
+
diagnostics: []
|
|
3963
|
+
});
|
|
3964
|
+
return;
|
|
3965
|
+
}
|
|
3966
|
+
const allDiagnostics = state.templates.flatMap((template) => {
|
|
3967
|
+
const entry = ctx.schemaResolver.getSchema(template.schemaName);
|
|
3968
|
+
if (!entry) {
|
|
3969
|
+
return [];
|
|
3970
|
+
}
|
|
3971
|
+
const externalFragments = ctx.documentManager.getExternalFragments(uri, template.schemaName).map((f) => f.definition);
|
|
3972
|
+
return [...computeTemplateDiagnostics({
|
|
3973
|
+
template,
|
|
3974
|
+
schema: entry.schema,
|
|
3975
|
+
tsSource: state.source,
|
|
3976
|
+
externalFragments
|
|
3977
|
+
})];
|
|
3978
|
+
});
|
|
3979
|
+
connection.sendDiagnostics({
|
|
3980
|
+
uri,
|
|
3981
|
+
diagnostics: allDiagnostics
|
|
3982
|
+
});
|
|
3983
|
+
};
|
|
3984
|
+
const publishDiagnosticsForAllOpen = () => {
|
|
3985
|
+
for (const doc of documents.all()) {
|
|
3986
|
+
publishDiagnosticsForDocument(doc.uri);
|
|
3987
|
+
}
|
|
3988
|
+
};
|
|
3989
|
+
connection.onInitialize((params) => {
|
|
3990
|
+
const rootUri = params.rootUri ?? params.rootPath;
|
|
3991
|
+
if (!rootUri) {
|
|
3992
|
+
connection.window.showErrorMessage("soda-gql LSP: no workspace root provided");
|
|
3993
|
+
return { capabilities: {} };
|
|
3994
|
+
}
|
|
3995
|
+
const rootPath = rootUri.startsWith("file://") ? fileURLToPath(rootUri) : rootUri;
|
|
3996
|
+
let configPaths = findAllConfigFiles(rootPath);
|
|
3997
|
+
if (configPaths.length === 0) {
|
|
3998
|
+
const singleConfigPath = findConfigFile(rootPath);
|
|
3999
|
+
if (!singleConfigPath) {
|
|
4000
|
+
connection.window.showErrorMessage("soda-gql LSP: no config file found");
|
|
4001
|
+
return { capabilities: {} };
|
|
4002
|
+
}
|
|
4003
|
+
configPaths = [singleConfigPath];
|
|
4004
|
+
}
|
|
4005
|
+
const registryResult = createConfigRegistry(configPaths);
|
|
4006
|
+
if (registryResult.isErr()) {
|
|
4007
|
+
connection.window.showErrorMessage(`soda-gql LSP: ${registryResult.error.message}`);
|
|
4008
|
+
return { capabilities: {} };
|
|
4009
|
+
}
|
|
4010
|
+
registry = registryResult.value;
|
|
4011
|
+
return { capabilities: {
|
|
4012
|
+
textDocumentSync: TextDocumentSyncKind.Full,
|
|
4013
|
+
hoverProvider: true,
|
|
4014
|
+
documentSymbolProvider: true,
|
|
4015
|
+
definitionProvider: true,
|
|
4016
|
+
referencesProvider: true,
|
|
4017
|
+
renameProvider: { prepareProvider: true },
|
|
4018
|
+
documentFormattingProvider: true,
|
|
4019
|
+
completionProvider: { triggerCharacters: [
|
|
4020
|
+
"{",
|
|
4021
|
+
"(",
|
|
4022
|
+
":",
|
|
4023
|
+
"@",
|
|
4024
|
+
"$",
|
|
4025
|
+
" ",
|
|
4026
|
+
"\n",
|
|
4027
|
+
"."
|
|
4028
|
+
] },
|
|
4029
|
+
codeActionProvider: { codeActionKinds: ["refactor.extract"] }
|
|
4030
|
+
} };
|
|
4031
|
+
});
|
|
4032
|
+
connection.onInitialized(() => {
|
|
4033
|
+
connection.client.register(DidChangeWatchedFilesNotification.type, { watchers: [{ globPattern: "**/*.graphql" }] });
|
|
4034
|
+
});
|
|
4035
|
+
documents.onDidChangeContent((change) => {
|
|
4036
|
+
if (!registry) {
|
|
4037
|
+
return;
|
|
4038
|
+
}
|
|
4039
|
+
const ctx = registry.resolveForUri(change.document.uri);
|
|
4040
|
+
if (!ctx) {
|
|
4041
|
+
return;
|
|
4042
|
+
}
|
|
4043
|
+
const state = ctx.documentManager.update(change.document.uri, change.document.version, change.document.getText());
|
|
4044
|
+
checkSwcUnavailable(state.swcUnavailable, swcNotification, (msg) => connection.window.showErrorMessage(msg));
|
|
4045
|
+
publishDiagnosticsForDocument(change.document.uri);
|
|
4046
|
+
});
|
|
4047
|
+
documents.onDidClose((change) => {
|
|
4048
|
+
if (!registry) {
|
|
4049
|
+
return;
|
|
4050
|
+
}
|
|
4051
|
+
const ctx = registry.resolveForUri(change.document.uri);
|
|
4052
|
+
if (ctx) {
|
|
4053
|
+
ctx.documentManager.remove(change.document.uri);
|
|
4054
|
+
}
|
|
4055
|
+
connection.sendDiagnostics({
|
|
4056
|
+
uri: change.document.uri,
|
|
4057
|
+
diagnostics: []
|
|
4058
|
+
});
|
|
4059
|
+
});
|
|
4060
|
+
connection.onCompletion((params) => {
|
|
4061
|
+
if (!registry) {
|
|
4062
|
+
return [];
|
|
4063
|
+
}
|
|
4064
|
+
const ctx = registry.resolveForUri(params.textDocument.uri);
|
|
4065
|
+
if (!ctx) {
|
|
4066
|
+
return [];
|
|
4067
|
+
}
|
|
4068
|
+
const template = ctx.documentManager.findTemplateAtOffset(params.textDocument.uri, positionToOffset(documents.get(params.textDocument.uri)?.getText() ?? "", params.position));
|
|
4069
|
+
if (!template) {
|
|
4070
|
+
return [];
|
|
4071
|
+
}
|
|
4072
|
+
const entry = ctx.schemaResolver.getSchema(template.schemaName);
|
|
4073
|
+
if (!entry) {
|
|
4074
|
+
return [];
|
|
4075
|
+
}
|
|
4076
|
+
const doc = documents.get(params.textDocument.uri);
|
|
4077
|
+
if (!doc) {
|
|
4078
|
+
return [];
|
|
4079
|
+
}
|
|
4080
|
+
const externalFragments = ctx.documentManager.getExternalFragments(params.textDocument.uri, template.schemaName).map((f) => f.definition);
|
|
4081
|
+
return handleCompletion({
|
|
4082
|
+
template,
|
|
4083
|
+
schema: entry.schema,
|
|
4084
|
+
tsSource: doc.getText(),
|
|
4085
|
+
tsPosition: {
|
|
4086
|
+
line: params.position.line,
|
|
4087
|
+
character: params.position.character
|
|
4088
|
+
},
|
|
4089
|
+
externalFragments
|
|
4090
|
+
});
|
|
4091
|
+
});
|
|
4092
|
+
connection.onHover((params) => {
|
|
4093
|
+
if (!registry) {
|
|
4094
|
+
return null;
|
|
4095
|
+
}
|
|
4096
|
+
const ctx = registry.resolveForUri(params.textDocument.uri);
|
|
4097
|
+
if (!ctx) {
|
|
4098
|
+
return null;
|
|
4099
|
+
}
|
|
4100
|
+
const doc = documents.get(params.textDocument.uri);
|
|
4101
|
+
if (!doc) {
|
|
4102
|
+
return null;
|
|
4103
|
+
}
|
|
4104
|
+
const template = ctx.documentManager.findTemplateAtOffset(params.textDocument.uri, positionToOffset(doc.getText(), params.position));
|
|
4105
|
+
if (!template) {
|
|
4106
|
+
return null;
|
|
4107
|
+
}
|
|
4108
|
+
const entry = ctx.schemaResolver.getSchema(template.schemaName);
|
|
4109
|
+
if (!entry) {
|
|
4110
|
+
return null;
|
|
4111
|
+
}
|
|
4112
|
+
return handleHover({
|
|
4113
|
+
template,
|
|
4114
|
+
schema: entry.schema,
|
|
4115
|
+
tsSource: doc.getText(),
|
|
4116
|
+
tsPosition: {
|
|
4117
|
+
line: params.position.line,
|
|
4118
|
+
character: params.position.character
|
|
4119
|
+
}
|
|
4120
|
+
});
|
|
4121
|
+
});
|
|
4122
|
+
connection.onDefinition(async (params) => {
|
|
4123
|
+
if (!registry) {
|
|
4124
|
+
return [];
|
|
4125
|
+
}
|
|
4126
|
+
const ctx = registry.resolveForUri(params.textDocument.uri);
|
|
4127
|
+
if (!ctx) {
|
|
4128
|
+
return [];
|
|
4129
|
+
}
|
|
4130
|
+
const doc = documents.get(params.textDocument.uri);
|
|
4131
|
+
if (!doc) {
|
|
4132
|
+
return [];
|
|
4133
|
+
}
|
|
4134
|
+
const template = ctx.documentManager.findTemplateAtOffset(params.textDocument.uri, positionToOffset(doc.getText(), params.position));
|
|
4135
|
+
if (!template) {
|
|
4136
|
+
return [];
|
|
4137
|
+
}
|
|
4138
|
+
const externalFragments = ctx.documentManager.getExternalFragments(params.textDocument.uri, template.schemaName);
|
|
4139
|
+
const entry = ctx.schemaResolver.getSchema(template.schemaName);
|
|
4140
|
+
return handleDefinition({
|
|
4141
|
+
template,
|
|
4142
|
+
tsSource: doc.getText(),
|
|
4143
|
+
tsPosition: {
|
|
4144
|
+
line: params.position.line,
|
|
4145
|
+
character: params.position.character
|
|
4146
|
+
},
|
|
4147
|
+
externalFragments,
|
|
4148
|
+
schema: entry?.schema,
|
|
4149
|
+
schemaFiles: entry?.files
|
|
4150
|
+
});
|
|
4151
|
+
});
|
|
4152
|
+
connection.onReferences((params) => {
|
|
4153
|
+
if (!registry) {
|
|
4154
|
+
return [];
|
|
4155
|
+
}
|
|
4156
|
+
const ctx = registry.resolveForUri(params.textDocument.uri);
|
|
4157
|
+
if (!ctx) {
|
|
4158
|
+
return [];
|
|
4159
|
+
}
|
|
4160
|
+
const doc = documents.get(params.textDocument.uri);
|
|
4161
|
+
if (!doc) {
|
|
4162
|
+
return [];
|
|
4163
|
+
}
|
|
4164
|
+
const template = ctx.documentManager.findTemplateAtOffset(params.textDocument.uri, positionToOffset(doc.getText(), params.position));
|
|
4165
|
+
if (!template) {
|
|
4166
|
+
return [];
|
|
4167
|
+
}
|
|
4168
|
+
return handleReferences({
|
|
4169
|
+
template,
|
|
4170
|
+
tsSource: doc.getText(),
|
|
4171
|
+
tsPosition: {
|
|
4172
|
+
line: params.position.line,
|
|
4173
|
+
character: params.position.character
|
|
4174
|
+
},
|
|
4175
|
+
allFragments: ctx.documentManager.getAllFragments(template.schemaName),
|
|
4176
|
+
findSpreadLocations: (name) => ctx.documentManager.findFragmentSpreadLocations(name, template.schemaName)
|
|
4177
|
+
});
|
|
4178
|
+
});
|
|
4179
|
+
connection.onPrepareRename((params) => {
|
|
4180
|
+
if (!registry) {
|
|
4181
|
+
return null;
|
|
4182
|
+
}
|
|
4183
|
+
const ctx = registry.resolveForUri(params.textDocument.uri);
|
|
4184
|
+
if (!ctx) {
|
|
4185
|
+
return null;
|
|
4186
|
+
}
|
|
4187
|
+
const doc = documents.get(params.textDocument.uri);
|
|
4188
|
+
if (!doc) {
|
|
4189
|
+
return null;
|
|
4190
|
+
}
|
|
4191
|
+
const template = ctx.documentManager.findTemplateAtOffset(params.textDocument.uri, positionToOffset(doc.getText(), params.position));
|
|
4192
|
+
if (!template) {
|
|
4193
|
+
return null;
|
|
4194
|
+
}
|
|
4195
|
+
return handlePrepareRename({
|
|
4196
|
+
template,
|
|
4197
|
+
tsSource: doc.getText(),
|
|
4198
|
+
tsPosition: {
|
|
4199
|
+
line: params.position.line,
|
|
4200
|
+
character: params.position.character
|
|
4201
|
+
}
|
|
4202
|
+
});
|
|
4203
|
+
});
|
|
4204
|
+
connection.onRenameRequest((params) => {
|
|
4205
|
+
if (!registry) {
|
|
4206
|
+
return null;
|
|
4207
|
+
}
|
|
4208
|
+
const ctx = registry.resolveForUri(params.textDocument.uri);
|
|
4209
|
+
if (!ctx) {
|
|
4210
|
+
return null;
|
|
4211
|
+
}
|
|
4212
|
+
const doc = documents.get(params.textDocument.uri);
|
|
4213
|
+
if (!doc) {
|
|
4214
|
+
return null;
|
|
4215
|
+
}
|
|
4216
|
+
const template = ctx.documentManager.findTemplateAtOffset(params.textDocument.uri, positionToOffset(doc.getText(), params.position));
|
|
4217
|
+
if (!template) {
|
|
4218
|
+
return null;
|
|
4219
|
+
}
|
|
4220
|
+
return handleRename({
|
|
4221
|
+
template,
|
|
4222
|
+
tsSource: doc.getText(),
|
|
4223
|
+
tsPosition: {
|
|
4224
|
+
line: params.position.line,
|
|
4225
|
+
character: params.position.character
|
|
4226
|
+
},
|
|
4227
|
+
newName: params.newName,
|
|
4228
|
+
allFragments: ctx.documentManager.getAllFragments(template.schemaName),
|
|
4229
|
+
findSpreadLocations: (name) => ctx.documentManager.findFragmentSpreadLocations(name, template.schemaName)
|
|
4230
|
+
});
|
|
4231
|
+
});
|
|
4232
|
+
connection.onDocumentSymbol((params) => {
|
|
4233
|
+
if (!registry) {
|
|
4234
|
+
return [];
|
|
4235
|
+
}
|
|
4236
|
+
const ctx = registry.resolveForUri(params.textDocument.uri);
|
|
4237
|
+
if (!ctx) {
|
|
4238
|
+
return [];
|
|
4239
|
+
}
|
|
4240
|
+
const state = ctx.documentManager.get(params.textDocument.uri);
|
|
4241
|
+
if (!state) {
|
|
4242
|
+
return [];
|
|
4243
|
+
}
|
|
4244
|
+
return handleDocumentSymbol({
|
|
4245
|
+
templates: state.templates,
|
|
4246
|
+
tsSource: state.source
|
|
4247
|
+
});
|
|
4248
|
+
});
|
|
4249
|
+
connection.onDocumentFormatting((params) => {
|
|
4250
|
+
if (!registry) {
|
|
4251
|
+
return [];
|
|
4252
|
+
}
|
|
4253
|
+
const ctx = registry.resolveForUri(params.textDocument.uri);
|
|
4254
|
+
if (!ctx) {
|
|
4255
|
+
return [];
|
|
4256
|
+
}
|
|
4257
|
+
const state = ctx.documentManager.get(params.textDocument.uri);
|
|
4258
|
+
if (!state) {
|
|
4259
|
+
return [];
|
|
4260
|
+
}
|
|
4261
|
+
return handleFormatting({
|
|
4262
|
+
templates: state.templates,
|
|
4263
|
+
tsSource: state.source
|
|
4264
|
+
});
|
|
4265
|
+
});
|
|
4266
|
+
connection.onCodeAction((params) => {
|
|
4267
|
+
if (!registry) {
|
|
4268
|
+
return [];
|
|
4269
|
+
}
|
|
4270
|
+
const ctx = registry.resolveForUri(params.textDocument.uri);
|
|
4271
|
+
if (!ctx) {
|
|
4272
|
+
return [];
|
|
4273
|
+
}
|
|
4274
|
+
const doc = documents.get(params.textDocument.uri);
|
|
4275
|
+
if (!doc) {
|
|
4276
|
+
return [];
|
|
4277
|
+
}
|
|
4278
|
+
const template = ctx.documentManager.findTemplateAtOffset(params.textDocument.uri, positionToOffset(doc.getText(), params.range.start));
|
|
4279
|
+
if (!template) {
|
|
4280
|
+
return [];
|
|
4281
|
+
}
|
|
4282
|
+
const entry = ctx.schemaResolver.getSchema(template.schemaName);
|
|
4283
|
+
if (!entry) {
|
|
4284
|
+
return [];
|
|
4285
|
+
}
|
|
4286
|
+
return handleCodeAction({
|
|
4287
|
+
template,
|
|
4288
|
+
schema: entry.schema,
|
|
4289
|
+
tsSource: doc.getText(),
|
|
4290
|
+
uri: params.textDocument.uri,
|
|
4291
|
+
selectionRange: {
|
|
4292
|
+
start: {
|
|
4293
|
+
line: params.range.start.line,
|
|
4294
|
+
character: params.range.start.character
|
|
4295
|
+
},
|
|
4296
|
+
end: {
|
|
4297
|
+
line: params.range.end.line,
|
|
4298
|
+
character: params.range.end.character
|
|
4299
|
+
}
|
|
4300
|
+
}
|
|
4301
|
+
});
|
|
4302
|
+
});
|
|
4303
|
+
connection.onDidChangeWatchedFiles((_params) => {
|
|
4304
|
+
if (!registry) {
|
|
4305
|
+
return;
|
|
4306
|
+
}
|
|
4307
|
+
const graphqlChanged = _params.changes.some((change) => change.uri.endsWith(".graphql") && (change.type === FileChangeType.Changed || change.type === FileChangeType.Created));
|
|
4308
|
+
if (graphqlChanged) {
|
|
4309
|
+
const result = registry.reloadAllSchemas();
|
|
4310
|
+
publishDiagnosticsForAllOpen();
|
|
4311
|
+
if (result.isErr()) {
|
|
4312
|
+
for (const error of result.error) {
|
|
4313
|
+
connection.window.showErrorMessage(`soda-gql LSP: schema reload failed: ${error.message}`);
|
|
4314
|
+
}
|
|
4315
|
+
}
|
|
4316
|
+
}
|
|
4317
|
+
});
|
|
4318
|
+
documents.listen(connection);
|
|
4319
|
+
return { start: () => {
|
|
4320
|
+
connection.listen();
|
|
4321
|
+
} };
|
|
4322
|
+
};
|
|
4323
|
+
/** Check if SWC is unavailable and show a one-time error notification. */
|
|
4324
|
+
const checkSwcUnavailable = (swcUnavailable, state, showError) => {
|
|
4325
|
+
if (swcUnavailable && !state.shown) {
|
|
4326
|
+
state.shown = true;
|
|
4327
|
+
showError(`soda-gql LSP: ${lspErrors.swcResolutionFailed().message}`);
|
|
4328
|
+
}
|
|
4329
|
+
};
|
|
4330
|
+
/** Convert LSP Position to byte offset in source text. */
|
|
4331
|
+
const positionToOffset = (source, position) => {
|
|
4332
|
+
let line = 0;
|
|
4333
|
+
let offset = 0;
|
|
4334
|
+
while (line < position.line && offset < source.length) {
|
|
4335
|
+
if (source.charCodeAt(offset) === 10) {
|
|
4336
|
+
line++;
|
|
4337
|
+
}
|
|
4338
|
+
offset++;
|
|
4339
|
+
}
|
|
4340
|
+
return offset + position.character;
|
|
4341
|
+
};
|
|
4342
|
+
|
|
4343
|
+
//#endregion
|
|
4344
|
+
export { createDocumentManager as a, lspErrors as i, createSchemaResolver as n, preprocessFragmentArgs as o, createPositionMapper as r, createLspServer as t };
|
|
4345
|
+
//# sourceMappingURL=server-BgXl3W41.mjs.map
|