LUA IDE with typehint support

Place to post guides, observations, things related to modding that are not mods themselves.
Post Reply
mattie112
Burner Inserter
Burner Inserter
Posts: 7
Joined: Fri Jan 28, 2022 3:39 pm
Contact:

LUA IDE with typehint support

Post by mattie112 »

Hi,

I'm a programmer (with no LUA experience) and I want to make a small mod for Factorio. One thing that I think makes life 100% better is using a good IDE with typing / autocomplete support. You don't want to spend tracing bugs and finding a typo like

Code: Select all

defines.events.on_research_fnished
if your IDE can alert you before trying your mod.

However: I can't really find anything on this other then a VSCode extension from 2019. I did find the API website (with a JSON) but is there an IDE/editor that can handle this? How are you guys working with this?

Thanks for any tips!

PFQNiet
Filter Inserter
Filter Inserter
Posts: 289
Joined: Sat Sep 05, 2020 7:48 pm
Contact:

Re: LUA IDE with typehint support

Post by PFQNiet »

That VSCode extension is exactly how I work with this.

Bilka
Factorio Staff
Factorio Staff
Posts: 3128
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: LUA IDE with typehint support

Post by Bilka »

I can generally recommend this setup for VSCode: https://github.com/justarandomgeek/vsco ... rkspace.md

It uses a function from justarandomgeek.factoriomod-debug to generate data for sumneko.lua to do the autocomplete for the api docs.

Since it uses the runtime-api.json, it's more up to date than the older svizzini.factorio-lua-api-autocomplete (which isn't needed for this setup).
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

mattie112
Burner Inserter
Burner Inserter
Posts: 7
Joined: Fri Jan 28, 2022 3:39 pm
Contact:

Re: LUA IDE with typehint support

Post by mattie112 »

Yes that was my problem with the extension I already found a couple of thins not listed there (probably due to it's age). I will take a look at your suggestion Bilka, thanks!

mattie112
Burner Inserter
Burner Inserter
Posts: 7
Joined: Fri Jan 28, 2022 3:39 pm
Contact:

Re: LUA IDE with typehint support

Post by mattie112 »

Allright, I have it now setup with that plugin but for example this piece of code

Code: Select all

script.on_event(defines.events.on_built_entity, function (event)
    log_message(event.created_entity.name)
end)
The IDE still doesn't know the type of event (it is EventData) but I like to know the actual type (onBuiltEntity). Is there any typehinting support? For example in php with most IDE's you can do something like

Code: Select all

/** @var $foo NotObjectButSomeOtherClass
$foo = new Object();
And the IDE assumes is is of type 'NotObjectButSomeOtherClass'

edit:

Allright this seems to work

Code: Select all

script.on_event(defines.events.on_built_entity,
    ---@param event on_built_entity
    function (event)
    log_message(event.created_entity.name)
end)
Automatic support for this would be great but this makes my live much easier :)

edit 2:
It does work automatically, I had a typo in the lua.runtime.plugin :)

Thank you!

fredthedeadhead
Inserter
Inserter
Posts: 28
Joined: Mon Oct 18, 2021 6:13 pm
Contact:

Re: LUA IDE with typehint support

Post by fredthedeadhead »

I'm using TypescriptToLua and GlassBricks/typed-factorio for exactly the same reason. It's working really well. I'd never used TypeScript (or Javascript) before I started, but I found it easy to pick up. IntelliJ supports autocomplete well.

mattie112
Burner Inserter
Burner Inserter
Posts: 7
Joined: Fri Jan 28, 2022 3:39 pm
Contact:

Re: LUA IDE with typehint support

Post by mattie112 »

Ah great, support for IntelliJ (and most likely others from JetBrains). I will look into this the next time I change stuff for my plugin :)

Post Reply

Return to “Modding discussion”