Lua autocomplete for Atom


Hi, so after a discussion started here, I decided I should try and play a bit with Lua ASTs and make an Atom autocomplete+ provider for Lua. I made this thread to share progress.

I’m not sure if this should be here or in The Defoldmine. Correct me if I’m wrong.

So, the repo is at dapetcu21/atom-autocomplete-lua

Get it for Atom here:

I also made a package specifically for Defold which parses the reference docs:

The idea

I started with the idea of structural type definitions. Type definitions for primitives are straightforward. For tables I store the type definition of the fields they might contain and the type definition of their metatable (if known).

Then, as I would parse, I would evaluate the types of expressions and update the type definitions as I scan by assignments and function definitions.

I solved the problem of variable scopes by treating them like tables and assigning them type defs, since table type defs can inherit from each other with metatables.

This type system lets me able to do more advanced stuff like inferring the return type of a function:

local cat = { __index: {} }
  local inst = {}
  setmetatable(inst, cat)
  return inst

function cat.__index:meow()

local tom =
tom: -- this would suggest meow()

What I have now

  • Discovers symbols from assignments, initializers, declarations or just plain usage of tables
  • Dot completion with . and :
  • Roughly detects the types of the symbols
  • Respects scope (even if you shadow a global var with a local one)
  • Can “see through” setmetatable() and __index
  • Infers the return type of functions
  • Can be configured with a .luacompleterc


Adding a function of using other code editors and offline mode
Auto complete not working (SOLVED)
I'm new to Lua, so I'm confused
Triggering hot reloading externally
Collapse/Expand functions in script files

Very nice! This will be quite useful!



Here’s some more progress. I’ll publish to APM soon.



Wow! Very helpful! Thanks!

1 Like


Aaand, it’s up:

Remember, this is still work in progress. There is no support for defining globals yet, no standard library definitions and the type inference system is nowhere complete.



It now also scans all the table members you’ve used and suggests them:

I still have some scoping issues to iron out.

…and by this point I should start writing tests… the dread…



Ladies and gents, I give you Atom Defold IDE:

It automatically downloads the API refs and keeps itself up to date.



Brilliant! Than you for the time you’ve put into this poject. Did you have any prior experience creating Atom plugins?

1 Like


Nope. First Atom plugins. But I have a lot of experience with JS.



It’s great! Very useful plugin. Thank you!

1 Like


Nothing brilliant to say, I just want to thanks and encourage you to keep doing it :wink:



Here’s some more progress:

It’s aware of setmetatable() and keeps track of function return types:



Looking awesome so far! How far off is it to get autocomplete for requires? I’ve tested most IDEs with autocomplete for LUA but not completely happy with any so far. LDT and Lua Glider have been the best so far. Will be nice to test this when requires work!

1 Like


It’s not very far off. I’ve been slowly heading in that direction with return type detection and some refactoring, but I’m adding definitions for Lua’s standard library first. I have them parsed, just need to do some work on the plugin system before I add them in.



Lua standard library completion and docs:



I also implemented triggering hot reloading from within Atom:

It’s not as instant as from within the Editor, but sure beats all that Alt-Tabbing.



I guess you should be able to also build and lunch using pyfold?



Huh? I don’t get it. What does pyfold have to do with this? You meant Defold? Yes, the intended use case is for you to still Build & Launch, work on collections etc. using the Defold editor, but when it comes to code, since you’re already editing code in Atom, you should be hot reloading without alt tabbing. It’s not meant to replace other aspects of the Defold editor in any way, other than their code editor and hot reloading seems to be a big feature of their code editor that’s desirable to replicate.

1 Like


I believe Pyfold is not an public library as for now.



To clarify:
pyfold is a python library developed internally at King (but not written nor maintained by the Defold team). The purpose is to simplify different tasks for commandline usage, mainly for CI. I bet it still uses bob though as I don’t think the pyfold authors replicated the entire content pipeline in python? :slight_smile: