Typescript 改变智能感知行为

Typescript 改变智能感知行为,typescript,monaco-editor,Typescript,Monaco Editor,我正在试验CompletionTemprovider,我有两个CompletionTemprovider。一个在所有字母上触发,另一个在用户键入单引号字符(')时触发 但我的目标是在双引号内,例如“here inside”,当用户点击CTRL+SPACE激活IntelliSense时,他只能看到特定的完成提供者,例如下面的。可能吗 // should only trigger inside quotes public areaCompletionProvider = <monaco.lan

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

但我的目标是在双引号内,例如“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;
    }
};
//应仅在引号内触发
公共区域完成提供程序={
触发器字符:['\''],
provideCompletionItems:(型号、位置、令牌)=>{
让current=this.store[this.store.length-1];
如果(!当前){
返回[];
}
让uniqueContextVariables:string[]=Array.from(新集合(current.contextVariables.map(ctxVariable=>ctxVariable.area));
让areaCompletions=uniqueContextVariables.map(area=>{
标签:区域,
种类:monaco.languages.CompletionItemKind.Field,
});
返回区完成;
}
};

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

我使用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 ...

    }
};
//用于完成上下文变量和快捷方式
公共变量CompletionProvider={
触发器字符:“ABCDEFGHIJKLMNOPQRSTUVXYZABCDFGHIJKLMNOPQRSTUVXYZ”。拆分(“”),
provideCompletionItems:(型号、位置、令牌)=>{
//检查是否有内部字符串引号,然后不要提供变量补全,因为只有内部引号区域补全才可用
var quotes=model.findMatches(`([^'])*`,true,true,true,null,true);
如果(quotes.length>0){
for(让我们引用引用){
如果(quote&&(position.column>=quote.range.startColumn&&position.column