Skip to content

Commit

Permalink
LSP on config change bug fixes for #2230 (#2271)
Browse files Browse the repository at this point in the history
  • Loading branch information
acao committed Apr 7, 2022
1 parent 6973a20 commit e15d1da
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .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
10 changes: 5 additions & 5 deletions packages/graphql-language-service-server/src/MessageProcessor.ts
Expand Up @@ -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
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -404,7 +404,7 @@ export class MessageProcessor {
return { uri, diagnostics };
}
async handleDidChangeConfiguration(
_params?: DidChangeConfigurationParams,
_params: DidChangeConfigurationParams,
): Promise<DidChangeConfigurationRegistrationOptions> {
await this._updateGraphQLConfig();
this._logger.log(
Expand Down
Expand Up @@ -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 () => {
Expand Down
5 changes: 3 additions & 2 deletions packages/graphql-language-service-server/src/startServer.ts
Expand Up @@ -25,6 +25,7 @@ import {
DidOpenTextDocumentNotification,
DidSaveTextDocumentNotification,
DidChangeTextDocumentNotification,
DidChangeConfigurationNotification,
DidCloseTextDocumentNotification,
ExitNotification,
HoverRequest,
Expand Down Expand Up @@ -366,7 +367,7 @@ async function addHandlers({
messageProcessor.handleWorkspaceSymbolRequest(params),
);

connection.onDidChangeConfiguration(
messageProcessor.handleDidChangeConfiguration,
connection.onNotification(DidChangeConfigurationNotification.type, params =>
messageProcessor.handleDidChangeConfiguration(params),
);
}

0 comments on commit e15d1da

Please sign in to comment.