microsoft / monaco-editor

A browser based code editor
https://microsoft.github.io/monaco-editor/
MIT License
40.68k stars 3.61k forks source link

Custom autocompletion ordering / periods in completion items #219

Closed aarinsmith closed 8 years ago

aarinsmith commented 8 years ago

monaco-editor npm version: 0.6.1 Browser: Chrome OS: MAC OSX 10.11.6

I have created a custom language for use with the editor. When registering a completion provider I was curious to know if there is a way of defining a custom sorting algorithm perhaps taking into account the most recent completion items. As an example I have multiple data objects that contain periods. eg. aaa.bbb.ccc aaa.ddd.eee bbb.ccc.ddd bbb.xxx.yyy xxx.yyy.zzz

this ends up being a fairly enormous list with many repeating patterns between the periods. currently it sorts the list alphabetically.

So if I have 100 aaa.bbb.* And 100 xxx.aaa.*

if i type xxx.aaa the autocomplete ends up splitting on the period and listing the first 100 aaa.bbb.* entries. However I would like it to prioritize by the xxx search that preceded it.

Is this something that is possible? And if not. Can someone point me in the direction of the code that is responsible for splitting my autocomplete items on the periods? Customizing this for my current project would not be the most ideal solution but would at least allow proper ordering when typing autocomplete suggestions.

alexdima commented 8 years ago

@jrieken @joaomoreno should know.

aarinsmith commented 8 years ago

Thanks, if anyone has any insight into a possible solution it would definitely help. Another thing I am curious about is if there is a way of registering completion providers within another. The list of data objects is huge. Because I am using this on the web it is not always optimal to register all the items at a single time. Does anyone know if it would be possible to have a completion item make an additional call to register its sub items.

For example:

When typing aaa make a subsequent API call to return and register the list of sub entries. aaa.bbb aaa.ccc aaa.ddd

aarinsmith commented 8 years ago

@jrieken @joaomoreno do either of you have any suggestions for this? Or happen to know where in the source I may be able to make a custom change for myself that would allow . in autocompletion items? I feel like this would be the simplest solution for my use at this point.

joaomoreno commented 8 years ago

Hi @aarinsmith, sorry for the delay.

The splitting on the period issue is Microsoft/vscode#11423 and was recently fixed. It will come with the October release.

There is no notion of sub completion providers. But there are incomplete completion results. You can use this to return only a subset of results initially. Once the user types more, your completion provider will be asked to provide further items.

aarinsmith commented 8 years ago

Hey no worries @joaomoreno, thanks for answering. In the mean time I spent a little more time looking over the API. I didn't notice the incomplete completion results feature. I was intending on re-mapping my completion items to a nested dictionary and then using regex matching to provide a way to get subsequent subsections of completion results but maybe this feature could take care of that for me? Do you by any chance know where I could find examples of this in use?

joaomoreno commented 8 years ago

You cat set isIncomplete to true and your provider will be asked to provide more items on the next keypress.