cuberite icon indicating copy to clipboard operation
cuberite copied to clipboard

Added code to export definitions for a lua-language-server

Open NiLSPACE opened this issue 3 years ago • 6 comments

I still need to write an article to explain how to configure the language server so this PR is still a work in progress, but the definition generation seems to be working now.

The definitions should work with any IDE that can use lua-language-server. Here is an example with Visual Studio Code:

https://user-images.githubusercontent.com/1160867/224548605-7651ff31-938e-4c51-bdcc-c0abfaabed29.mp4

NiLSPACE avatar Mar 12 '23 13:03 NiLSPACE

I now see why everything in the APIDump plugin was in a single file ;) It's so the functions don't show up in the global environment. I'll move the functions over to the main file later.

NiLSPACE avatar Mar 12 '23 15:03 NiLSPACE

Seeing the APIDump code makes me want to rewrite it :)

madmaxoft avatar Mar 12 '23 16:03 madmaxoft

I had the same urge when I looked at some (or most) of the WorldEdit code yesterday ;)

NiLSPACE avatar Mar 12 '23 16:03 NiLSPACE

The 'not polluting _G' issue could also be fixed by immediately replacing _G with an empty table with __index pointing to the old values.

local newEnv, oldEnv = {}, _G
local setmetatable = setmetatable
for k, v in pairs(_G) do
	newEnv[k] = v;
	oldEnv[k] = nil;
end
_G = setmetatable(oldEnv, {__index = newEnv});

Then instead of looping through _G you'd loop through getmetatable(_G).__index

NiLSPACE avatar Mar 12 '23 17:03 NiLSPACE

So is it VSCode-only or generic lua-language-server? Just to get the naming right.

madmaxoft avatar Mar 12 '23 17:03 madmaxoft

I've only tested it on VSCode, but it should work on any lua-language-server. But you're right, I'll change the naming.

NiLSPACE avatar Mar 12 '23 19:03 NiLSPACE