Jump to content
TeardownMods

Unofficial API.lua Workspace Library Converted from xml for VSCode 1.0.0

   (1 review)

2 Screenshots

About This File

After getting frustrated by having to search the api.xml file every time I needed to call a function, rather than being able to use VSCode's Intellisense to autocomplete and check them, as well as getting no good answer on how I could use the XML as a library or what IDE would support it; I decided to use a series of long regex replacements to convert it from .xml format to .lua format so that I could use the lua.workspace.library setting in Sumneko's LUA extension to add the api to intellisense. I am providing it here because I put 7 hours into this and I don't want anyone who has the same problem to have to do the same thing if I can provide a solution for them.

Bear in mind that this was done with regex replacement, so it's not perfect. And also note that I could not find a way to mark an argument/parameter as optional in a lua library... I may rebuild it and add that to the description section if I get the motivation.

 

Special thanks to https://regexr.com/ for making the process achievable for me. Without it and it's tools, I would never have been able to finish this project.

 

 

If you are interested, here is an example of the crazy regex I ended up using... This isn't even the longest one...

Find: (?:---@return (\b\w+\b ).+?[\s\S]+?)?(?:---@return (\b\w+\b ).+?[\s\S]+?)?(?:---@return (\b\w+\b ).+?[\s\S]+?)?(?:---@return (\b\w+\b ).+?[\s\S]+?)?function (?:\b\w+\b)

replace:$&\n\treturn $1\n\treturn $2\n\treturn $3\n\treturn $4\n


What's New in Version 1.0.0   See changelog

Released

No changelog available for this version.

  • Like 2

User Feedback

Recommended Comments

Note for those which need help for installation follow these steps:
 
1. Open VS Code
2. Install the Lua extension from Sumenko (https://marketplace.visualstudio.com/items?itemName=sumneko.lua)
3. Change the Lua > Workspace: Library in the extensions settings
    -> Add the here provided "api.lua" file to the settings.json which could look like that:
{
    "Lua.workspace.library": {
        "C:\\Users\\<username>\\Documents\\Teardown": true
    }
}
4. Restart VS Code
5. Using intellisense in your own Lua script will now provide help

Thanks for the creation.

May I suggest you create a GitHub repository so it can be improved?

Edited by viperbone
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Add a comment...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

How to Disable AdBlock - And why you should do it?

I have disabled AdBlocker. Refresh the page.