diff --git a/.changeset/thick-baboons-glow.md b/.changeset/thick-baboons-glow.md new file mode 100644 index 00000000000..497cc1f6b12 --- /dev/null +++ b/.changeset/thick-baboons-glow.md @@ -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 diff --git a/packages/graphql-language-service-parser/src/Rules.ts b/packages/graphql-language-service-parser/src/Rules.ts index feae5313bc9..efc9983b4e0 100644 --- a/packages/graphql-language-service-parser/src/Rules.ts +++ b/packages/graphql-language-service-parser/src/Rules.ts @@ -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')], diff --git a/packages/graphql-language-service-parser/src/onlineParser.ts b/packages/graphql-language-service-parser/src/onlineParser.ts index 5c6d232ed3b..1321b8f68f1 100644 --- a/packages/graphql-language-service-parser/src/onlineParser.ts +++ b/packages/graphql-language-service-parser/src/onlineParser.ts @@ -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) { diff --git a/packages/graphql-language-service-parser/src/types.ts b/packages/graphql-language-service-parser/src/types.ts index 032a0812b7b..4898dea4c8d 100644 --- a/packages/graphql-language-service-parser/src/types.ts +++ b/packages/graphql-language-service-parser/src/types.ts @@ -52,6 +52,7 @@ export type State = { needsSeperator: boolean; needsAdvance?: boolean; indentLevel?: number; + inBlockstring?: boolean; }; export const AdditionalRuleKinds: _AdditionalRuleKinds = {