vscode-apollo 1.20.0 → 2.0.1
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/.circleci/config.yml +27 -18
- package/.git-blame-ignore-revs +2 -0
- package/.nvmrc +1 -1
- package/.vscode/launch.json +9 -4
- package/.vscode/tasks.json +58 -16
- package/.vscodeignore +12 -1
- package/CHANGELOG.md +84 -0
- package/CODEOWNERS +4 -0
- package/README.md +97 -48
- package/graphql.configuration.json +5 -1
- package/images/marketplace/apollo-wordmark.png +0 -0
- package/jest.config.ts +14 -4
- package/jest.e2e.config.js +17 -0
- package/package.json +67 -68
- package/renovate.json +7 -0
- package/sampleWorkspace/clientSchema/apollo.config.cjs +10 -0
- package/sampleWorkspace/clientSchema/src/clientSchema.js +16 -0
- package/sampleWorkspace/clientSchema/src/test.js +18 -0
- package/sampleWorkspace/fixtures/starwarsSchema.graphql +299 -0
- package/sampleWorkspace/httpSchema/apollo.config.ts +8 -0
- package/sampleWorkspace/httpSchema/src/test.js +9 -0
- package/sampleWorkspace/localSchema/apollo.config.js +8 -0
- package/sampleWorkspace/localSchema/src/test.js +8 -0
- package/sampleWorkspace/localSchemaArray/apollo.config.js +12 -0
- package/sampleWorkspace/localSchemaArray/planets.graphql +20 -0
- package/sampleWorkspace/localSchemaArray/src/test.js +12 -0
- package/sampleWorkspace/sampleWorkspace.code-workspace +20 -0
- package/sampleWorkspace/spotifyGraph/apollo.config.mjs +5 -0
- package/sampleWorkspace/spotifyGraph/src/test.js +11 -0
- package/src/__e2e__/mockServer.js +117 -0
- package/src/__e2e__/mocks.js +13094 -0
- package/src/__e2e__/run.js +23 -0
- package/src/__e2e__/runTests.js +44 -0
- package/src/__e2e__/setup.js +1 -0
- package/src/__e2e__/vscode-environment.js +16 -0
- package/src/__e2e__/vscode.js +1 -0
- package/src/build.js +57 -0
- package/src/env/index.ts +0 -3
- package/src/extension.ts +251 -225
- package/src/language-server/__e2e__/clientSchema.e2e.ts +147 -0
- package/src/language-server/__e2e__/httpSchema.e2e.ts +21 -0
- package/src/language-server/__e2e__/localSchema.e2e.ts +25 -0
- package/src/language-server/__e2e__/localSchemaArray.e2e.ts +31 -0
- package/src/language-server/__e2e__/studioGraph.e2e.ts +65 -0
- package/src/language-server/__e2e__/utils.ts +151 -0
- package/src/language-server/__tests__/diagnostics.test.ts +8 -8
- package/src/language-server/__tests__/fileSet.test.ts +1 -1
- package/src/language-server/__tests__/fixtures/starwarsSchema.ts +2 -2
- package/src/language-server/config/__tests__/config.ts +22 -96
- package/src/language-server/config/__tests__/loadConfig.ts +120 -220
- package/src/language-server/config/__tests__/utils.ts +22 -29
- package/src/language-server/config/config.ts +221 -156
- package/src/language-server/config/loadConfig.ts +32 -153
- package/src/language-server/config/loadTsConfig.ts +70 -0
- package/src/language-server/config/utils.ts +5 -16
- package/src/language-server/diagnostics.ts +17 -8
- package/src/language-server/document.ts +16 -16
- package/src/language-server/engine/index.ts +57 -39
- package/src/language-server/engine/operations/frontendUrlRoot.ts +9 -1
- package/src/language-server/engine/operations/schemaTagsAndFieldStats.ts +9 -1
- package/src/language-server/errors/__tests__/NoMissingClientDirectives.test.ts +10 -5
- package/src/language-server/errors/logger.ts +1 -1
- package/src/language-server/errors/validation.ts +20 -23
- package/src/language-server/fileSet.ts +10 -12
- package/src/language-server/format.ts +1 -1
- package/src/language-server/graphqlTypes.ts +13020 -3455
- package/src/language-server/index.ts +0 -1
- package/src/language-server/languageProvider.ts +29 -32
- package/src/language-server/loadingHandler.ts +10 -27
- package/src/language-server/project/base.ts +32 -25
- package/src/language-server/project/client.ts +80 -114
- package/src/language-server/project/defaultClientSchema.ts +29 -4
- package/src/language-server/providers/schema/__tests__/file.ts +60 -19
- package/src/language-server/providers/schema/base.ts +2 -2
- package/src/language-server/providers/schema/endpoint.ts +15 -34
- package/src/language-server/providers/schema/engine.ts +25 -18
- package/src/language-server/providers/schema/file.ts +41 -32
- package/src/language-server/providers/schema/index.ts +5 -21
- package/src/language-server/server.ts +72 -50
- package/src/language-server/typings/graphql.d.ts +3 -3
- package/src/language-server/utilities/__tests__/graphql.test.ts +42 -54
- package/src/language-server/utilities/debouncer.ts +1 -1
- package/src/language-server/utilities/debug.ts +6 -5
- package/src/language-server/utilities/graphql.ts +17 -16
- package/src/language-server/utilities/source.ts +16 -16
- package/src/language-server/utilities/uri.ts +2 -2
- package/src/language-server/workspace.ts +29 -37
- package/src/languageServerClient.ts +4 -4
- package/src/messages.ts +38 -47
- package/src/tools/__tests__/buildServiceDefinition.test.ts +2 -2
- package/src/tools/buildServiceDefinition.ts +11 -11
- package/src/tools/schema/resolveObject.ts +1 -1
- package/src/tools/utilities/predicates.ts +1 -1
- package/src/utils.ts +7 -6
- package/syntaxes/graphql.dart.json +2 -4
- package/syntaxes/graphql.ex.json +1 -4
- package/tsconfig.build.json +8 -1
- package/tsconfig.json +5 -3
- package/src/env/fetch/fetch.ts +0 -32
- package/src/env/fetch/global.ts +0 -30
- package/src/env/fetch/index.d.ts +0 -2
- package/src/env/fetch/index.ts +0 -2
- package/src/env/fetch/url.ts +0 -9
- package/src/env/polyfills/array.ts +0 -17
- package/src/env/polyfills/index.ts +0 -2
- package/src/env/polyfills/object.ts +0 -7
- package/src/language-server/engine/GraphQLDataSource.ts +0 -124
- package/src/language-server/project/service.ts +0 -48
- package/src/language-server/typings/codemirror.d.ts +0 -4
|
@@ -32,8 +32,7 @@ describe("withTypenameFieldAddedWhereNeeded", () => {
|
|
|
32
32
|
value
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
-
}
|
|
36
|
-
"
|
|
35
|
+
}"
|
|
37
36
|
`);
|
|
38
37
|
});
|
|
39
38
|
|
|
@@ -71,8 +70,7 @@ describe("withTypenameFieldAddedWhereNeeded", () => {
|
|
|
71
70
|
}
|
|
72
71
|
}
|
|
73
72
|
}
|
|
74
|
-
}
|
|
75
|
-
"
|
|
73
|
+
}"
|
|
76
74
|
`);
|
|
77
75
|
});
|
|
78
76
|
});
|
|
@@ -83,14 +81,13 @@ describe("removeDirectiveAnnotatedFields", () => {
|
|
|
83
81
|
print(
|
|
84
82
|
removeDirectiveAnnotatedFields(
|
|
85
83
|
parse(`query Query { fieldToKeep fieldToRemove @client }`),
|
|
86
|
-
["client"]
|
|
87
|
-
)
|
|
88
|
-
)
|
|
84
|
+
["client"],
|
|
85
|
+
),
|
|
86
|
+
),
|
|
89
87
|
).toMatchInlineSnapshot(`
|
|
90
88
|
"query Query {
|
|
91
89
|
fieldToKeep
|
|
92
|
-
}
|
|
93
|
-
"
|
|
90
|
+
}"
|
|
94
91
|
`);
|
|
95
92
|
});
|
|
96
93
|
|
|
@@ -106,14 +103,13 @@ describe("removeDirectiveAnnotatedFields", () => {
|
|
|
106
103
|
}
|
|
107
104
|
}
|
|
108
105
|
`),
|
|
109
|
-
["client"]
|
|
110
|
-
)
|
|
111
|
-
)
|
|
106
|
+
["client"],
|
|
107
|
+
),
|
|
108
|
+
),
|
|
112
109
|
).toMatchInlineSnapshot(`
|
|
113
110
|
"query Query {
|
|
114
111
|
fieldToKeep
|
|
115
|
-
}
|
|
116
|
-
"
|
|
112
|
+
}"
|
|
117
113
|
`);
|
|
118
114
|
});
|
|
119
115
|
|
|
@@ -130,16 +126,15 @@ describe("removeDirectiveAnnotatedFields", () => {
|
|
|
130
126
|
hello
|
|
131
127
|
}
|
|
132
128
|
`),
|
|
133
|
-
["client"]
|
|
134
|
-
)
|
|
135
|
-
)
|
|
129
|
+
["client"],
|
|
130
|
+
),
|
|
131
|
+
),
|
|
136
132
|
).toMatchInlineSnapshot(`
|
|
137
133
|
"{
|
|
138
134
|
me {
|
|
139
135
|
name
|
|
140
136
|
}
|
|
141
|
-
}
|
|
142
|
-
"
|
|
137
|
+
}"
|
|
143
138
|
`);
|
|
144
139
|
});
|
|
145
140
|
|
|
@@ -155,16 +150,15 @@ describe("removeDirectiveAnnotatedFields", () => {
|
|
|
155
150
|
}
|
|
156
151
|
}
|
|
157
152
|
`),
|
|
158
|
-
["client"]
|
|
159
|
-
)
|
|
160
|
-
)
|
|
153
|
+
["client"],
|
|
154
|
+
),
|
|
155
|
+
),
|
|
161
156
|
).toMatchInlineSnapshot(`
|
|
162
157
|
"{
|
|
163
158
|
me {
|
|
164
159
|
name
|
|
165
160
|
}
|
|
166
|
-
}
|
|
167
|
-
"
|
|
161
|
+
}"
|
|
168
162
|
`);
|
|
169
163
|
});
|
|
170
164
|
|
|
@@ -181,16 +175,15 @@ describe("removeDirectiveAnnotatedFields", () => {
|
|
|
181
175
|
... ClientObject
|
|
182
176
|
}
|
|
183
177
|
`),
|
|
184
|
-
["client"]
|
|
185
|
-
)
|
|
186
|
-
)
|
|
178
|
+
["client"],
|
|
179
|
+
),
|
|
180
|
+
),
|
|
187
181
|
).toMatchInlineSnapshot(`
|
|
188
182
|
"{
|
|
189
183
|
me {
|
|
190
184
|
name
|
|
191
185
|
}
|
|
192
|
-
}
|
|
193
|
-
"
|
|
186
|
+
}"
|
|
194
187
|
`);
|
|
195
188
|
});
|
|
196
189
|
|
|
@@ -232,9 +225,9 @@ describe("removeDirectiveAnnotatedFields", () => {
|
|
|
232
225
|
}
|
|
233
226
|
}
|
|
234
227
|
`),
|
|
235
|
-
["client"]
|
|
236
|
-
)
|
|
237
|
-
)
|
|
228
|
+
["client"],
|
|
229
|
+
),
|
|
230
|
+
),
|
|
238
231
|
).toMatchInlineSnapshot(`
|
|
239
232
|
"fragment LaunchTile on Launch {
|
|
240
233
|
__typename
|
|
@@ -258,8 +251,7 @@ describe("removeDirectiveAnnotatedFields", () => {
|
|
|
258
251
|
}
|
|
259
252
|
...LaunchTile
|
|
260
253
|
}
|
|
261
|
-
}
|
|
262
|
-
"
|
|
254
|
+
}"
|
|
263
255
|
`);
|
|
264
256
|
});
|
|
265
257
|
|
|
@@ -287,9 +279,9 @@ describe("removeDirectiveAnnotatedFields", () => {
|
|
|
287
279
|
}
|
|
288
280
|
}
|
|
289
281
|
`),
|
|
290
|
-
["client"]
|
|
291
|
-
)
|
|
292
|
-
)
|
|
282
|
+
["client"],
|
|
283
|
+
),
|
|
284
|
+
),
|
|
293
285
|
).toMatchInlineSnapshot(`
|
|
294
286
|
"fragment One on Node {
|
|
295
287
|
...Two
|
|
@@ -308,8 +300,7 @@ describe("removeDirectiveAnnotatedFields", () => {
|
|
|
308
300
|
me {
|
|
309
301
|
...One
|
|
310
302
|
}
|
|
311
|
-
}
|
|
312
|
-
"
|
|
303
|
+
}"
|
|
313
304
|
`);
|
|
314
305
|
});
|
|
315
306
|
|
|
@@ -333,16 +324,15 @@ describe("removeDirectiveAnnotatedFields", () => {
|
|
|
333
324
|
}
|
|
334
325
|
}
|
|
335
326
|
`),
|
|
336
|
-
["client"]
|
|
337
|
-
)
|
|
338
|
-
)
|
|
327
|
+
["client"],
|
|
328
|
+
),
|
|
329
|
+
),
|
|
339
330
|
).toMatchInlineSnapshot(`
|
|
340
331
|
"{
|
|
341
332
|
me {
|
|
342
333
|
name
|
|
343
334
|
}
|
|
344
|
-
}
|
|
345
|
-
"
|
|
335
|
+
}"
|
|
346
336
|
`);
|
|
347
337
|
});
|
|
348
338
|
|
|
@@ -366,14 +356,13 @@ describe("removeDirectiveAnnotatedFields", () => {
|
|
|
366
356
|
}
|
|
367
357
|
}
|
|
368
358
|
`),
|
|
369
|
-
["client"]
|
|
370
|
-
)
|
|
371
|
-
)
|
|
359
|
+
["client"],
|
|
360
|
+
),
|
|
361
|
+
),
|
|
372
362
|
).toMatchInlineSnapshot(`
|
|
373
363
|
"{
|
|
374
364
|
name
|
|
375
|
-
}
|
|
376
|
-
"
|
|
365
|
+
}"
|
|
377
366
|
`);
|
|
378
367
|
});
|
|
379
368
|
|
|
@@ -392,9 +381,9 @@ describe("removeDirectiveAnnotatedFields", () => {
|
|
|
392
381
|
}
|
|
393
382
|
}
|
|
394
383
|
`),
|
|
395
|
-
["client"]
|
|
396
|
-
)
|
|
397
|
-
)
|
|
384
|
+
["client"],
|
|
385
|
+
),
|
|
386
|
+
),
|
|
398
387
|
).toMatchInlineSnapshot(`
|
|
399
388
|
"fragment One on Node {
|
|
400
389
|
id
|
|
@@ -404,8 +393,7 @@ describe("removeDirectiveAnnotatedFields", () => {
|
|
|
404
393
|
me {
|
|
405
394
|
name
|
|
406
395
|
}
|
|
407
|
-
}
|
|
408
|
-
"
|
|
396
|
+
}"
|
|
409
397
|
`);
|
|
410
398
|
});
|
|
411
399
|
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LanguageServerNotifications as Notifications } from "../../messages";
|
|
2
|
+
import { Connection } from "vscode-languageserver/node";
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* for errors (and other logs in debug mode) we want to print
|
|
@@ -32,17 +33,17 @@ export class Debug {
|
|
|
32
33
|
public static SetConnection(conn: Connection) {
|
|
33
34
|
Debug.connection = conn;
|
|
34
35
|
Debug.infoLogger = (message) =>
|
|
35
|
-
Debug.connection!.sendNotification(
|
|
36
|
+
Debug.connection!.sendNotification(Notifications.ServerDebugMessage, {
|
|
36
37
|
type: "info",
|
|
37
38
|
message: message,
|
|
38
39
|
});
|
|
39
40
|
Debug.warningLogger = (message) =>
|
|
40
|
-
Debug.connection!.sendNotification(
|
|
41
|
+
Debug.connection!.sendNotification(Notifications.ServerDebugMessage, {
|
|
41
42
|
type: "warning",
|
|
42
43
|
message: message,
|
|
43
44
|
});
|
|
44
45
|
Debug.errorLogger = (message) =>
|
|
45
|
-
Debug.connection!.sendNotification(
|
|
46
|
+
Debug.connection!.sendNotification(Notifications.ServerDebugMessage, {
|
|
46
47
|
type: "error",
|
|
47
48
|
message: message,
|
|
48
49
|
});
|
|
@@ -81,7 +82,7 @@ export class Debug {
|
|
|
81
82
|
|
|
82
83
|
public static sendErrorTelemetry(message: string) {
|
|
83
84
|
Debug.connection &&
|
|
84
|
-
Debug.connection.sendNotification(
|
|
85
|
+
Debug.connection.sendNotification(Notifications.ServerDebugMessage, {
|
|
85
86
|
type: "errorTelemetry",
|
|
86
87
|
message: message,
|
|
87
88
|
});
|
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
isUnionType,
|
|
20
20
|
FragmentDefinitionNode,
|
|
21
21
|
InlineFragmentNode,
|
|
22
|
+
DocumentNode,
|
|
22
23
|
} from "graphql";
|
|
23
24
|
|
|
24
25
|
import { ExecutionContext } from "graphql/execution/execute";
|
|
@@ -36,7 +37,7 @@ export function isNamedNode(node: ASTNode): node is NamedNode {
|
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
export function isDirectiveDefinitionNode(
|
|
39
|
-
node: ASTNode
|
|
40
|
+
node: ASTNode,
|
|
40
41
|
): node is DirectiveDefinitionNode {
|
|
41
42
|
return node.kind === Kind.DIRECTIVE_DEFINITION;
|
|
42
43
|
}
|
|
@@ -58,7 +59,7 @@ export function highlightNodeForNode(node: ASTNode): ASTNode {
|
|
|
58
59
|
export function getFieldDef(
|
|
59
60
|
schema: GraphQLSchema,
|
|
60
61
|
parentType: GraphQLCompositeType,
|
|
61
|
-
fieldAST: FieldNode
|
|
62
|
+
fieldAST: FieldNode,
|
|
62
63
|
): GraphQLField<any, any> | undefined {
|
|
63
64
|
const name = fieldAST.name.value;
|
|
64
65
|
if (
|
|
@@ -93,7 +94,7 @@ export function getFieldDef(
|
|
|
93
94
|
*/
|
|
94
95
|
export function removeDirectives<AST extends ASTNode>(
|
|
95
96
|
ast: AST,
|
|
96
|
-
directiveNames: string[]
|
|
97
|
+
directiveNames: string[],
|
|
97
98
|
): AST {
|
|
98
99
|
if (!directiveNames.length) return ast;
|
|
99
100
|
return visit(ast, {
|
|
@@ -117,7 +118,7 @@ export function removeDirectives<AST extends ASTNode>(
|
|
|
117
118
|
*/
|
|
118
119
|
function removeOrphanedFragmentDefinitions<AST extends ASTNode>(
|
|
119
120
|
ast: AST,
|
|
120
|
-
fragmentNamesEligibleForRemoval: Set<string
|
|
121
|
+
fragmentNamesEligibleForRemoval: Set<string>,
|
|
121
122
|
): AST {
|
|
122
123
|
/**
|
|
123
124
|
* Flag to keep track of removing any fragments
|
|
@@ -172,7 +173,7 @@ function removeOrphanedFragmentDefinitions<AST extends ASTNode>(
|
|
|
172
173
|
*/
|
|
173
174
|
return removeOrphanedFragmentDefinitions(
|
|
174
175
|
ast,
|
|
175
|
-
fragmentNamesEligibleForRemoval
|
|
176
|
+
fragmentNamesEligibleForRemoval,
|
|
176
177
|
);
|
|
177
178
|
}
|
|
178
179
|
|
|
@@ -208,7 +209,7 @@ function removeNodesWithEmptySelectionSets<AST extends ASTNode>(ast: AST): AST {
|
|
|
208
209
|
*/
|
|
209
210
|
export function removeDirectiveAnnotatedFields<AST extends ASTNode>(
|
|
210
211
|
ast: AST,
|
|
211
|
-
directiveNames: string[]
|
|
212
|
+
directiveNames: string[],
|
|
212
213
|
): AST {
|
|
213
214
|
print;
|
|
214
215
|
if (!directiveNames.length) return ast;
|
|
@@ -236,7 +237,7 @@ export function removeDirectiveAnnotatedFields<AST extends ASTNode>(
|
|
|
236
237
|
"directives" in node &&
|
|
237
238
|
node.directives &&
|
|
238
239
|
node.directives.find((directive) =>
|
|
239
|
-
directiveNames.includes(directive.name.value)
|
|
240
|
+
directiveNames.includes(directive.name.value),
|
|
240
241
|
)
|
|
241
242
|
) {
|
|
242
243
|
/*
|
|
@@ -307,18 +308,18 @@ const typenameField = {
|
|
|
307
308
|
name: { kind: Kind.NAME, value: "__typename" },
|
|
308
309
|
};
|
|
309
310
|
|
|
310
|
-
export function withTypenameFieldAddedWhereNeeded(ast:
|
|
311
|
+
export function withTypenameFieldAddedWhereNeeded(ast: DocumentNode) {
|
|
311
312
|
return visit(ast, {
|
|
312
|
-
|
|
313
|
-
|
|
313
|
+
SelectionSet: {
|
|
314
|
+
enter(node: SelectionSetNode) {
|
|
314
315
|
return {
|
|
315
316
|
...node,
|
|
316
317
|
selections: node.selections.filter(
|
|
317
318
|
(selection) =>
|
|
318
319
|
!(
|
|
319
|
-
selection.kind ===
|
|
320
|
+
selection.kind === Kind.FIELD &&
|
|
320
321
|
selection.name.value === "__typename"
|
|
321
|
-
)
|
|
322
|
+
),
|
|
322
323
|
),
|
|
323
324
|
};
|
|
324
325
|
},
|
|
@@ -357,7 +358,7 @@ export function simpleCollectFields(
|
|
|
357
358
|
context: ExecutionContext,
|
|
358
359
|
selectionSet: SelectionSetNode,
|
|
359
360
|
fields: Record<string, FieldNode[]>,
|
|
360
|
-
visitedFragmentNames: Record<string, boolean
|
|
361
|
+
visitedFragmentNames: Record<string, boolean>,
|
|
361
362
|
): Record<string, FieldNode[]> {
|
|
362
363
|
for (const selection of selectionSet.selections) {
|
|
363
364
|
switch (selection.kind) {
|
|
@@ -374,7 +375,7 @@ export function simpleCollectFields(
|
|
|
374
375
|
context,
|
|
375
376
|
selection.selectionSet,
|
|
376
377
|
fields,
|
|
377
|
-
visitedFragmentNames
|
|
378
|
+
visitedFragmentNames,
|
|
378
379
|
);
|
|
379
380
|
break;
|
|
380
381
|
}
|
|
@@ -388,7 +389,7 @@ export function simpleCollectFields(
|
|
|
388
389
|
context,
|
|
389
390
|
fragment.selectionSet,
|
|
390
391
|
fields,
|
|
391
|
-
visitedFragmentNames
|
|
392
|
+
visitedFragmentNames,
|
|
392
393
|
);
|
|
393
394
|
break;
|
|
394
395
|
}
|
|
@@ -397,7 +398,7 @@ export function simpleCollectFields(
|
|
|
397
398
|
return fields;
|
|
398
399
|
}
|
|
399
400
|
export function hasClientDirective(
|
|
400
|
-
node: FieldNode | InlineFragmentNode | FragmentDefinitionNode
|
|
401
|
+
node: FieldNode | InlineFragmentNode | FragmentDefinitionNode,
|
|
401
402
|
) {
|
|
402
403
|
return (
|
|
403
404
|
node.directives &&
|
|
@@ -7,12 +7,12 @@ import {
|
|
|
7
7
|
TypeInfo,
|
|
8
8
|
GraphQLSchema,
|
|
9
9
|
getVisitFn,
|
|
10
|
-
|
|
10
|
+
ASTVisitor,
|
|
11
11
|
ASTKindToNode,
|
|
12
12
|
} from "graphql";
|
|
13
13
|
import { SourceLocation, getLocation } from "graphql/language/location";
|
|
14
14
|
|
|
15
|
-
import { Position, Range } from "vscode-languageserver";
|
|
15
|
+
import { Position, Range } from "vscode-languageserver/node";
|
|
16
16
|
|
|
17
17
|
import { isNode } from "./graphql";
|
|
18
18
|
|
|
@@ -22,7 +22,7 @@ type applyArg = [
|
|
|
22
22
|
string | number | undefined,
|
|
23
23
|
any,
|
|
24
24
|
readonly (string | number)[],
|
|
25
|
-
readonly any[]
|
|
25
|
+
readonly any[],
|
|
26
26
|
];
|
|
27
27
|
|
|
28
28
|
/**
|
|
@@ -31,8 +31,8 @@ type applyArg = [
|
|
|
31
31
|
*/
|
|
32
32
|
export function visitWithTypeInfo(
|
|
33
33
|
typeInfo: TypeInfo,
|
|
34
|
-
visitor:
|
|
35
|
-
):
|
|
34
|
+
visitor: ASTVisitor,
|
|
35
|
+
): ASTVisitor {
|
|
36
36
|
return {
|
|
37
37
|
enter(node: ASTNode) {
|
|
38
38
|
typeInfo.enter(node);
|
|
@@ -67,23 +67,23 @@ export function visitWithTypeInfo(
|
|
|
67
67
|
|
|
68
68
|
export function positionFromPositionInContainingDocument(
|
|
69
69
|
source: Source,
|
|
70
|
-
position: Position
|
|
70
|
+
position: Position,
|
|
71
71
|
) {
|
|
72
72
|
if (!source.locationOffset) return position;
|
|
73
73
|
return Position.create(
|
|
74
74
|
position.line - (source.locationOffset.line - 1),
|
|
75
|
-
position.character
|
|
75
|
+
position.character,
|
|
76
76
|
);
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
export function positionInContainingDocument(
|
|
80
80
|
source: Source,
|
|
81
|
-
position: Position
|
|
81
|
+
position: Position,
|
|
82
82
|
): Position {
|
|
83
83
|
if (!source.locationOffset) return position;
|
|
84
84
|
return Position.create(
|
|
85
85
|
source.locationOffset.line - 1 + position.line,
|
|
86
|
-
position.character
|
|
86
|
+
position.character,
|
|
87
87
|
);
|
|
88
88
|
}
|
|
89
89
|
|
|
@@ -91,7 +91,7 @@ export function rangeInContainingDocument(source: Source, range: Range): Range {
|
|
|
91
91
|
if (!source.locationOffset) return range;
|
|
92
92
|
return Range.create(
|
|
93
93
|
positionInContainingDocument(source, range.start),
|
|
94
|
-
positionInContainingDocument(source, range.end)
|
|
94
|
+
positionInContainingDocument(source, range.end),
|
|
95
95
|
);
|
|
96
96
|
}
|
|
97
97
|
|
|
@@ -101,13 +101,13 @@ export function rangeForASTNode(node: ASTNode): Range {
|
|
|
101
101
|
|
|
102
102
|
return Range.create(
|
|
103
103
|
positionFromSourceLocation(source, getLocation(source, location.start)),
|
|
104
|
-
positionFromSourceLocation(source, getLocation(source, location.end))
|
|
104
|
+
positionFromSourceLocation(source, getLocation(source, location.end)),
|
|
105
105
|
);
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
export function positionFromSourceLocation(
|
|
109
109
|
source: Source,
|
|
110
|
-
location: SourceLocation
|
|
110
|
+
location: SourceLocation,
|
|
111
111
|
) {
|
|
112
112
|
return Position.create(
|
|
113
113
|
(source.locationOffset ? source.locationOffset.line - 1 : 0) +
|
|
@@ -117,7 +117,7 @@ export function positionFromSourceLocation(
|
|
|
117
117
|
? source.locationOffset.column - 1
|
|
118
118
|
: 0) +
|
|
119
119
|
location.column -
|
|
120
|
-
1
|
|
120
|
+
1,
|
|
121
121
|
);
|
|
122
122
|
}
|
|
123
123
|
|
|
@@ -132,7 +132,7 @@ export function positionToOffset(source: Source, position: Position): number {
|
|
|
132
132
|
position.character +
|
|
133
133
|
linesUntilPosition
|
|
134
134
|
.map(
|
|
135
|
-
(line) => line.length + lineEndingLength // count EOL
|
|
135
|
+
(line) => line.length + lineEndingLength, // count EOL
|
|
136
136
|
)
|
|
137
137
|
.reduce((a, b) => a + b, 0)
|
|
138
138
|
);
|
|
@@ -142,7 +142,7 @@ export function getASTNodeAndTypeInfoAtPosition(
|
|
|
142
142
|
source: Source,
|
|
143
143
|
position: Position,
|
|
144
144
|
root: ASTNode,
|
|
145
|
-
schema: GraphQLSchema
|
|
145
|
+
schema: GraphQLSchema,
|
|
146
146
|
): [ASTNode, TypeInfo] | null {
|
|
147
147
|
const offset = positionToOffset(source, position);
|
|
148
148
|
|
|
@@ -171,7 +171,7 @@ export function getASTNodeAndTypeInfoAtPosition(
|
|
|
171
171
|
}
|
|
172
172
|
return;
|
|
173
173
|
},
|
|
174
|
-
})
|
|
174
|
+
}),
|
|
175
175
|
);
|
|
176
176
|
|
|
177
177
|
if (nodeContainingPosition) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import URI from "vscode-uri";
|
|
1
|
+
import { URI } from "vscode-uri";
|
|
2
2
|
|
|
3
3
|
const withUnixSeparator = (uriString: string) =>
|
|
4
4
|
uriString.split(/[\/\\]/).join("/");
|
|
@@ -10,7 +10,7 @@ export const normalizeURI = (uriString: string) => {
|
|
|
10
10
|
} else if (uriString.match(/^[a-zA-Z]:[\/\\].*/)) {
|
|
11
11
|
// uri with a drive prefix but not file:///
|
|
12
12
|
parsed = URI.file(
|
|
13
|
-
URI.parse("file:///" + withUnixSeparator(uriString)).fsPath
|
|
13
|
+
URI.parse("file:///" + withUnixSeparator(uriString)).fsPath,
|
|
14
14
|
);
|
|
15
15
|
} else {
|
|
16
16
|
parsed = URI.parse(withUnixSeparator(uriString));
|