-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Auto completion #174
Comments
Unfortunately this feature is not implemented yet, although I plan to do it at some point. I think auto closing brackets, quotes, parentheses etc... is different from autocompletion for actual code keywords (and far easier to implement so that will probably get done first). I think it would be best to have an autocompletion core in micro, and implement specific completion for each language in plugins. Micro can't magically know that Anyway, I'll try to implement auto complete for brackets soon, and I'll do more advanced auto completion some time in the future, but that's a lot more complex. |
I totally agree, the benefit of code keywords and whole API catalogs is also smaller. But let me explain the following example for a method definition in ruby: def mymethod(myparam)
# some action
end If the user types in an usual bracket, a closed one will be added after the cursor. In the above example, I appreciate your effort. |
IMO it would be best if something like this get handled very similar to how syntax highlighting is done. So just simple files with regex patterns, and some pre-defined actions, like "Add X character(s) on the next line" or "Add X character(s) after the cursor". |
Yeah, I think what you're looking for here is snippets, and luckily, Vim users have already collected all those patterns. We just need a way of reading the snippet files and then of course actually implementing the snippet functionality. See here for lots of snippets that are already made. Those files are for the Vim plugin snipmate, but there are more complex ones in that repository for the Vim plugin UltiSnips. Those snippets are more complex but also more powerful, so we'll have to decide which one to use. Anyway, I think this is a separate issue from snippets, although maybe snippets is what you meant originally. In any case, I think autocomplete and snippets are both features that would be great to have in micro and will hopefully get implemented at some point soon. |
Thanks for the new autoclose feature, it works very well. The vim snippets look quite hard to read/parse, for example this one:
They also seem to cover many languages completely which I simply did not want to request here, originally I just thought of brackets and the most basic snippets. |
Just as a reference for autocomplete function implemented in vim, there's one utilizing lua that is also popular: https://github.com/shougo/neocomplete.vim (I recall saw this or something similar before, using lua for auto-completion functionality in vim). |
It would be great if there was autocompletion not only for languages, but also for commands available - would make Micro even more intuitive as you'd discover commands by typing them! |
There is in fact autocompletion for commands. Maybe I should say that somewhere in the docs though... Just press tab and it should give you a list of suggestions in the statusline. It will also autocomplete filenames, and options when appropriate. |
As for VS Code - it uses an open JSON-based |
I really like the idea of this standart, but the list of implementations is very limited and it is "immature", e.g. the server for rust:
|
This box can be used to auto completion once it is exposed to plugins. There is a mode without the prompt that just shows the list. |
later in December I would like to try implementing Language Server Protocol (client) to micro. Golang has most of the primitives implemented already, so the communication part should be easy. I am wondering if this kind of improvement would be considered welcome. If so, can somebody provide clues how it would be suitable to be implemented? |
@askalski Maybe https://github.com/Alloyed/lua-lsp could be used in some way |
@sum01 thank you. From what I understand is that I need to implement LSP client and languages provide servers. Also, I think I will dive into editing micro with go-lang to implement client. But I am still learning language features. |
I put together a quick hack using To run it, create the file function gocode(offset)
--TODO: Work out how to get the current buffer contents and pass it to gocode via stdin instead
-- of saving and using the -in parameter. For large files, this is likely to be inefficient, perhaps
-- micro keeps a scratch temporary file?
CurView():Save(false)
-- Use gocode and output the results of the autocomplete in JSON.
local handle = io.popen("gocode -f=json -in=" .. CurView().Buf.Path .. " autocomplete " .. offset)
local result = handle:read("*a")
--TODO: Work out how to parse the JSON (or text output) and create a list of options to return.
messenger:AddLog("gocode result: " .. result)
handle:close()
end
function onRune(r, v)
--TODO: Add some logic to determine when to start autocompleting. This will be:
-- * When a period is entered (e.g. "fmt." should produce "fmt.Println")
-- * When a bracket is opened (e.g. "fmt.Println(" should give information about the parameters)
-- * When Ctrl+Space is pressed
--TODO: Add some logic to determine when to stop autocompleting, e.g.
-- * Escape is pressed
-- * A selection is made from the list and entered into the buffer
-- * The bracket is closed
-- * Space is pressed
-- Convert the position of the cursor to a byte offset for use with gocode.
-- The '-' here is to derefence the pointer to v.Cursor.Loc which is automatically made
-- when converting go structs to lua
local offset = ByteOffset(-v.Cursor.Loc, CurView().Buf)
messenger:AddLog("rune: " .. r .. offset)
gocode(offset)
return false
end Open up the editor again, and switch on logging by hitting Start editing the text... At that point, every time you hit a rune in the editor, the It's very crude, but it shows that the autocomplete function is possible. The log shows So... any pointers on how to draw out a list of options, or does someone want to give that a blast? |
Apologies for the Go-specific nature of the above. I appreciate that it's not a globally useful solution. If the approach is to tackle this via a language server integration, then I guess it doesn't need to be a plugin and could be added to the core (and therefore written in Go)? |
I've started up on the autocomplete functionality as part of the core of micro in Go instead of as a plugin. I spent a few hours and I think what I've done would be a reasonable way to be able to extend it to other languages over at https://github.com/a-h/micro It doesn't insert text into the buffer yet, that's next. Look about right? |
I like it, simple and efficient. Hopefully you made sure to expose the proper functions so plugins can easily add onto it. |
Great, if I'm headed in the right direction, I'll keep on going. Good point on the plugin support, I'll make sure it's possible to write a plugin that can use autocomplete functionality. (adding options to, triggering and hiding the "dialog"). |
Created pull request: #977 |
Definitive +1 for a general Language Server Protocol implementation. The project got a new website recently, with this page listing all the supported languages (that includes Go). Looks like a quick win... |
The code from the refactor that I have been working on is now more or less ready to be merged. These changes make some breaking changes, notably with regards to the plugin interface. Once a lot more documentation has been written, I will release this code as micro 2.0. There are a lot of new features, and in the coming days I will try to go through the open issues to see exactly which ones are addressed by the new features, and write lots more documentation regarding what has been implemented. Some highlights include: * Simple autocompletion. * Autocompletion (tab by default) will do a simple "buffer completion" which will autocomplete according to words used elsewhere in the buffer. In the future plugin support could be added along with support for interfacing with language-specific autocompletion tools. * Automatic backups. * Backup files are stored in `~/.config/micro/backups` for every open buffer and are saved roughly every 8 seconds if the buffer is being modified. Backups are removed when the buffer is closed, but if micro or the system crashes, any unsaved changes can be recovered by re-opening the file (micro will auto- recover) or by manually viewing the backup in the `~/.config/micro/backups` directory. * Configurable statusline. * Configurable linter plugin. * Resizeable splits. * Complete re-organization of the code to support better go modules and maintain a better directory structure. * Better plugin interface with better access to the Go standard library and internal Micro functions (lots of documentation still needs to be written). * Documentation still needs to be written, but in the meantime please see the default plugins as examples as they have been converted from their old versions to be compatible with the new interface. * Buffer synchronization when the same file is opened multiple times. * Keybindings and mouse support in the command bar. * Support for non-utf8 encodings. * General QoL improvements and bug fixes. * Notably I believe the autoclose plugin crash issue is fixed. * No more plugin manager. * Plugin installation will now be performed manually by git cloning into the `~/.config/micro/plug` directory. This may not be a highlight for some but I believe it is much simpler, and there is no need to have a heavyweight dependency manager. Perhaps in the future, a good command-line tool can be made to manage plugins if people would find it useful. * Other features that I have forgotten. Next I plan to write up more documentation for all the new features, and make a "release candidate" for micro 2.0. I will also be working to fix any bugs that come up (hopefully not too many, but this is a big change and bound to have some issues). After release I hope to focus more on optimization (for example loading syntax files is currently somewhat inefficient, and the bottleneck for startup time #1427). Sorry for not being so active recently, but I hope merging this big change can help me get back to more regular development. Thanks to everyone for using micro and for giving feedback and engaging with development online (even if I don't always respond). Merry Christmas! Issues that are fixed/affected by this change: Ref #1419 (configurable statusline) Ref #1413 (cursor behaves better) Ref #1401 (softwrap problems) Ref #1383 (better save with sudo) Ref #1424 (better save with sudo) Ref #1382 (go modules) Ref #1381 (install plugins from command line) Ref #1357 (sorting -- textfilter) Ref #1351 (custom linting) Ref #1350 (sudo problem might be fixed) Ref #1298 (readonly option) Ref #1250 (autoclose bug) Ref #1239 (go modules) Ref #813 (autoclose bug) Ref #812 (cursor sync across same buffers) Ref #770 (resizeable panes) Ref #635 (keybindings in infobar) Ref #596 (disable builtin plugins) Ref #550 (backups) Ref #174 (autocompletion)
Simple buffer autocompletion (based on words in the current buffer) is now supported. The framework for autocompletion is also implemented so hopefully soon we can have support for more complex autocompletion and a plugin interface. |
It's amazing to see how Micro is growing sometimes slowly but steady. Have been waiting for buffer auto-completion for so long. Great job everyone involved, keep going. |
Are there any status updates? Just curious. |
I'd love to be able to provide additional autocomplete support via a plugin. Is there a starting point for this yet where I can pick up? |
Would love to use micro as my daily-driver text editor, will this feature be added? |
@zyedidia Is there a way to customize the word boundaries in the simple buffer autocompletion based on the filetype? I can't make it to work for so-called lispy identifiers (Lisp/Clojure/Scheme use dashes in identifiers |
we need a tabnine port for micro. |
Thanks for the suggestion, tabnine looks like it could be a good as a solution to more advanced autocompletion than what currently exists in micro. |
@zyedidia I am also a big fan of the LSP implementation and would love to see if someone has started working on this, as I might be able to help. |
wow i love this |
Hello, how are you ✋ |
any updates? will native autocomplete be implemented? |
I'm just waiting for this LSP feature to definitively leave NeoVIM+CoC. 🙂 |
Any progress on this? (Or a plugin that intergrates Jedi with Micro?) |
@XxnittanixX , nice to see you playing with high quality completion. I tried similar approach to LSP, executing gopls binary to get function signatures. However, @AndCake has now created a real JSON-RPC LSP plugin. As it keeps the language server running and communicates trough RPC, it's likely more efficient. It has some rudimentary support for LSP auto completion. Micro's LSP support and the plugin are also discussed in #1138. If you want to try it out, it's a two line install. E.g. on Debian 'sudo apt-get update; sudo apt-get -y install micro golang-go gopls; micro --plugin install lsp'. To test it, write a hello world 'micro hello.go', move cursor over PrintLn and press alt-K. Auto completion is ctrl-space. Update: Go installation is the easiest. Python installation is detailed in help/lsp.md. It has also been briefly tested with Javascript, Typescript, Rust and Lua; installation instructions for these would be nice. |
This looks amazing, thanks @AndCake |
Sorry to bump this, but I'm having a hard time recreating the behavior shown here
I ran
Then set my
which, for some reason, after quitting micro automatically gets rewritten to
After this, none of the commands (ctrl+space, alt+k, alt+r, alt+d) do anything. I was hoping someone could point me in the right direction? Is there something I forgot to configure or some docs that I missed on accident? Edit: Okay maybe it's not that nothing's happening, but it's incredibly delayed? I smashed ctrl+space over and over again and eventually something did show up, but
|
@ryan-caesar-ramos micro-plugin-lsp is a 3rd party plugin so a better place for the discussion would be its own repository (I wouldn't expect much as the project is not very active though). In my experience the autocompletion feature in micro-plugin-lsp is too buggy to be usable. I wrote my own alternative LSP plugin a while back, it's also far from perfect but its autocompletion has worked better for me most of the time. |
@Andriamanitra Thank you for the tip! Also appreciate you linking your alternative, I'll take a look |
Because micro already provides features like true color support, I wonder why there is not even an automatic completition for brackets and statements like
def
in python in ruby.Is this feature not implemented yet or do I experience a bug? Unfortunately I can't code in go.
Thanks!
The text was updated successfully, but these errors were encountered: