Skip to content

Commit

Permalink
fix: more cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
acao committed Mar 17, 2024
1 parent 4216bd6 commit 310048b
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 56 deletions.
7 changes: 4 additions & 3 deletions packages/graphql-language-service-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
"@babel/parser": "^7.23.6",
"@babel/types": "^7.23.5",
"@graphql-tools/code-file-loader": "8.0.3",
"@graphql-tools/graphql-tag-pluck": "^8.3.0",
"@graphql-tools/graphql-file-loader": "^8.0.1",
"@graphql-tools/url-loader": "^8.0.2",
"@graphql-tools/utils": "^10.1.2",
"@vue/compiler-sfc": "^3.4.5",
"astrojs-compiler-sync": "^0.3.5",
"cosmiconfig-toml-loader": "^1.0.0",
Expand All @@ -63,9 +67,6 @@
"vscode-uri": "^3.0.2"
},
"devDependencies": {
"@graphql-tools/graphql-file-loader": "^8.0.1",
"@graphql-tools/url-loader": "^8.0.2",
"@graphql-tools/utils": "^10.1.2",
"@types/glob": "^8.1.0",
"@types/mkdirp": "^1.0.1",
"@types/mock-fs": "^4.13.4",
Expand Down
12 changes: 6 additions & 6 deletions packages/graphql-language-service-server/src/GraphQLCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -802,12 +802,7 @@ export class GraphQLCache {
let fsPath = doc.location;
let filePath;
const isNetwork = doc.location.startsWith('http');
if (!isNetwork) {
try {
fsPath = resolve(rootDir, doc.location);
} catch {}
filePath = URI.file(fsPath).toString();
} else {
if (isNetwork) {
filePath = this._getTmpProjectPath(
projectConfig,
true,
Expand All @@ -818,6 +813,11 @@ export class GraphQLCache {
false,
'generated-schema.graphql',
);
} else {
try {
fsPath = resolve(rootDir, doc.location);
} catch {}
filePath = URI.file(fsPath).toString();
}

const content = doc.document.loc?.source.body ?? '';
Expand Down
48 changes: 15 additions & 33 deletions packages/graphql-language-service-server/src/MessageProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,22 +392,16 @@ export class MessageProcessor {
return { uri, diagnostics };
}
try {
console.log('and here');
const project = this._graphQLCache.getProjectForFile(uri);
console.log('and here 1');
if (project) {
const text = 'text' in textDocument && textDocument.text;
// the disk is always valid here, so the textDocument.text isn't useful I don't think
// const text = 'text' in textDocument && textDocument.text;
// for some reason if i try to tell to not parse empty files, it breaks :shrug:
// i think this is because if the file change is empty, it doesn't get parsed
// TODO: this could be related to a bug in how we are calling didOpenOrSave in our tests
// that doesn't reflect the real runtime behavior

const { contents } = await this._parseAndCacheFile(
uri,
project,
// text as string,
);
console.log('and here 2');
const { contents } = await this._parseAndCacheFile(uri, project);
if (project?.extensions?.languageService?.enableValidation !== false) {
await Promise.all(
contents.map(async ({ documentString, range }) => {
Expand Down Expand Up @@ -487,7 +481,6 @@ export class MessageProcessor {
if (project?.extensions?.languageService?.enableValidation !== false) {
// Send the diagnostics onChange as well
try {
console.log({ contents });
await Promise.all(
contents.map(async ({ documentString, range }) => {
const results = await this._languageService.getDiagnostics(
Expand Down Expand Up @@ -595,21 +588,17 @@ export class MessageProcessor {
// Treat the computed list always complete.

const cachedDocument = this._getCachedDocument(textDocument.uri);
console.log({ cachedDocument, uri: textDocument.uri });
if (!cachedDocument) {
return { items: [], isIncomplete: false };
}

const found = cachedDocument.contents.find(content => {
const currentRange = content.range;
console.log({ currentRange, position: toPosition(position) });
if (currentRange?.containsPosition(toPosition(position))) {
return true;
}
});

console.log({ found });

// If there is no GraphQL query in this file, return an empty result.
if (!found) {
return { items: [], isIncomplete: false };
Expand Down Expand Up @@ -797,24 +786,17 @@ export class MessageProcessor {
const { textDocument, position } = params;
const project = this._graphQLCache.getProjectForFile(textDocument.uri);
const cachedDocument = this._getCachedDocument(textDocument.uri);
console.log({ cachedDocument });
if (!cachedDocument) {
return [];
}

const found = cachedDocument.contents.find(content => {
console.log(content.range, toPosition(position));
const currentRange = content?.range;
if (
currentRange &&
currentRange?.containsPosition(toPosition(position))
) {
if (currentRange?.containsPosition(toPosition(position))) {
return true;
}
});

console.log({ found }, 'definition');

// If there is no GraphQL query in this file, return an empty result.
if (!found) {
return [];
Expand All @@ -833,9 +815,7 @@ export class MessageProcessor {
toPosition(position),
textDocument.uri,
);
console.log({ result });
} catch (err) {
console.error(err);
} catch {
// these thrown errors end up getting fired before the service is initialized, so lets cool down on that
}

Expand Down Expand Up @@ -865,7 +845,6 @@ export class MessageProcessor {
const vOffset = isEmbedded
? cachedDoc?.contents[0].range?.start.line ?? 0
: parentRange.start.line;
console.log({ defRange });

defRange.setStart(
(defRange.start.line += vOffset),
Expand Down Expand Up @@ -1333,11 +1312,15 @@ export class MessageProcessor {
}

private _getCachedDocument(uri: string): CachedDocumentType | null {
const fileCache = this._getDocumentCacheForFile(uri);
console.log(fileCache);
const cachedDocument = fileCache?.get(uri);
if (cachedDocument) {
return cachedDocument;
const project = this._graphQLCache.getProjectForFile(uri);
if (project) {
const cachedDocument = this._graphQLCache._getCachedDocument(
uri,
project,
);
if (cachedDocument) {
return cachedDocument;
}
}

return null;
Expand All @@ -1347,7 +1330,6 @@ export class MessageProcessor {
uri: Uri,
contents: CachedContent[],
): Promise<Map<string, CachedDocumentType> | null> {
console.log('invalidate');
let documentCache = this._getDocumentCacheForFile(uri);
if (!documentCache) {
const project = await this._graphQLCache.getProjectForFile(uri);
Expand Down Expand Up @@ -1386,7 +1368,7 @@ export class MessageProcessor {
export function processDiagnosticsMessage(
results: Diagnostic[],
query: string,
range: RangeType | null,
range?: RangeType,
): Diagnostic[] {
const queryLines = query.split('\n');
const totalLines = queryLines.length;
Expand Down
1 change: 1 addition & 0 deletions packages/graphql-language-service/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export interface IRange {
setStart(line: number, character: number): void;
containsPosition(position: IPosition): boolean;
}

export type CachedContent = {
documentString: string;
range?: IRange;
Expand Down
41 changes: 27 additions & 14 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1036,10 +1036,10 @@
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.22.7.tgz#df8cf085ce92ddbdbf668a7f186ce848c9036cae"
integrity sha512-7NF8pOkHP5o2vpmGgNGcfAeCvOYhGLyA3Z4eBQkT1RJlWu47n63bCs93QfJ2hIAFCil7L5P2IWhs1oToVgrL0Q==

"@babel/parser@^7.23.9":
version "7.23.9"
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.23.9.tgz#7b903b6149b0f8fa7ad564af646c4c38a77fc44b"
integrity sha512-9tcKgqKbs3xGJ+NtKF2ndOBBLVwPjl1SHxPQkd36r3Dlirw3xWUeGaTbqr7uGZcTaxkVNwc+03SVP7aCdWrTlA==
"@babel/parser@^7.24.0":
version "7.24.0"
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.24.0.tgz#26a3d1ff49031c53a97d03b604375f028746a9ac"
integrity sha512-QuP/FxEAzMSjXygs8v4N9dvdXzEHN4W1oF3PxuWAtPo08UdM17u89RDMgjLn/mlc56iM0HlLmVkO/wgR+rDgHg==

"@babel/plugin-bugfix-safari-id-destructuring-collision-in-function-expression@^7.18.6":
version "7.18.6"
Expand Down Expand Up @@ -2392,19 +2392,19 @@
"@babel/parser" "^7.12.13"
"@babel/types" "^7.12.13"

"@babel/traverse@^7.16.8", "@babel/traverse@^7.17.3", "@babel/traverse@^7.20.5", "@babel/traverse@^7.20.7", "@babel/traverse@^7.21.0", "@babel/traverse@^7.21.2", "@babel/traverse@^7.22.5", "@babel/traverse@^7.22.6", "@babel/traverse@^7.22.8", "@babel/traverse@^7.23.7", "@babel/traverse@^7.7.2":
version "7.23.9"
resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.23.9.tgz#2f9d6aead6b564669394c5ce0f9302bb65b9d950"
integrity sha512-I/4UJ9vs90OkBtY6iiiTORVMyIhJ4kAVmsKo9KFc8UOxMeUfi2hvtIBsET5u9GizXE6/GFSuKCTNfgCswuEjRg==
"@babel/traverse@^7.16.8", "@babel/traverse@^7.17.3", "@babel/traverse@^7.20.5", "@babel/traverse@^7.20.7", "@babel/traverse@^7.21.0", "@babel/traverse@^7.21.2", "@babel/traverse@^7.22.5", "@babel/traverse@^7.22.6", "@babel/traverse@^7.22.8", "@babel/traverse@^7.23.2", "@babel/traverse@^7.23.7", "@babel/traverse@^7.7.2":
version "7.24.0"
resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.24.0.tgz#4a408fbf364ff73135c714a2ab46a5eab2831b1e"
integrity sha512-HfuJlI8qq3dEDmNU5ChzzpZRWq+oxCZQyMzIMEqLho+AQnhMnKQUzH6ydo3RBl/YjPCuk68Y6s0Gx0AeyULiWw==
dependencies:
"@babel/code-frame" "^7.23.5"
"@babel/generator" "^7.23.6"
"@babel/helper-environment-visitor" "^7.22.20"
"@babel/helper-function-name" "^7.23.0"
"@babel/helper-hoist-variables" "^7.22.5"
"@babel/helper-split-export-declaration" "^7.22.6"
"@babel/parser" "^7.23.9"
"@babel/types" "^7.23.9"
"@babel/parser" "^7.24.0"
"@babel/types" "^7.24.0"
debug "^4.3.1"
globals "^11.1.0"

Expand Down Expand Up @@ -2460,10 +2460,10 @@
"@babel/helper-validator-identifier" "^7.22.20"
to-fast-properties "^2.0.0"

"@babel/types@^7.23.9":
version "7.23.9"
resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.23.9.tgz#1dd7b59a9a2b5c87f8b41e52770b5ecbf492e002"
integrity sha512-dQjSq/7HaSjRM43FFGnv5keM2HsxpmyV1PfaSVm0nzzjwwTmjOe6J4bC8e3+pTEIgHaHj+1ZlLThRJ2auc/w1Q==
"@babel/types@^7.24.0":
version "7.24.0"
resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.24.0.tgz#3b951f435a92e7333eba05b7566fd297960ea1bf"
integrity sha512-+j7a5c253RfKh8iABBhywc8NSfP5LURe7Uh4qpsh6jc+aLJguvmIUBdjSdEMQv2bENrCR5MfRdjGo7vzS/ob7w==
dependencies:
"@babel/helper-string-parser" "^7.23.4"
"@babel/helper-validator-identifier" "^7.22.20"
Expand Down Expand Up @@ -3710,6 +3710,19 @@
"@graphql-tools/utils" "^10.0.0"
tslib "^2.4.0"

"@graphql-tools/graphql-tag-pluck@^8.3.0":
version "8.3.0"
resolved "https://registry.yarnpkg.com/@graphql-tools/graphql-tag-pluck/-/graphql-tag-pluck-8.3.0.tgz#11bb8c627253137b39b34fb765cd6ebe506388b9"
integrity sha512-gNqukC+s7iHC7vQZmx1SEJQmLnOguBq+aqE2zV2+o1hxkExvKqyFli1SY/9gmukFIKpKutCIj+8yLOM+jARutw==
dependencies:
"@babel/core" "^7.22.9"
"@babel/parser" "^7.16.8"
"@babel/plugin-syntax-import-assertions" "^7.20.0"
"@babel/traverse" "^7.16.8"
"@babel/types" "^7.16.8"
"@graphql-tools/utils" "^10.0.13"
tslib "^2.4.0"

"@graphql-tools/import@7.0.0":
version "7.0.0"
resolved "https://registry.yarnpkg.com/@graphql-tools/import/-/import-7.0.0.tgz#a6a91a90a707d5f46bad0fd3fde2f407b548b2be"
Expand Down

0 comments on commit 310048b

Please sign in to comment.