[Dev release] Visual Studio Code native snippets

Native code snippets for Visual Studio Code. Similar to what I’ve made in the past for Notepad++

I know some version similar to this already exists here, but that hasn’t been updated for quite some time and does not provide a description with detailed information about return value, namespace, CFX apiset and the actual native description.

So here’s my version:

Code snippets (all native functions) for visual studio code

download: https://vespura.com/hi/i/lua.json

install:

  1. Download the json file (just right click > save as)
  2. Either
    • copy/paste everything into your user snippets (in visual studio go to File > Preferences > User Snippets and open the Lua one), or;
    • place the lua.json file inside {your visual studio code installation folder}\resources\app\extensions\lua\snippets\lua.json (make the snippets folder if it doesn’t exist), next follow step 3.
  3. (skip if you chose the first option in step 2): go up one folder level from the previous step, so you end up in \lua\, and open the package.json file, add this code below the “grammars” section.
,
        "snippets": [
            {
              "language": "lua",
              "path": "./snippets/lua.json"
            }
        ]
  1. Restart visual studio code and edit any .lua file to test it out.
  2. Profit

issues
Only known issue currently is that there’s no snippets for Citizen.CreateThread and similar non-native functions. Neither does it have actual basic Lua functions like table.unpack for example. For the non-native functions, I suggest you just add those manually for now (until I add them at some later point) or use the ones from the other release mentioned at the top of this thread.

The download will be updated whenever major changes are made to the native reference, so just download the file from the same url as mentioned above whenever a new version is released.

14 Likes

love you @Vespura :kissing_heart: . Been using the old one for awhile, nice to have a update.

1 Like

How long did this take you to put together?

1 Like

Not that long, made a script for it.

Ah ok, I was under the impression you did that manually lol

1 Like

This snippets can be used with js too ?

If that uses the same format then probably yeah.

For JS use https://www.npmjs.com/package/@citizenfx/client (add it as a reference to your file)

Small update, natives have been updated to the latest version.

Added warnings that show when you are using old native names, and it tells you what the new native name is that you should be using instead:

Old names will also be shown when you start typing the latest name:

Download: here or lua.json (3.1 MB) (read a couple of comments below for the correct files)

2 Likes

Can’t seem to get this to work, I tried both methods (adding with VSCode and putting the file in the snippets folder) but it keeps saying “No Suggestions”. I tried the old snippets you linked in your post and they work fine. When I copy/paste into lua.json it says: Incorrect type. Expected “object”

I was looking to use this but the lua.json format doesn’t seem to match VSCode’s snippet format which causes it to fail to load.

Adding the latest file linked, no snippet help shows and I get:

Cannot Destructure propery "Prefix" of Undefined or Null

when trying to load the user snippets panel. the file has to be manually removed from config directory before snippet panel will load again.

Same here, not working on my end.

I’ll look into this, it worked fine for me, maybe I’ve confused the two output files of my script when uploading this latest version. Will let you guys know tomorrow.

Edit: looks like I indeed mixed up the output file with another. My bad, I’ll fix this tomorrow.

1 Like

lua.json (1.9 MB)
There we go, that should be the correct one. This link has also been updated.

3 Likes

That works great, thanks!

1 Like

Thank you so much! <3

We thank you for your screenshot.