From 9e66bbf3fd64993dfc7ca0b66b5349ca3af465bd Mon Sep 17 00:00:00 2001 From: Makito Date: Fri, 20 Dec 2024 15:45:36 +0800 Subject: [PATCH] fix(expressions): autocompletion in parentheses (#1868) --- packages/core/expressions/src/monaco.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/core/expressions/src/monaco.ts b/packages/core/expressions/src/monaco.ts index c88a3107cd..0d54b1aab5 100644 --- a/packages/core/expressions/src/monaco.ts +++ b/packages/core/expressions/src/monaco.ts @@ -77,12 +77,13 @@ export const registerLanguage = (schema: Schema) => { '@default': 'variable', }, }], + [/[()]/, 'delimiter.parenthesis'], [/==|!=|~|\^=|=\^|>=?|<=?|&&|\|\|/, 'operators'], - [/[()]/, 'brackets'], [/".*?"/, 'string'], [/\d+/, 'number'], ], }, + brackets: [{ open: '(', close: ')', token: 'delimiter.parenthesis' }], } as MonarchLanguage) monaco.languages.registerCompletionItemProvider(languageId, { @@ -130,7 +131,9 @@ export const registerLanguage = (schema: Schema) => { }) const words = lastChars.replace('\t', '').split(' ') - const activeTyping = words[words.length - 1] // what the user is currently typing (everything after the last space) + let activeTyping = words[words.length - 1] // what the user is currently typing (everything after the last space) + // Here, we will start counting the characters after the last open parenthesis + activeTyping = activeTyping.slice(activeTyping.lastIndexOf('(') + 1) const inputTokens = activeTyping.split('.').slice(0, -1) let token: Token = tokenTree