Skip to content

Commit

Permalink
[RFC] fix: fix block string parsing in language parser (#1777)
Browse files Browse the repository at this point in the history
* fix: fix block string parsing in language parser

* add changeset

Co-authored-by: Rikki Schulte <rikki.schulte@gmail.com>
  • Loading branch information
dwwoelfel and acao committed Oct 29, 2021
1 parent 83c4a00 commit 75dbb0b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
10 changes: 10 additions & 0 deletions .changeset/thick-baboons-glow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"graphiql": patch
"codemirror-graphql": patch
"graphql-language-service-parser": patch
"graphql-language-service": patch
"graphql-language-service-server": patch
"graphql-language-service-cli": patch
---

adopt block string parsing for variables in language parser
12 changes: 11 additions & 1 deletion packages/graphql-language-service-parser/src/Rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,17 @@ export const ParseRules: { [name: string]: ParseRule } = {
}
},
NumberValue: [t('Number', 'number')],
StringValue: [t('String', 'string')],
StringValue: [
{
style: 'string',
match: token => token.kind === 'String',
update(state: State, token: Token) {
if (token.value.startsWith('"""')) {
state.inBlockstring = !token.value.slice(3).endsWith('"""');
}
},
},
],
BooleanValue: [t('Name', 'builtin')],
NullValue: [t('Name', 'keyword')],
EnumValue: [name('string-2')],
Expand Down
10 changes: 10 additions & 0 deletions packages/graphql-language-service-parser/src/onlineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ function getToken(
state: State,
options: ParserOptions,
): string {
if (state.inBlockstring) {
if (stream.match(/.*"""/)) {
state.inBlockstring = false;
return 'string';
} else {
stream.skipToEnd();
return 'string';
}
}

const { lexRules, parseRules, eatWhitespace, editorConfig } = options;
// Restore state after an empty-rule.
if (state.rule && state.rule.length === 0) {
Expand Down
1 change: 1 addition & 0 deletions packages/graphql-language-service-parser/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export type State = {
needsSeperator: boolean;
needsAdvance?: boolean;
indentLevel?: number;
inBlockstring?: boolean;
};

export const AdditionalRuleKinds: _AdditionalRuleKinds = {
Expand Down

0 comments on commit 75dbb0b

Please sign in to comment.