摩纳哥编辑器更改 IntelliSense 行为
Monaco Editor change IntelliSense Behaviour
我正在试验 CompletionItemProvider,我有两个 CompletionItemProvider。一个在所有字母上触发,另一个在用户键入单引号字符 (') 时触发。
但我的目标是在用户点击 CTRL+SPACE[ 时在双引号内,例如 'here inside' =17=] 激活 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;
}
};
我不确定是否有更好的解决方案,但我设法更改了字符串内(两个引号之间)的 IntelliSense 行为 CTRL+SPACE。
我正在使用 findMatches 方法并在正则表达式的帮助下查看我是否在字符串中。如果是这样我return。
// 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 ...
}
};
我不确定我是否可以做得更好。它也不适用于超过更多行的字符串。对于任何建议,我都很感激。
我正在试验 CompletionItemProvider,我有两个 CompletionItemProvider。一个在所有字母上触发,另一个在用户键入单引号字符 (') 时触发。
但我的目标是在用户点击 CTRL+SPACE[ 时在双引号内,例如 'here inside' =17=] 激活 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;
}
};
我不确定是否有更好的解决方案,但我设法更改了字符串内(两个引号之间)的 IntelliSense 行为 CTRL+SPACE。
我正在使用 findMatches 方法并在正则表达式的帮助下查看我是否在字符串中。如果是这样我return。
// 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 ...
}
};
我不确定我是否可以做得更好。它也不适用于超过更多行的字符串。对于任何建议,我都很感激。