From 19d80be10b284354c4aad9f741bb70befd46aacc Mon Sep 17 00:00:00 2001 From: Rikki Schulte Date: Sun, 31 Jan 2021 14:16:58 -0500 Subject: [PATCH] fix: fix block string parsing in language parser --- .../graphql-language-service-parser/src/Rules.ts | 12 +++++++++++- .../src/onlineParser.ts | 10 ++++++++++ .../graphql-language-service-parser/src/types.ts | 1 + 3 files changed, 22 insertions(+), 1 deletion(-) 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 24de5483a13..f1623c1f2ca 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 e924439c9cb..7c29c89a66d 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 = {