首页 文章

摩纳哥编辑改变了IntelliSense行为

提问于
浏览
1

我正在试验CompletionItemProvider,我有两个CompletionItemProvider . 一个在所有字母上被触发,另一个在用户输入单引号字符(')时被触发 .

但我的目标是在双引号内,例如' here inside ',当用户点击CTRL SPACE激活IntelliSense时,他只能看到特定的完成提供者,例如下面的下方 . 那可能吗 ?

// should only trigger inside quotes
public areaCompletionProvider = <monaco.languages.CompletionItemProvider>{
    triggerCharacters: ['\''],
    provideCompletionItems: (model, position, token) => {
        let current = this.store[this.store.length - 1];
        if (!current) {
            return [];
        }

        let uniqueContextVariables: string[] = Array.from(new Set(current.contextVariables.map(ctxVariable => ctxVariable.area)));
        let areaCompletions = uniqueContextVariables.map(area => <monaco.languages.CompletionItem>{
            label: area,
            kind: monaco.languages.CompletionItemKind.Field,
        });

        return areaCompletions;
    }
};

1 回答

  • 0

    我不确定是否有更好的解决方案,但我设法在字符串内(两个引号之间)更改了IntelliSense行为CTRL SPACE .

    我正在使用findMatches方法,并在正则表达式的帮助下,我正在查看我是否在字符串中 . 如果是这种情况我会回来 .

    // This is for completion of context variables and shortcuts
    public variableCompletionProvider = <monaco.languages.CompletionItemProvider>{
        triggerCharacters: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split(''),
        provideCompletionItems: (model, position, token) => {
    
            // Check if inside string quotes, then don't offer variable completion as inside quotes only area completion should be available
            var quotes = model.findMatches(`'([^'])*'`, true, true, true, null, true);
            if (quotes.length > 0) {
                for (let quote of quotes) {
                    if (quote && (position.column >= quote.range.startColumn && position.column <= quote.range.endColumn)) {
                        return;
                    }
                }
            }
    
             // If I am not inside a string (quotes) then proceed with providing Completion 
             // Some more Code Here ...
    
        }
    };
    

    我不确定我是否能做得更好 . 此外,它不适用于越过更多行的字符串 . 对于任何建议我都很感激 .

相关问题