-
Notifications
You must be signed in to change notification settings - Fork 5
Support snippet autocompletion #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
To be honest I prefer not even displaying the snippet completions until placeholders are supported. |
|
Most of the snippets are not useful until the placeholder situation is addressed. I primarily implemented this to test how my tooltip module handles newlines from snippets (which I will probably publish this week). I need to see how the snippets work. I don't even know if this type of snippet is standardized across all LSPs or not. |
|
Yeah it's not a simple thing to implement. 😅 I'm really not sure how to make the tab stops work in micro (at least without some ugly hacks to get around autocomplete) which is why I didn't even bother trying. |
When a completion with a placeholder is inserted, a "search" its executed, and the placeholders are highlighted. You can keep cycling between suggestions with `Tab` and `Backtab` as usual. When a completion with placeholders is selected, you can cycle between the placeholders with `FindNext` and `FindPrevious`.
|
I implemented partial support for placeholders. Long story short, I use regex and a "find region" to mark the placeholders in the completion. You can cycle forward and backward through the completions with Tab, as usual, and then use I only tested it with P.S. If you don't mind, could you test my plugin? It creates a tooltip for the suggestions. Maybe you'll like it. |
I tested with
I tried to install it but when starting micro there was an error from this line: with the following error message: |
|
Sorry, I did not mention that you have to use The error message is because it cannot find the module.
This line in the plugin is responsible for adding the path for the plugin to the package.path = config.ConfigDir .. "/plug/?.lua;" .. package.pathThe I tried it myself; I cloned the repo into a fake directory and used Using this setup, my |
|
I tried Further tests:
This was the completion: function $1($2)
$0
endI also tried I do not know what is going on. |
|
I also get the completion but after accepting the snippet pressing Tab should take the cursor to $1, then $2, and finally $0 (or end of snippet if $0 wasn't present). That's the part I can't get working. The error with your plugin was that the I didn't know something like this was even possible in micro so that's very cool. I would love to have tooltips like this for hoverAction. And although I prefer completions to stay out of my way for the most part, a vertical list would open up room to include extra information along with the completions (eg. type signatures). I wonder if there's a way to implement this without triggering micro's own autocomplete at all, so you wouldn't get the usual autocomplete menu in the statusline in addition to the tooltip? |
From my previous message:
The use of Micro cannot jump between searches other than sequentially, so the placeholders must be in order. Micro only searches for the next match with the last regex/literal; the highlighter gives the false illusion of a list of matches. The jump to the end of the snippet would require adding more state to the plugin; not sure if it’s worth it. You could always cycle over all the matches, detecting all of them, create a sorter, then append the end of the snippet to that list, and fake iterate over them...(?) When you "accept" the snippet, the suggestions are reset inside Micro, and then you listen to I think that using the default search functions is the best option until Micro provides at least a real list of matches. I think there should be a good reason to do that here instead of in Micro (primarily, not knowing Go, like me). And users are familiar with that.
Yes, it's on purpose. If you use only the file name and that file exists in one of the paths inside
I already implemented a plugin to display the diagnostic messages (and other gutter messages) in a tooltip. The inconvenience is that I have to format the text into lines in order to have a real background (Micro did not consider buffers on top of each other; in fact, the mouse does not work very well—something with "layers" probably). You have to pad the lines with spaces to make it look like a box, and that has its limitations regarding highlighting/syntax.
I was playing with that when you merged your last PR, using the labels as suggestions, adding the kinds, etc.
The answer is yes, but it comes with trade-offs. In the case of my plugin, it depends on the suggestions and completions of the buffer. So, in order to display that info, you will also affect the status line suggestions. That being said, as I mentioned before, the plugin has to format each suggestion to pad the text like a box, so it is completely possible to change that text without changing the status line at all. tooltip: statusline: But you cannot communicate that extra information to the plugin. There are options: a. Detecting at runtime if my plugin is installed; if it is, you add that information formatted to the status line (my plugin will pad it), not caring at all how the status line looks. If it’s not installed, you leave the current implementation. The status line will look like this: b. Add my plugin to |
|
I found a bug. When the autocompletion is direct (only 1 match), the placeholder search does not work. I have to see how it works internally. This can be reproduced with the example you used: With |
Yes, it is possible, and it is done. I was able to get the native micro autocompletions without displaying anything in the statusline (it does not work for InfoBar because it does not trigger actions). I am currently testing the triggers for completion and signature (also the manual call of signatureHelp; this uses my tooltip module) with it. The base functionality is done, but it needs to be polished. This new plugin will not autocomplete directly and could be called externally to set its suggestions from other plugins. This is primarily to improve the synergy with The API is: ---@param bufpane `BufPane` where the tooltip is created
---@param suggestions `string[]` is used internally to match the output of `GetWord()`.
---@param completions `string[]`
---@param displayedSuggestions `string[]` is the suggestion displayed and can contain more information on it.
---@param filetype `string` tooltip's buffer syntax to being able to have external customization (this is not done yet but should be trivial).
function ShowSuggestions(bufpane, suggestions, completions, displayedSuggestions, filetype)The plugin keeps this information until the tooltip is closed. Example ( So the text inserted is matched against the suggestion, but the displayed text is what the tooltip's buffer contains. This list changes while you type; then you use ENTER to insert the completion. The important thing is to make If you type 'o', the list will be modified and only display 1 and 2; if you remove the 'o' and type 'm', the other 2 will be displayed. The tooltip is closed if the trigger location (initial location of the active cursor) is surpassed to its left or if you insert something that does not match anything. Enter is used to enter the completion. |
It's a simple implementation; it does not support placeholders and only correctly indents the text.