Skip to content
This repository was archived by the owner on May 4, 2023. It is now read-only.

Commit 14a1b6f

Browse files
committed
Fix configuration caching for Jupyter Lab
1 parent b7a265c commit 14a1b6f

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

server/src/server.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -262,18 +262,29 @@ connection.onInitialized(async () => {
262262
//Initializes the GraphQL client
263263
initializeClient(clientName, clientVersion);
264264

265-
//May be already set by 'onDidChangeConfiguration()'. This can happen e.g. in Jupyter Lab where the configuration is not available
266-
// via 'connection.workspace.getConfiguration()' but only via the DidChangeConfigurationParams.
267-
// 'onDidChangeConfiguration()' may be executed before 'onInitialized()',
268-
// so if there is an API token set at launch, it can be picked up and cached by that event handler before 'onInitialized()' would pick it up.
265+
/*
266+
In Jupyter Lab, the configuration is not available via 'connection.workspace.getConfiguration("codiga.api.token")' for some reason,
267+
but only via the DidChangeConfigurationParams in 'connection.onDidChangeConfiguration()'.
268+
Also, Jupyter Lab triggers a call for `onDidChangeConfiguration()` when 'getConfiguration()' is first called here.
269+
This trigger doesn't seem to happen with VS Code and Sublime Text.
270+
271+
There are two such calls, one with an empty configuration ({}), the second one with the actual contents of the configuration.
272+
273+
Thus, in order to have the codiga.api.token cached, we
274+
- first, call 'getConfiguration()', and save its result,
275+
- if `onDidChangeConfiguration()` cached the value in the meantime, we don't update the cache (e.g. Jupyter Lab)
276+
- if `onDidChangeConfiguration()` didn't cache the value, we use the returned value (e.g. VS Code)
277+
*/
278+
const apiToken = await connection.workspace.getConfiguration("codiga.api.token");
269279
if (!getApiToken()) {
270-
cacheCodigaApiToken(await connection.workspace.getConfiguration("codiga.api.token"));
280+
cacheCodigaApiToken(apiToken);
271281
}
272282

273283
//Start the rules cache updater only if the client supports diagnostics
274-
if (hasDiagnosticCapability)
284+
if (hasDiagnosticCapability) {
275285
setAllTextDocumentsValidator(() => documents.all().forEach(validateTextDocument));
276286
refreshCachePeriodic();
287+
}
277288
});
278289

279290
/**

0 commit comments

Comments
 (0)