Page 1 of 1
LUA IDE with typehint support
Posted: Fri Jan 28, 2022 3:48 pm
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!
Re: LUA IDE with typehint support
Posted: Sat Jan 29, 2022 6:47 am
by PFQNiet
That VSCode extension is exactly how I work with this.
Re: LUA IDE with typehint support
Posted: Sat Jan 29, 2022 10:09 am
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).
Re: LUA IDE with typehint support
Posted: Sun Jan 30, 2022 11:05 am
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!
Re: LUA IDE with typehint support
Posted: Sun Jan 30, 2022 11:25 am
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!
Re: LUA IDE with typehint support
Posted: Wed Feb 09, 2022 9:39 pm
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.
Re: LUA IDE with typehint support
Posted: Thu Feb 10, 2022 6:37 pm
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