Skip to content

Commit 75dbb0b

Browse files
dwwoelfelacao
andauthored
[RFC] fix: fix block string parsing in language parser (#1777)
* fix: fix block string parsing in language parser * add changeset Co-authored-by: Rikki Schulte <[email protected]>
1 parent 83c4a00 commit 75dbb0b

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed

.changeset/thick-baboons-glow.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
"graphiql": patch
3+
"codemirror-graphql": patch
4+
"graphql-language-service-parser": patch
5+
"graphql-language-service": patch
6+
"graphql-language-service-server": patch
7+
"graphql-language-service-cli": patch
8+
---
9+
10+
adopt block string parsing for variables in language parser

packages/graphql-language-service-parser/src/Rules.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,17 @@ export const ParseRules: { [name: string]: ParseRule } = {
192192
}
193193
},
194194
NumberValue: [t('Number', 'number')],
195-
StringValue: [t('String', 'string')],
195+
StringValue: [
196+
{
197+
style: 'string',
198+
match: token => token.kind === 'String',
199+
update(state: State, token: Token) {
200+
if (token.value.startsWith('"""')) {
201+
state.inBlockstring = !token.value.slice(3).endsWith('"""');
202+
}
203+
},
204+
},
205+
],
196206
BooleanValue: [t('Name', 'builtin')],
197207
NullValue: [t('Name', 'keyword')],
198208
EnumValue: [name('string-2')],

packages/graphql-language-service-parser/src/onlineParser.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,16 @@ function getToken(
8181
state: State,
8282
options: ParserOptions,
8383
): string {
84+
if (state.inBlockstring) {
85+
if (stream.match(/.*"""/)) {
86+
state.inBlockstring = false;
87+
return 'string';
88+
} else {
89+
stream.skipToEnd();
90+
return 'string';
91+
}
92+
}
93+
8494
const { lexRules, parseRules, eatWhitespace, editorConfig } = options;
8595
// Restore state after an empty-rule.
8696
if (state.rule && state.rule.length === 0) {

packages/graphql-language-service-parser/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export type State = {
5252
needsSeperator: boolean;
5353
needsAdvance?: boolean;
5454
indentLevel?: number;
55+
inBlockstring?: boolean;
5556
};
5657

5758
export const AdditionalRuleKinds: _AdditionalRuleKinds = {

0 commit comments

Comments
 (0)