Added code to export definitions for a lua-language-server
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
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.
Seeing the APIDump code makes me want to rewrite it :)
I had the same urge when I looked at some (or most) of the WorldEdit code yesterday ;)
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
So is it VSCode-only or generic lua-language-server? Just to get the naming right.
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.