Skip to content

Commit

Permalink
improve LSP tests (#3510)
Browse files Browse the repository at this point in the history
- mockfs strategy
- move parseDocument tests to their own file
- config failure/lifecycle tests
  • Loading branch information
acao authored Jan 24, 2024
1 parent 98af530 commit 253d76f
Show file tree
Hide file tree
Showing 11 changed files with 605 additions and 365 deletions.
12 changes: 11 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
{
"npm.packageManager": "yarn",
"editor.formatOnSave": true,
"files.insertFinalNewline": true
"files.insertFinalNewline": true,
"editor.trimAutoWhitespace": false,
"coverage-gutters.showLineCoverage": true,
"coverage-gutters.coverageBaseDir": "coverage",
"coverage-gutters.coverageFileNames": [
"lcov.info",
"cov.xml",
"coverage.xml",
"jacoco.xml",
"coverage.cobertura.xml"
]
}
3 changes: 2 additions & 1 deletion custom-words.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ intellij
jsdelivr
lezer
manypkg
modulemap
mockfs
meros
nullthrows
onig
Expand Down Expand Up @@ -131,7 +133,6 @@ listvalues
marko
matchingbracket
middlewares
modulemap
newhope
nextjs
nocheck
Expand Down
3 changes: 2 additions & 1 deletion packages/graphql-language-service-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"@types/glob": "^8.1.0",
"@types/mkdirp": "^1.0.1",
"cross-env": "^7.0.2",
"graphql": "^16.8.1"
"graphql": "^16.8.1",
"mock-fs": "^5.2.0"
}
}
19 changes: 12 additions & 7 deletions packages/graphql-language-service-server/src/MessageProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,18 @@ export class MessageProcessor {
const settings = await this._connection.workspace.getConfiguration({
section: 'graphql-config',
});

const vscodeSettings = await this._connection.workspace.getConfiguration({
section: 'vscode-graphql',
});
if (settings?.dotEnvPath) {
require('dotenv').config({ path: settings.dotEnvPath });
}
this._settings = { ...settings, ...vscodeSettings };
const rootDir = this._settings?.load?.rootDir || this._rootPath;
const rootDir =
this._settings?.load?.rootDir ??
this._loadConfigOptions?.rootDir ??
this._rootPath;
this._rootPath = rootDir;
this._loadConfigOptions = {
...Object.keys(this._settings?.load ?? {}).reduce((agg, key) => {
Expand All @@ -243,9 +247,9 @@ export class MessageProcessor {
this._graphQLCache,
this._logger,
);
if (this._graphQLConfig || this._graphQLCache?.getGraphQLConfig) {
const config =
this._graphQLConfig ?? this._graphQLCache.getGraphQLConfig();
if (this._graphQLCache?.getGraphQLConfig()) {
const config = (this._graphQLConfig =
this._graphQLCache.getGraphQLConfig());
await this._cacheAllProjectFiles(config);
}
this._isInitialized = true;
Expand All @@ -254,6 +258,7 @@ export class MessageProcessor {
}
}
_handleConfigError({ err }: { err: unknown; uri?: string }) {
// console.log(err, typeof err);
if (err instanceof ConfigNotFoundError || err instanceof ConfigEmptyError) {
// TODO: obviously this needs to become a map by workspace from uri
// for workspaces support
Expand Down Expand Up @@ -303,9 +308,9 @@ export class MessageProcessor {
if (!this._isInitialized || !this._graphQLCache) {
// don't try to initialize again if we've already tried
// and the graphql config file or package.json entry isn't even there
if (this._isGraphQLConfigMissing === true) {
return null;
}
// if (this._isGraphQLConfigMissing === true) {
// return null;
// }
// then initial call to update graphql config
await this._updateGraphQLConfig();
}
Expand Down
Loading

0 comments on commit 253d76f

Please sign in to comment.