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/xtext/ContentAssistService.ts | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) (limited to 'language-web/src/main/js/xtext') 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