Skip to content

Commit e15d1da

Browse files
authored
LSP on config change bug fixes for #2230 (#2271)
1 parent 6973a20 commit e15d1da

File tree

4 files changed

+35
-7
lines changed

4 files changed

+35
-7
lines changed

.changeset/wet-bobcats-chew.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'graphql-language-service-server': patch
3+
---
4+
5+
a few bugfixes related to config handling impacting vim and potentially other LSP server users

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -217,13 +217,13 @@ export class MessageProcessor {
217217
const rootDir = this._settings?.load?.rootDir || this._rootPath;
218218
this._rootPath = rootDir;
219219
this._loadConfigOptions = {
220-
...Object.keys(this._settings.load || []).reduce((agg, key) => {
221-
const value = this._settings.load[key];
220+
...Object.keys(this._settings?.load ?? {}).reduce((agg, key) => {
221+
const value = this._settings?.load[key];
222222
if (value === undefined || value === null) {
223223
delete agg[key];
224224
}
225225
return agg;
226-
}, this._settings.load),
226+
}, this._settings.load ?? {}),
227227
rootDir,
228228
};
229229
// reload the graphql cache
@@ -288,7 +288,7 @@ export class MessageProcessor {
288288
'graphql.config',
289289
'graphqlrc',
290290
'package.json',
291-
this._settings.load.fileName,
291+
this._settings.load?.fileName,
292292
].filter(Boolean);
293293
if (configMatchers.some(v => uri.match(v)?.length)) {
294294
this._logger.info('updating graphql config');
@@ -404,7 +404,7 @@ export class MessageProcessor {
404404
return { uri, diagnostics };
405405
}
406406
async handleDidChangeConfiguration(
407-
_params?: DidChangeConfigurationParams,
407+
_params: DidChangeConfigurationParams,
408408
): Promise<DidChangeConfigurationRegistrationOptions> {
409409
await this._updateGraphQLConfig();
410410
this._logger.log(

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

+22
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,28 @@ describe('MessageProcessor', () => {
350350

351351
expect(messageProcessor._updateGraphQLConfig).toHaveBeenCalled();
352352
});
353+
354+
it('handles config requests with no config', async () => {
355+
const customConfigName = 'custom-config-name.yml';
356+
messageProcessor._settings = {};
357+
358+
await messageProcessor.handleDidChangeConfiguration({
359+
settings: [],
360+
});
361+
362+
expect(messageProcessor._updateGraphQLConfig).toHaveBeenCalled();
363+
364+
await messageProcessor.handleDidOpenOrSaveNotification({
365+
textDocument: {
366+
uri: `${pathToFileURL('.')}/.graphql.config.js`,
367+
languageId: 'js',
368+
version: 0,
369+
text: '',
370+
},
371+
});
372+
373+
expect(messageProcessor._updateGraphQLConfig).toHaveBeenCalled();
374+
});
353375
});
354376

355377
it('parseDocument finds queries in tagged templates', async () => {

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
DidOpenTextDocumentNotification,
2626
DidSaveTextDocumentNotification,
2727
DidChangeTextDocumentNotification,
28+
DidChangeConfigurationNotification,
2829
DidCloseTextDocumentNotification,
2930
ExitNotification,
3031
HoverRequest,
@@ -366,7 +367,7 @@ async function addHandlers({
366367
messageProcessor.handleWorkspaceSymbolRequest(params),
367368
);
368369

369-
connection.onDidChangeConfiguration(
370-
messageProcessor.handleDidChangeConfiguration,
370+
connection.onNotification(DidChangeConfigurationNotification.type, params =>
371+
messageProcessor.handleDidChangeConfiguration(params),
371372
);
372373
}

0 commit comments

Comments
 (0)