forked from graphql/graphiql
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: temporarily disable astro parsing again (graphql#3652)
- Loading branch information
1 parent
6dc3fae
commit 2583302
Showing
6 changed files
with
105 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 64 additions & 64 deletions
128
packages/graphql-language-service-server/src/parsers/astro.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; | ||
// }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters