Skip to content

Commit

Permalink
fix: fix block string parsing in language parser
Browse files Browse the repository at this point in the history
  • Loading branch information
acao authored and dwwoelfel committed Feb 2, 2021
1 parent cb4debd commit 6b86b9e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
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 6b86b9e

Please sign in to comment.