Skip to content

Commit 4f1894c

Browse files
committed
more progress - now stuck on getDocuments() with no output
1 parent 01e64dd commit 4f1894c

File tree

16 files changed

+181
-553
lines changed

16 files changed

+181
-553
lines changed

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"${workspaceFolder}/packages/vscode-graphql/fixtures/diagnostics.txt"
3333
],
3434
"outFiles": [
35-
"${workspaceFolder}/packages/vscode-graphql/dist/extension.js"
35+
"${workspaceFolder}/packages/vscode-graphql/out/extension.js"
3636
],
3737
"trace": true,
3838
"preLaunchTask": "watch-vscode"

packages/graphql-language-service-server/src/GraphQLCache.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ import { CodeFileLoader } from '@graphql-tools/code-file-loader';
4747

4848
const LanguageServiceExtension: GraphQLExtensionDeclaration = api => {
4949
// For schema
50-
api.loaders.schema.register(new CodeFileLoader());
50+
api.loaders.schema.register(new CodeFileLoader({ noSilentErrors: false }));
5151
// For documents
52-
api.loaders.documents.register(new CodeFileLoader());
52+
api.loaders.documents.register(new CodeFileLoader({ noSilentErrors: false }));
5353

5454
return { name: 'languageService' };
5555
};

packages/graphql-language-service-server/src/MessageProcessor.ts

Lines changed: 63 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -205,15 +205,31 @@ export class MessageProcessor {
205205
}
206206

207207
async _updateGraphQLConfig() {
208-
const settings = await this._connection.workspace.getConfiguration({
209-
section: 'graphql-config',
210-
});
211-
const vscodeSettings = await this._connection.workspace.getConfiguration({
212-
section: 'vscode-graphql',
213-
});
214-
if (settings?.dotEnvPath) {
215-
require('dotenv').config({ path: settings.dotEnvPath });
208+
this._logger.info('updating config')
209+
let settings = {
210+
dotEnvPath: null
211+
};
212+
let vscodeSettings = {};
213+
// try {
214+
// settings = await this.connection.workspace.getConfiguration({
215+
// section: 'graphql-config',
216+
// scopeUri: this._rootPath
217+
// });
218+
// this._logger.info('graphql config loaded')
219+
// vscodeSettings = await this.connection.workspace.getConfiguration({
220+
// section: 'vscode-graphql',
221+
// scopeUri: this._rootPath
222+
// });
223+
// }
224+
// catch(err) {
225+
// this._logger.info(JSON.stringify(err))
226+
// }
227+
this._logger.info('updating config 1')
228+
229+
if (this._settings?.dotEnvPath) {
230+
require('dotenv').config({ path: settings?.dotEnvPath });
216231
}
232+
this._logger.info('updating config 2')
217233
this._settings = { ...settings, ...vscodeSettings };
218234
const rootDir = this._settings?.load?.rootDir || this._rootPath;
219235
this._rootPath = rootDir;
@@ -228,21 +244,28 @@ export class MessageProcessor {
228244
rootDir,
229245
};
230246
try {
247+
this._logger.info('updating config 3')
231248
// reload the graphql cache
232249
this._graphQLCache = await getGraphQLCache({
233250
parser: this._parser,
234251
loadConfigOptions: this._loadConfigOptions,
235252

236253
logger: this._logger,
237254
});
255+
this._logger.info('updating config 4')
238256
this._languageService = new GraphQLLanguageService(
239257
this._graphQLCache,
240258
this._logger,
241259
);
260+
this._logger.info('updating config 5')
242261
if (this._graphQLConfig || this._graphQLCache?.getGraphQLConfig) {
243262
const config =
244263
this._graphQLConfig ?? this._graphQLCache.getGraphQLConfig();
264+
this._logger.info('updating config 6')
265+
this._logger.info(JSON.stringify(config))
245266
await this._cacheAllProjectFiles(config);
267+
this._logger.info('updating config 7')
268+
246269
}
247270
this._isInitialized = true;
248271
} catch (err) {
@@ -291,15 +314,18 @@ export class MessageProcessor {
291314
async handleDidOpenOrSaveNotification(
292315
params: DidSaveTextDocumentParams | DidOpenTextDocumentParams,
293316
): Promise<PublishDiagnosticsParams | null> {
317+
this._logger.info('opening document')
294318
/**
295319
* Initialize the LSP server when the first file is opened or saved,
296320
* so that we can access the user settings for config rootDir, etc
297321
*/
298322
try {
299323
if (!this._isInitialized || !this._graphQLCache) {
324+
this._logger.info('no cache')
300325
// don't try to initialize again if we've already tried
301326
// and the graphql config file or package.json entry isn't even there
302327
if (this._isGraphQLConfigMissing === true) {
328+
this._logger.info('config missing')
303329
return null;
304330
}
305331
// then initial call to update graphql config
@@ -308,6 +334,7 @@ export class MessageProcessor {
308334
} catch (err) {
309335
this._logger.error(String(err));
310336
}
337+
this._logger.info('opening document 2')
311338

312339
// Here, we set the workspace settings in memory,
313340
// and re-initialize the language service when a different
@@ -896,10 +923,14 @@ export class MessageProcessor {
896923

897924
async _cacheSchemaText(uri: string, text: string, version: number) {
898925
try {
926+
this._logger.info('cache schema text 1')
899927
const contents = this._parser(text, uri);
900928
if (contents.length > 0) {
901929
await this._invalidateCache({ version, uri }, uri, contents);
930+
this._logger.info('cache schema text 2')
931+
902932
await this._updateObjectTypeDefinition(uri, contents);
933+
this._logger.info('cache schema text 3')
903934
}
904935
} catch (err) {
905936
this._logger.error(String(err));
@@ -909,19 +940,25 @@ export class MessageProcessor {
909940
_uri: UnnormalizedTypeDefPointer,
910941
project: GraphQLProjectConfig,
911942
) {
943+
this._logger.info('cache schema file 1')
944+
912945
const uri = _uri.toString();
913946

914947
const isFileUri = existsSync(uri);
915948
let version = 1;
916949
if (isFileUri) {
917950
const schemaUri = URI.file(path.join(project.dirpath, uri)).toString();
951+
this._logger.info('cache schema file 2')
918952
const schemaDocument = this._getCachedDocument(schemaUri);
953+
this._logger.info('cache schema file 3')
919954

920955
if (schemaDocument) {
921956
version = schemaDocument.version++;
922957
}
923958
const schemaText = readFileSync(uri, 'utf8');
959+
this._logger.info('cache schema file 4')
924960
await this._cacheSchemaText(schemaUri, schemaText, version);
961+
this._logger.info('cache schema file 5')
925962
}
926963
}
927964
_getTmpProjectPath(
@@ -952,9 +989,13 @@ export class MessageProcessor {
952989
* @param project
953990
*/
954991
async _cacheSchemaPath(uri: string, project: GraphQLProjectConfig) {
992+
this._logger.info('cache schema files 3')
993+
955994
try {
956995
const files = await glob(uri);
957996
if (files && files.length > 0) {
997+
this._logger.info('cache schema files 4')
998+
958999
await Promise.all(
9591000
files.map(uriPath => this._cacheSchemaFile(uriPath, project)),
9601001
);
@@ -993,6 +1034,7 @@ export class MessageProcessor {
9931034
}
9941035

9951036
async _cacheSchemaFilesForProject(project: GraphQLProjectConfig) {
1037+
this._logger.info('cache schema files 1')
9961038
const schema = project?.schema;
9971039
const config = project?.extensions?.languageService;
9981040
/**
@@ -1013,9 +1055,13 @@ export class MessageProcessor {
10131055
config?.cacheSchemaFileForLookup ??
10141056
this?._settings?.cacheSchemaFileForLookup ??
10151057
false;
1058+
this._logger.info('cache schema files 2')
1059+
10161060
if (cacheSchemaFileForLookup) {
10171061
await this._cacheConfigSchema(project);
10181062
} else if (typeof schema === 'string') {
1063+
this._logger.info('cache schema files 3')
1064+
10191065
await this._cacheSchemaPath(schema, project);
10201066
} else if (Array.isArray(schema)) {
10211067
await this._cacheArraySchema(schema, project);
@@ -1077,20 +1123,29 @@ export class MessageProcessor {
10771123
*/
10781124
async _cacheDocumentFilesforProject(project: GraphQLProjectConfig) {
10791125
try {
1126+
this._logger.info('cacheDocumentFilesforProject 1')
1127+
this._logger.info(JSON.stringify(project, null, 2))
10801128
const documents = await project.getDocuments();
1129+
this._logger.info('cacheDocumentFilesforProject 2')
1130+
10811131
return Promise.all(
10821132
documents.map(async document => {
10831133
if (!document.location || !document.rawSDL) {
10841134
return;
10851135
}
1136+
this._logger.info('cacheDocumentFilesforProject 3')
1137+
10861138

10871139
let filePath = document.location;
10881140
if (!path.isAbsolute(filePath)) {
10891141
filePath = path.join(project.dirpath, document.location);
10901142
}
1143+
this._logger.info('cacheDocumentFilesforProject 4')
10911144

10921145
// build full system URI path with protocol
10931146
const uri = URI.file(filePath).toString();
1147+
this._logger.info('cacheDocumentFilesforProject 5')
1148+
10941149

10951150
// I would use the already existing graphql-config AST, but there are a few reasons we can't yet
10961151
const contents = this._parser(document.rawSDL, uri);

packages/graphql-language-service-server/src/findGraphQLTags.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const PARSER_OPTIONS: ParserOptions = {
2424
allowImportExportEverywhere: true,
2525
allowReturnOutsideFunction: true,
2626
allowSuperOutsideMethod: true,
27-
sourceType: 'module',
27+
sourceType: "unambiguous",
2828
strictMode: false,
2929
};
3030

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"graphql-config.load.legacy": true,
3+
"vscode-graphql.cacheSchemaFileForLookup": false
4+
}
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
import { graphql } from 'graphql-tag';
12

2-
gql`
3-
4-
# example fragment
5-
fragment ExampleFragment4 on ExampleType {
6-
shelter
7-
}
3+
const fragment = graphql`
4+
# example fragment
5+
fragment ExampleFragment4 on ExampleType {
6+
shelter
7+
}
88
`

packages/vscode-graphql/fixtures/src/queries/query.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
const gql = (arg: TemplateStringsArray) => null;
1+
import { graphql } from 'graphql-tag'
22

3-
4-
gql`
3+
const query1 = graphql`
54
fragment ExampleFragment on ExampleType {
65
something
76
}
87
`
98

10-
gql`
9+
const query2 = graphql`
1110
query ExampleQuery {
1211
exampleField {
1312
...ExampleFragment

packages/vscode-graphql/fixtures/src/schema/schema.graphql

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ enum ExampleEnum {
88

99
# for example
1010
type ExampleType {
11-
field: String
12-
field2: ExampleEnum
13-
fiel3: String
1411
shelter: String
1512
something: String
1613
however: String
@@ -20,14 +17,5 @@ type Query {
2017
exampleField: ExampleType
2118
love: String
2219
message: String
23-
example: Boolean
24-
example2: String
25-
example3: Boolean
26-
example4: Boolean
27-
example5: Boolean
28-
example6: String
29-
something: String
30-
something2: String
31-
something3: String
3220
}
3321

packages/vscode-graphql/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"workspaceContains:**/package.json"
4949
],
5050
"extensionKind": ["ui"],
51-
"main": "./dist/extension.js",
51+
"main": "./out/extension.js",
5252
"contributes": {
5353
"icons": {
5454
"graphql-logo": {
@@ -169,7 +169,7 @@
169169
},
170170
"dependencies": {
171171
"graphql-language-service-server": "^2.11.2",
172-
"vscode-languageclient": "8.0.2",
172+
"vscode-languageclient": "8.1.0",
173173
"graphql": "16.6.0"
174174
}
175175
}

packages/vscode-graphql/src/extension.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ export async function activate(context: ExtensionContext) {
114114
context.subscriptions.push(statusBarItem);
115115

116116
await client.start();
117+
console.log('after client start')
117118
initStatusBar(statusBarItem, client, window.activeTextEditor);
118119

119120
const commandShowOutputChannel = commands.registerCommand(

0 commit comments

Comments
 (0)