lua-mode icon indicating copy to clipboard operation
lua-mode copied to clipboard

company backend

Open gozes opened this issue 9 years ago • 5 comments

It be great if lua-mode came with a company backend.

gozes avatar Mar 06 '15 01:03 gozes

There's https://github.com/ptrv/company-lua for builtin stuff. As for dynamic completions, I don't think it will come soon.

immerrr avatar Oct 23 '15 11:10 immerrr

That is if you wait it from me :) But, of course, PRs are welcome.

immerrr avatar Oct 23 '15 11:10 immerrr

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.

technomancy avatar Jun 06 '16 04:06 technomancy

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?

technomancy avatar Jun 06 '16 07:06 technomancy

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 .

jdtsmith avatar May 24 '19 14:05 jdtsmith