monaco-editor version: 0.13.1
Browser: Chrome
OS: Mac
Steps or JS usage snippet reproducing the issue:
Hello there! If there is a way to make editor request completion items after the "enter" or "cmd+v" was typed?
For dot using triggerCharacters: ["."], but how to trigger completion after "enter" or "cmd+v"?
You could implement this by:
editor.onDidType (and looking for \n) and editor.onDidPaste (internal APIs)editor.trigger('anything', 'editor.action.triggerSuggest')Thanks @alexandrudima ! It's workable to listening enter or cmd+v using editor.onDidType or editor.onDidPaste, It's fantastic! But i also have one question.
provideCompletionItems?As you can say, editor.trigger('anything', 'editor.action.triggerSuggest') can show completion items directly, but the model filled No suggestions, that isn't what i want.
I have registered a completionItemProvider:
monaco.language.registerCompletionItemProvider('sql', provideCompletionItems: (model, position) => {
return myCustomItems
})
Using the object model and position, i create myCustomItems. My question is, how to do provideCompletionItems effects using editor.trigger('anything', 'editor.action.triggerSuggest')? I can't find any docs, I guess I can get model and position some where, and return new completion items?
My goal is to achieve this effect:
a, show completion items a ab abc.abc, whatever using enter or tab, or even paste abc directly, will auto show the next completion items d de def.Here is a gif:

What you show consists of two pieces:
command field in CompletionItem.position sits within the SQL query and propose only what makes sense. For example, if you are before FROM you should suggest column names. If you are after FROM you should not suggest column names.Thanks for your reply! Can you give me a simple example how triggering suggestions by command in CompletionItem? Thanks a lot!
I don't know how to trigger provideCompletionItems again by using command field in CompletionItem..
For each completion item, you would use the command field and use editor.action.triggerSuggest as the value for the command. Then, when the completion item is accepted, that command will also be invoked.
At least I think that's how that should work. We can ask @jrieken for further help if it does not.
Thank @alexandrudima, you helped me find the key to solving the problem! But i still need help because nothing happens when choose any completion item when using this code:
resolveCompletionItem(item: monaco.languages.CompletionItem) {
item.command = {
id: 'editor.action.triggerSuggest',
title: '123'
};
return item;
}
What should i trigger new suggestion when choose completion items, and set custom suggest items? @jrieken I would like to get your help very much!
The command id is correct and I know that css uses this successfully. Try setting the command during provideCompletionItems and not in resolve...
Hello @jrieken , i add command to provideCompletionItems, but nothing happened. Here is my code:
provideCompletionItems: () => {
return [{label: 'test', command: {id: 'editor.action.triggerSuggest', title: 123}}]
}
, but nothing happened
Something always happens ;-) Is it that your provider isn't called or that your completions aren't showing? Is there an error? You can debug this on suggestController.js#_onDidSelectItem
Thank you for your quick reply, but I'm still in doubt.
When trigger command in provideCompletionItems, where should i handle it? Or it will recall provideCompletionItems itself?
Yes. You don't trigger the command you tell the editor to trigger the command once a completion is selected and then that will eventually call provideCompletionItems
Thanks, i'll try it.
Thanks @jrieken ! It now works fine! Another question, how can i change point position after a completion is selected?
I want both trigger provideCompletionItems(Using command) and change cursor position after select a completion.
Use a SnippetString as insert text
Thanks @alexandrudima and @jrieken! All works fine for me now!
@ascoders I'm going through a similar use-case. Would it be possible for you to share some gist on how you used Editor APIs?
@suhasdeshpande What's your problem?
@alexandrudima @jrieken
How does excuse me multilevel clew use
monaco.languages.registerCompletionItemProvider('javascript', {
provideCompletionItems: function () {
return {
suggestions: [
{
label: 'May',
kind: monaco.languages.CompletionItemKind['Function'],
insertText: 'Mayname',
detail: '鍚嶅瓧',
command: {id: 'editor.action.triggerSuggest', title: 123}
{
label: 'Cay',
kind: monaco.languages.CompletionItemKind['Function'],
insertText: 'CayNmae',
detail: 'cay',
}
]
}
},
triggerCharacters: ['M', 'C']
})
+1 would love to see a final code example solution for this. I've got a very similar usecase but even though my completionItemProvider is returning suggestions, they are in some cases either not triggering the suggestion widget at all, or if manually triggered, widget displays "No suggestions" even though I can see the suggestions logged to console.
Seems it will only actually display the suggestions if there is a space preceding the suggestion trigger.
@ascoders @alexandrudima @jrieken
How to resolve this problem since SnippetString is removed?
I was able to generally get this working fine by adding a space to the end of each suggestion item.