lua-mode
lua-mode copied to clipboard
company backend
It be great if lua-mode came with a company backend.
There's https://github.com/ptrv/company-lua for builtin stuff. As for dynamic completions, I don't think it will come soon.
That is if you wait it from me :) But, of course, PRs are welcome.
I have some code here for loading completions dynamically from a subprocess: http://p.hagelb.org/pnh-lua-completion.el.html It uses Emacs's built-in completion-at-point
instead of any 3rd-party completion libs. If you like I could clean it up for inclusion in lua-mode.
There are a few shortcomings; first that it uses a tempfile to communicate candidates back to Emacs. I believe this is the only way since lua-mode only seems to support one-way Emacs->Lua communication, but this is kind of tacky. Secondly it only supports completing from _G
; I would like to support completing from the current lexical context, but Lua makes this difficult because loadstring
ignores lexical context.
I have a new version that works with top-level lexical scope; however the means by which it accomplishes it is somewhat questionable: http://p.hagelb.org/pnh-lua-complete.el.html
Basically it greps the file for "local x = require y" matches and then during the point of calculating the completions, it creates a clone of _G
, stuffs each lib that was required into that table under the name of the local. Then it uses this table as a context in which to look up completions.
Anyway, this seems a lot more useful than completing based on _G
alone, but I'm not so sure about the way we match against loaded libs using a regex. Thoughts?
I've taken technomancy's PR and fixed various issues that made CI testing fail, and made some significant improvements. These include using comint-redirect to avoid writing an external file, traversing the globals tree in a limited breadth-first search, caching completion results for speed, and more. Very usable at this point, including with company mode; see the discussion in the PR's: #147, #148 .