dfhack icon indicating copy to clipboard operation
dfhack copied to clipboard

vscode Lua integration

Open ab9rf opened this issue 3 years ago • 5 comments

we should probably provide whatever integration is needed to enable vscode's lua extension (vscode-lua) to be aware of DFHack's lua libraries, as this would facilitate the use of vscode to edit dfhack lua scripts

for more info about vscode-lua, see this link

ab9rf avatar Dec 14 '22 03:12 ab9rf

Also if i could be totally shameless - related issue #420. Theoretically any we could have lua breakpoints! (not sure if vscode-lua supports the same attach a debugger to socket system)

warmist avatar Dec 14 '22 06:12 warmist

You may want to use sumneko's lua vscode extension instead of vscode-lua. Vscode-Lua hasn't been updated in 4 years and I think the only analysis it does is provided by luacheck, which is a good tool but doesnt seem to cover any type checking.

sumneko's on the other hand is under active development and provides dynamic type checking that can be further augmented by using annotations. I have used type annotations on some of my python projects in a similar way and it is an extremely nice feature

Extension: https://github.com/sumneko/lua-language-server

Type checking example: https://github.com/sumneko/lua-language-server/wiki/Type-Checking

Akiira avatar Dec 14 '22 12:12 Akiira

sumneko's extension looks pretty slick. I'm looking into it now. I'm trying to figure out how to get it to recognize the symbols injected into the environment from dfhack.lua.

I asked a question here: sumneko/lua-language-server#1766

myk002 avatar Dec 14 '22 16:12 myk002

See Akiira's comment that just adding df and dfhack as globals goes a long way: https://github.com/sumneko/lua-language-server/issues/1766#issuecomment-1352627728

we could also produce a library definition file and maybe get the entire C API available for autocompletion...

myk002 avatar Dec 15 '22 19:12 myk002

Working through some prototyping over in https://github.com/vallode/dfhack-lua-definitions. The gist, as I see it, is:

  • Automatic generation of type definitions for all structures is possible
  • Module-level functions will need to be maintained manually

I think my generating the definitions from XML parsing via ruby isn't ideal, but it's probably the only way available in my toolbelt right now. Ideally we'd hook into the actual XML generation and generate the lua definitions in the same way we do the structures. My 2 cents, I'll know more when I work through this a bit more :)

vallode avatar Jan 24 '23 18:01 vallode

@vallode have you been able to make anything sharable for dfhack-vscode integration? something we could check into our tree or add to our docs?

myk002 avatar Feb 27 '23 19:02 myk002