diff --git a/.changeset/wet-bobcats-chew.md b/.changeset/wet-bobcats-chew.md new file mode 100644 index 00000000000..fe836a2f799 --- /dev/null +++ b/.changeset/wet-bobcats-chew.md @@ -0,0 +1,5 @@ +--- +'graphql-language-service-server': patch +--- + +a few bugfixes related to config handling impacting vim and potentially other LSP server users diff --git a/packages/graphql-language-service-server/src/MessageProcessor.ts b/packages/graphql-language-service-server/src/MessageProcessor.ts index 0b9059dcdf1..4ae2fb181d1 100644 --- a/packages/graphql-language-service-server/src/MessageProcessor.ts +++ b/packages/graphql-language-service-server/src/MessageProcessor.ts @@ -217,13 +217,13 @@ export class MessageProcessor { const rootDir = this._settings?.load?.rootDir || this._rootPath; this._rootPath = rootDir; this._loadConfigOptions = { - ...Object.keys(this._settings.load || []).reduce((agg, key) => { - const value = this._settings.load[key]; + ...Object.keys(this._settings?.load ?? {}).reduce((agg, key) => { + const value = this._settings?.load[key]; if (value === undefined || value === null) { delete agg[key]; } return agg; - }, this._settings.load), + }, this._settings.load ?? {}), rootDir, }; // reload the graphql cache @@ -288,7 +288,7 @@ export class MessageProcessor { 'graphql.config', 'graphqlrc', 'package.json', - this._settings.load.fileName, + this._settings.load?.fileName, ].filter(Boolean); if (configMatchers.some(v => uri.match(v)?.length)) { this._logger.info('updating graphql config'); @@ -404,7 +404,7 @@ export class MessageProcessor { return { uri, diagnostics }; } async handleDidChangeConfiguration( - _params?: DidChangeConfigurationParams, + _params: DidChangeConfigurationParams, ): Promise { await this._updateGraphQLConfig(); this._logger.log( diff --git a/packages/graphql-language-service-server/src/__tests__/MessageProcessor-test.ts b/packages/graphql-language-service-server/src/__tests__/MessageProcessor-test.ts index fac08acf863..08f67c56964 100644 --- a/packages/graphql-language-service-server/src/__tests__/MessageProcessor-test.ts +++ b/packages/graphql-language-service-server/src/__tests__/MessageProcessor-test.ts @@ -350,6 +350,28 @@ describe('MessageProcessor', () => { expect(messageProcessor._updateGraphQLConfig).toHaveBeenCalled(); }); + + it('handles config requests with no config', async () => { + const customConfigName = 'custom-config-name.yml'; + messageProcessor._settings = {}; + + await messageProcessor.handleDidChangeConfiguration({ + settings: [], + }); + + expect(messageProcessor._updateGraphQLConfig).toHaveBeenCalled(); + + await messageProcessor.handleDidOpenOrSaveNotification({ + textDocument: { + uri: `${pathToFileURL('.')}/.graphql.config.js`, + languageId: 'js', + version: 0, + text: '', + }, + }); + + expect(messageProcessor._updateGraphQLConfig).toHaveBeenCalled(); + }); }); it('parseDocument finds queries in tagged templates', async () => { diff --git a/packages/graphql-language-service-server/src/startServer.ts b/packages/graphql-language-service-server/src/startServer.ts index 3b15003fdfe..58ef94b3e9f 100644 --- a/packages/graphql-language-service-server/src/startServer.ts +++ b/packages/graphql-language-service-server/src/startServer.ts @@ -25,6 +25,7 @@ import { DidOpenTextDocumentNotification, DidSaveTextDocumentNotification, DidChangeTextDocumentNotification, + DidChangeConfigurationNotification, DidCloseTextDocumentNotification, ExitNotification, HoverRequest, @@ -366,7 +367,7 @@ async function addHandlers({ messageProcessor.handleWorkspaceSymbolRequest(params), ); - connection.onDidChangeConfiguration( - messageProcessor.handleDidChangeConfiguration, + connection.onNotification(DidChangeConfigurationNotification.type, params => + messageProcessor.handleDidChangeConfiguration(params), ); }