Replies: 2 comments
-
You can use underscore as trigger character, but then you must exclude it from your word pattern: monaco.languages.register({
id: "myLang",
});
monaco.languages.setLanguageConfiguration("myLang", {
wordPattern: /[a-zA-Z]+/
});
monaco.languages.registerCompletionItemProvider("myLang", {
triggerCharacters: ["_"],
provideCompletionItems: function(model, position) {
const word = model.getWordAtPosition(position)
|| { startColumn: position.column, endColumn: position.column };
return {
suggestions: [
{
kind: monaco.languages.CompletionItemKind.Class,
label: "foo",
insertText: "foo",
range: {
startLineNumber: 1,
endLineNumber: 1,
startColumn: word.startColumn,
endColumn: word.endColumn,
}
}
]
};
}
});
monaco.editor.create(document.getElementById("container"), {
value: "",
language: "myLang"
}); Typing a word pattern will trigger the completion provider by default without setting the word characters as triger characters. A suggest widget is only shown though if the completion items match with what the user typed. |
Beta Was this translation helpful? Give feedback.
0 replies
-
monaco.languages.setLanguageConfiguration("myLang", {
wordPattern: /[a-zA-Z]+/
}); Perfect, thank you~ |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
monaco.languages.registerCompletionItemProvider('myLanguage', {
triggerCharacters: ['_', '_', '-', ','],
provideCompletionItems: ... ...
}
eg. TABLE_FOO, TABLE_BAR, when type '_', editor completion 'FOO', 'BAR'。
As shown in the code above, commas and crossbars can complete the effect, and underscores or escaped underscores do not prompt the code correctly.
Beta Was this translation helpful? Give feedback.
All reactions