|
1 |
| -import { Position, Range } from 'graphql-language-service'; |
2 |
| -import { RangeMapper, SourceParser } from './types'; |
3 |
| -import { babelParser } from './babel'; |
4 |
| -import { parse } from 'astrojs-compiler-sync'; |
| 1 | +// import { Position, Range } from 'graphql-language-service'; |
| 2 | +// import { RangeMapper, SourceParser } from './types'; |
| 3 | +// import { babelParser } from './babel'; |
| 4 | +// import { parse } from 'astrojs-compiler-sync'; |
5 | 5 |
|
6 |
| -// import { teardown } from '@astrojs/compiler/dist/node'; |
| 6 | +// // import { teardown } from '@astrojs/compiler/dist/node'; |
7 | 7 |
|
8 |
| -type ParseAstroResult = |
9 |
| - | { type: 'error'; errors: string[] } |
10 |
| - | { |
11 |
| - type: 'ok'; |
12 |
| - scriptOffset: number; |
13 |
| - scriptAst: any[]; |
14 |
| - }; |
| 8 | +// type ParseAstroResult = |
| 9 | +// | { type: 'error'; errors: string[] } |
| 10 | +// | { |
| 11 | +// type: 'ok'; |
| 12 | +// scriptOffset: number; |
| 13 | +// scriptAst: any[]; |
| 14 | +// }; |
15 | 15 |
|
16 |
| -function parseAstro(source: string): ParseAstroResult { |
17 |
| - // eslint-disable-next-line unicorn/no-useless-undefined |
18 |
| - const { ast, diagnostics } = parse(source, undefined); |
| 16 | +// function parseAstro(source: string): ParseAstroResult { |
| 17 | +// // eslint-disable-next-line unicorn/no-useless-undefined |
| 18 | +// const { ast, diagnostics } = parse(source, undefined); |
19 | 19 |
|
20 |
| - if (diagnostics.some(d => d.severity === /* Error */ 1)) { |
21 |
| - return { |
22 |
| - type: 'error', |
23 |
| - errors: diagnostics.map(d => JSON.stringify(d)), |
24 |
| - }; |
25 |
| - } |
| 20 | +// if (diagnostics.some(d => d.severity === /* Error */ 1)) { |
| 21 | +// return { |
| 22 | +// type: 'error', |
| 23 | +// errors: diagnostics.map(d => JSON.stringify(d)), |
| 24 | +// }; |
| 25 | +// } |
26 | 26 |
|
27 |
| - for (const node of ast.children) { |
28 |
| - if (node.type === 'frontmatter') { |
29 |
| - try { |
30 |
| - return { |
31 |
| - type: 'ok', |
32 |
| - scriptOffset: (node.position?.start.line ?? 1) - 1, |
33 |
| - scriptAst: [babelParser(node.value, ['typescript'])], |
34 |
| - }; |
35 |
| - } catch (error) { |
36 |
| - return { |
37 |
| - type: 'error', |
38 |
| - errors: [String(error)], |
39 |
| - }; |
40 |
| - } |
41 |
| - } |
42 |
| - } |
| 27 | +// for (const node of ast.children) { |
| 28 | +// if (node.type === 'frontmatter') { |
| 29 | +// try { |
| 30 | +// return { |
| 31 | +// type: 'ok', |
| 32 | +// scriptOffset: (node.position?.start.line ?? 1) - 1, |
| 33 | +// scriptAst: [babelParser(node.value, ['typescript'])], |
| 34 | +// }; |
| 35 | +// } catch (error) { |
| 36 | +// return { |
| 37 | +// type: 'error', |
| 38 | +// errors: [String(error)], |
| 39 | +// }; |
| 40 | +// } |
| 41 | +// } |
| 42 | +// } |
43 | 43 |
|
44 |
| - return { type: 'error', errors: ['Could not find frontmatter block'] }; |
45 |
| -} |
| 44 | +// return { type: 'error', errors: ['Could not find frontmatter block'] }; |
| 45 | +// } |
46 | 46 |
|
47 |
| -export const astroParser: SourceParser = (text, uri, logger) => { |
48 |
| - const parseAstroResult = parseAstro(text); |
49 |
| - if (parseAstroResult.type === 'error') { |
50 |
| - logger.info( |
51 |
| - `Could not parse the astro file at ${uri} to extract the graphql tags:`, |
52 |
| - ); |
53 |
| - for (const error of parseAstroResult.errors) { |
54 |
| - logger.info(String(error)); |
55 |
| - } |
56 |
| - return null; |
57 |
| - } |
| 47 | +// export const astroParser: SourceParser = (text, uri, logger) => { |
| 48 | +// const parseAstroResult = parseAstro(text); |
| 49 | +// if (parseAstroResult.type === 'error') { |
| 50 | +// logger.info( |
| 51 | +// `Could not parse the astro file at ${uri} to extract the graphql tags:`, |
| 52 | +// ); |
| 53 | +// for (const error of parseAstroResult.errors) { |
| 54 | +// logger.info(String(error)); |
| 55 | +// } |
| 56 | +// return null; |
| 57 | +// } |
58 | 58 |
|
59 |
| - const rangeMapper: RangeMapper = range => { |
60 |
| - return new Range( |
61 |
| - new Position( |
62 |
| - range.start.line + parseAstroResult.scriptOffset, |
63 |
| - range.start.character, |
64 |
| - ), |
65 |
| - new Position( |
66 |
| - range.end.line + parseAstroResult.scriptOffset, |
67 |
| - range.end.character, |
68 |
| - ), |
69 |
| - ); |
70 |
| - }; |
71 |
| - return { asts: parseAstroResult.scriptAst, rangeMapper }; |
72 |
| -}; |
| 59 | +// const rangeMapper: RangeMapper = range => { |
| 60 | +// return new Range( |
| 61 | +// new Position( |
| 62 | +// range.start.line + parseAstroResult.scriptOffset, |
| 63 | +// range.start.character, |
| 64 | +// ), |
| 65 | +// new Position( |
| 66 | +// range.end.line + parseAstroResult.scriptOffset, |
| 67 | +// range.end.character, |
| 68 | +// ), |
| 69 | +// ); |
| 70 | +// }; |
| 71 | +// return { asts: parseAstroResult.scriptAst, rangeMapper }; |
| 72 | +// }; |
0 commit comments