Skip to content

Commit

Permalink
fix: temporarily disable astro parsing again (graphql#3652)
Browse files Browse the repository at this point in the history
  • Loading branch information
acao authored and dimaMachina committed Jul 24, 2024
1 parent 6dc3fae commit 2583302
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 71 deletions.
7 changes: 7 additions & 0 deletions .changeset/ten-mangos-judge.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"graphql-language-service-server": patch
"graphql-language-service-cli": patch
"vscode-graphql": patch
---

Temporarily disable astro support again because of bundling issues
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,8 @@ export function Example(arg: string) {}`;
const contents = findGraphQLTags(text, '.svelte');
expect(contents.length).toEqual(1);
});
it('handles full astro example', () => {
// eslint-disable-next-line jest/no-disabled-tests
it.skip('handles full astro example', () => {
const text = `
---
const gql = String.raw;
Expand Down
3 changes: 2 additions & 1 deletion packages/graphql-language-service-server/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@ export const DEFAULT_SUPPORTED_EXTENSIONS = [
'.tsx',
'.vue',
'.svelte',
'.astro',
// '.astro',
'.cts',
'.mts',
] as const;

export type SupportedExtensions = typeof DEFAULT_SUPPORTED_EXTENSIONS;
export type SupportedExtensionsEnum =
(typeof DEFAULT_SUPPORTED_EXTENSIONS)[number];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { Position, Range } from 'graphql-language-service';
import { TAG_MAP } from './constants';
import { ecmaParser, tsParser } from './parsers/babel';
import { vueParser } from './parsers/vue';
import { astroParser } from './parsers/astro';
// import { astroParser } from './parsers/astro';
import type { Logger, NoopLogger } from './Logger';
import { RangeMapper } from './parsers/types';
import { svelteParser } from './parsers/svelte';
Expand All @@ -43,7 +43,7 @@ const parserMap = {
'.mts': tsParser,
'.svelte': svelteParser,
'.vue': vueParser,
'.astro': astroParser,
// '.astro': astroParser,
};

export function findGraphQLTags(
Expand Down
128 changes: 64 additions & 64 deletions packages/graphql-language-service-server/src/parsers/astro.ts
Original file line number Diff line number Diff line change
@@ -1,72 +1,72 @@
import { Position, Range } from 'graphql-language-service';
import { RangeMapper, SourceParser } from './types';
import { babelParser } from './babel';
import { parse } from 'astrojs-compiler-sync';
// import { Position, Range } from 'graphql-language-service';
// import { RangeMapper, SourceParser } from './types';
// import { babelParser } from './babel';
// import { parse } from 'astrojs-compiler-sync';

// import { teardown } from '@astrojs/compiler/dist/node';
// // import { teardown } from '@astrojs/compiler/dist/node';

type ParseAstroResult =
| { type: 'error'; errors: string[] }
| {
type: 'ok';
scriptOffset: number;
scriptAst: any[];
};
// type ParseAstroResult =
// | { type: 'error'; errors: string[] }
// | {
// type: 'ok';
// scriptOffset: number;
// scriptAst: any[];
// };

function parseAstro(source: string): ParseAstroResult {
// eslint-disable-next-line unicorn/no-useless-undefined
const { ast, diagnostics } = parse(source, undefined);
// function parseAstro(source: string): ParseAstroResult {
// // eslint-disable-next-line unicorn/no-useless-undefined
// const { ast, diagnostics } = parse(source, undefined);

if (diagnostics.some(d => d.severity === /* Error */ 1)) {
return {
type: 'error',
errors: diagnostics.map(d => JSON.stringify(d)),
};
}
// if (diagnostics.some(d => d.severity === /* Error */ 1)) {
// return {
// type: 'error',
// errors: diagnostics.map(d => JSON.stringify(d)),
// };
// }

for (const node of ast.children) {
if (node.type === 'frontmatter') {
try {
return {
type: 'ok',
scriptOffset: (node.position?.start.line ?? 1) - 1,
scriptAst: [babelParser(node.value, ['typescript'])],
};
} catch (error) {
return {
type: 'error',
errors: [String(error)],
};
}
}
}
// for (const node of ast.children) {
// if (node.type === 'frontmatter') {
// try {
// return {
// type: 'ok',
// scriptOffset: (node.position?.start.line ?? 1) - 1,
// scriptAst: [babelParser(node.value, ['typescript'])],
// };
// } catch (error) {
// return {
// type: 'error',
// errors: [String(error)],
// };
// }
// }
// }

return { type: 'error', errors: ['Could not find frontmatter block'] };
}
// return { type: 'error', errors: ['Could not find frontmatter block'] };
// }

export const astroParser: SourceParser = (text, uri, logger) => {
const parseAstroResult = parseAstro(text);
if (parseAstroResult.type === 'error') {
logger.info(
`Could not parse the astro file at ${uri} to extract the graphql tags:`,
);
for (const error of parseAstroResult.errors) {
logger.info(String(error));
}
return null;
}
// export const astroParser: SourceParser = (text, uri, logger) => {
// const parseAstroResult = parseAstro(text);
// if (parseAstroResult.type === 'error') {
// logger.info(
// `Could not parse the astro file at ${uri} to extract the graphql tags:`,
// );
// for (const error of parseAstroResult.errors) {
// logger.info(String(error));
// }
// return null;
// }

const rangeMapper: RangeMapper = range => {
return new Range(
new Position(
range.start.line + parseAstroResult.scriptOffset,
range.start.character,
),
new Position(
range.end.line + parseAstroResult.scriptOffset,
range.end.character,
),
);
};
return { asts: parseAstroResult.scriptAst, rangeMapper };
};
// const rangeMapper: RangeMapper = range => {
// return new Range(
// new Position(
// range.start.line + parseAstroResult.scriptOffset,
// range.start.character,
// ),
// new Position(
// range.end.line + parseAstroResult.scriptOffset,
// range.end.character,
// ),
// );
// };
// return { asts: parseAstroResult.scriptAst, rangeMapper };
// };
31 changes: 28 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -16297,7 +16297,7 @@ string-length@^4.0.1:
char-regex "^1.0.2"
strip-ansi "^6.0.0"

"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
"string-width-cjs@npm:string-width@^4.2.0":
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
Expand Down Expand Up @@ -16332,6 +16332,15 @@ string-width@^3.0.0, string-width@^3.1.0:
is-fullwidth-code-point "^2.0.0"
strip-ansi "^5.1.0"

string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
dependencies:
emoji-regex "^8.0.0"
is-fullwidth-code-point "^3.0.0"
strip-ansi "^6.0.1"

string-width@^5.0.1, string-width@^5.1.2:
version "5.1.2"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-5.1.2.tgz#14f8daec6d81e7221d2a357e668cab73bdbca794"
Expand Down Expand Up @@ -16435,7 +16444,7 @@ stringify-object@^3.3.0:
is-obj "^1.0.1"
is-regexp "^1.0.0"

"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
Expand Down Expand Up @@ -16463,6 +16472,13 @@ strip-ansi@^5.0.0, strip-ansi@^5.1.0, strip-ansi@^5.2.0:
dependencies:
ansi-regex "^4.1.0"

strip-ansi@^6.0.0, strip-ansi@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
dependencies:
ansi-regex "^5.0.1"

strip-ansi@^7.0.1:
version "7.1.0"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-7.1.0.tgz#d5b6568ca689d8561370b0707685d22434faff45"
Expand Down Expand Up @@ -18457,7 +18473,7 @@ workerpool@6.2.1:
resolved "https://registry.yarnpkg.com/workerpool/-/workerpool-6.2.1.tgz#46fc150c17d826b86a008e5a4508656777e9c343"
integrity sha512-ILEIE97kDZvF9Wb9f6h5aXK4swSlKGUcOEGiIYb2OOu/IrDU9iwj0fD//SsA6E5ibwJxpEvhullJY4Sl4GcpAw==

"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
Expand Down Expand Up @@ -18492,6 +18508,15 @@ wrap-ansi@^6.2.0:
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
dependencies:
ansi-styles "^4.0.0"
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^8.1.0:
version "8.1.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"
Expand Down

0 comments on commit 2583302

Please sign in to comment.