From 10df138d6084000659626aaf50afb16e6b674b25 Mon Sep 17 00:00:00 2001 From: Kristóf Marussy Date: Fri, 5 Nov 2021 19:17:30 +0100 Subject: chore(web): implicit completion info in grammar Move information about which tokens should support implicit completions into the Lezer grammar. --- language-web/src/main/js/language/problem.grammar | 10 +++++++--- language-web/src/main/js/language/props.ts | 7 +++++++ language-web/src/main/js/xtext/ContentAssistService.ts | 15 ++++----------- 3 files changed, 18 insertions(+), 14 deletions(-) create mode 100644 language-web/src/main/js/language/props.ts (limited to 'language-web/src') diff --git a/language-web/src/main/js/language/problem.grammar b/language-web/src/main/js/language/problem.grammar index 86cc7722..8e39243f 100644 --- a/language-web/src/main/js/language/problem.grammar +++ b/language-web/src/main/js/language/problem.grammar @@ -1,3 +1,7 @@ +@detectDelim + +@external prop implicitCompletion from '../../../../src/main/js/language/props.ts' + @top Problem { statement* } statement { @@ -89,11 +93,11 @@ VariableName { QualifiedName } NodeName { QualifiedName } -QualifiedName { identifier ("::" identifier)* } +QualifiedName[implicitCompletion=true] { identifier ("::" identifier)* } -kw { @specialize[@name={term}] } +kw { @specialize[@name={term},implicitCompletion=true] } -ckw { @extend[@name={term}] } +ckw { @extend[@name={term},implicitCompletion=true] } ParameterList { "(" sep<",", content> ")" } diff --git a/language-web/src/main/js/language/props.ts b/language-web/src/main/js/language/props.ts new file mode 100644 index 00000000..8e488bf5 --- /dev/null +++ b/language-web/src/main/js/language/props.ts @@ -0,0 +1,7 @@ +import { NodeProp } from '@lezer/common'; + +export const implicitCompletion = new NodeProp({ + deserialize(s: string) { + return s === 'true'; + }, +}); diff --git a/language-web/src/main/js/xtext/ContentAssistService.ts b/language-web/src/main/js/xtext/ContentAssistService.ts index 65381b21..aa9a80b0 100644 --- a/language-web/src/main/js/xtext/ContentAssistService.ts +++ b/language-web/src/main/js/xtext/ContentAssistService.ts @@ -7,18 +7,11 @@ import { syntaxTree } from '@codemirror/language'; import type { Transaction } from '@codemirror/state'; import escapeStringRegexp from 'escape-string-regexp'; +import { implicitCompletion } from '../language/props'; import type { UpdateService } from './UpdateService'; import { getLogger } from '../utils/logger'; import type { IContentAssistEntry } from './xtextServiceResults'; -const IMPLICIT_COMPLETION_TOKENS = [ - 'QualifiedName', - 'true', - 'false', - 'unknown', - 'error', -]; - const PROPOSALS_LIMIT = 1000; const IDENTIFIER_REGEXP_STR = '[a-zA-Z0-9_]*'; @@ -32,7 +25,7 @@ interface IFoundToken { to: number; - name: string; + implicitCompletion: boolean; text: string; } @@ -50,14 +43,14 @@ function findToken({ pos, state }: CompletionContext): IFoundToken | null { return { from: token.from, to: token.to, - name: token.name, + implicitCompletion: token.type.prop(implicitCompletion) || false, text: state.sliceDoc(token.from, token.to), }; } function shouldCompleteImplicitly(token: IFoundToken | null, context: CompletionContext): boolean { return token !== null - && IMPLICIT_COMPLETION_TOKENS.includes(token.name) + && token.implicitCompletion && context.pos - token.from >= 2; } -- cgit v1.2.3-70-g09d2