A Visual Studio Code extension that brings full IntelliSense, auto-completion, diagnostics, and type annotations to the Lua scripting environment used by FiveM and RedM. Built on top of the Lua Language Server by sumneko, this extension automatically configures your workspace with the correct runtime definitions, native function signatures, and LuaGLM type information so you can write Cfx.re Lua scripts with confidence.
Note
This project is an independently maintained fork. The original repository by Overextended was archived and its CI/CD pipeline was disabled, meaning native definitions could no longer be updated. This fork exists to keep the extension alive, with actively updated native definitions and continued maintenance.
This extension is not authored, published, sponsored, nor endorsed by Cfx.re or Rockstar Games.
- What It Does
- Supported Platforms
- Prerequisites
- Installation
- Getting Started
- Configuration
- Native Libraries
- Runtime Definitions
- LuaGLM Support
- The Plugin System
- How It Works Under the Hood
- Project Structure
- Troubleshooting
- Contributing
- Credits
When you open a Lua file in VS Code with this extension active, it will:
- Auto-configure the Lua Language Server — sets the runtime to Lua 5.4, enables Cfx-specific nonstandard operators (
+=,-=,*=,/=, backtick strings, block comments, etc.), and configures workspace ignore directories for performance. - Inject native function definitions — provides typed signatures for thousands of GTA V, Red Dead Redemption 3, and CFX-specific native functions, complete with parameter names, types, and documentation links.
- Provide runtime globals — adds type definitions for Cfx runtime APIs like
Citizen.CreateThread,Citizen.Wait,PerformHttpRequest, promises, statebags, events, JSON helpers, and msgpack utilities. - Add LuaGLM types — defines
vector2,vector3,vector4,quat, and matrix types with full operator overloads and method signatures, matching the custom Lua implementation used by Cfx.re. - Install a language server plugin — a Lua plugin that handles Cfx-specific syntax edge cases, such as safe navigation operators (
foo?.bar),fxmanifest.lua/__resource.luaglobal suppression, and FX asset protection headers.
| Platform | Natives | Runtime Globals |
|---|---|---|
| FiveM (GTA V) | ~64,000 lines of typed definitions across 43 categories (VEHICLE, PED, ENTITY, HUD, etc.) | Full support |
| RedM (RDR3) | ~50,000+ lines of typed definitions across 60+ categories | Full support |
| CFX Shared | ~9,000 lines of CFX-specific native definitions | Full support |
- Visual Studio Code v1.71.0 or later
- Lua Language Server extension by sumneko (installed automatically as a dependency)
- Open VS Code.
- Go to the Extensions view (
Ctrl+Shift+X/Cmd+Shift+X). - Search for Cfx Lua IntelliSense by
ihyajb. - Click Install.
Once installed, the extension activates automatically whenever you open a .lua file. There is no manual setup required. Your workspace will be configured with the appropriate Lua Language Server settings on activation.
By default, GTA V (FiveM) natives are loaded. To switch to RedM natives, use the Command Palette:
Ctrl+Shift+P→ CfxLua: Use RDR3 nativesCtrl+Shift+P→ CfxLua: Use GTAV natives
Your selection is persisted in your VS Code settings.
The extension exposes a single setting:
| Setting | Type | Default | Description |
|---|---|---|---|
cfxlua.game |
"gtav" | "rdr3" |
"gtav" |
Determines which set of game-specific natives to load into the language server. |
You can change this in your VS Code settings.json:
{
"cfxlua.game": "rdr3"
}Or use the provided commands from the Command Palette:
| Command | Description |
|---|---|
| CfxLua: Use GTAV natives | Switch to GTA V / FiveM native definitions |
| CfxLua: Use RDR3 natives | Switch to Red Dead Redemption 3 / RedM native definitions |
When switching games, the extension will remove the previous game's native library and add the new one, keeping CFX shared natives always active.
Native function definitions are organized into three sets:
These are platform-independent natives provided by the Cfx.re framework itself, such as AddAudioSubmixOutput, ActivateTimecycleEditor, and hundreds of other CFX-specific functions. These are always loaded regardless of your game selection.
Game-specific natives split across 43 files by category:
APP · AUDIO · BRAIN · CAM · CLOCK · CUTSCENE · DATAFILE · DECORATOR · DLC · ENTITY · EVENT · FILES · FIRE · GRAPHICS · HUD · INTERIOR · ITEMSET · LOADINGSCREEN · LOCALIZATION · MISC · MOBILE · MONEY · NETSHOPPING · NETWORK · OBJECT · PAD · PATHFIND · PED · PHYSICS · PLAYER · RECORDING · REPLAY · SAVEMIGRATION · SCRIPT · SHAPETEST · SOCIALCLUB · STATS · STREAMING · SYSTEM · TASK · VEHICLE · WATER · WEAPON · ZONE
Game-specific natives split across 60+ files by category, including RedM-specific categories like:
ANIMSCENE · ATTRIBUTE · BOUNTY · COLLECTION · COMPANION · COMPENDIUM · DATABINDING · FLOCK · GANG · INVENTORY · ITEMDATABASE · LAW · MAP · MINIGAME · MISSIONDATA · PERSCHAR · PERSISTENCE · POPULATION · and many more.
Each native definition includes:
- Full function signature with typed parameters and return values
- A link to the official FiveM/RedM native documentation
- The native category and execution context (client/server)
- Deprecated aliases where applicable
The extension ships with type annotations for the Cfx.re Lua runtime environment. These are located in the plugin/library/runtime/ directory:
Typed definitions for the global Citizen table and its convenience aliases:
Citizen.CreateThread/CreateThread— Create an async coroutine (executes next tick)Citizen.CreateThreadNow— Create an async coroutine (executes immediately)Citizen.SetTimeout/SetTimeout— Execute a callback after a delayCitizen.Wait/Wait— Yield (pause) a coroutine for a durationCitizen.Trace— Output to trace/consoleCitizen.Await— Yield until a promise resolvesCitizen.InvokeNative— Invoke a native by hash
Typed definitions for server/client globals:
GetPlayerIdentifiers,GetPlayerTokens,GetPlayersPerformHttpRequest/PerformHttpRequestAwaitStateBagclass andEntityInterfacetypes- Event registration:
AddEventHandler,RegisterNetEvent,TriggerEvent,TriggerServerEvent,TriggerClientEvent - Resource metadata:
GetCurrentResourceName,GetResourceState
Full type definitions for the lua-promises library bundled with Cfx.re:
promise.new,promise.all,promise.map,promise.firstpromiseclass withresolve,reject,next,value, andstatefields
Type definitions for the built-in json.encode and json.decode functions.
Type definitions for the msgpack utilities available in the Cfx.re runtime.
Additional event-related type definitions and helpers.
See the dedicated section below.
Cfx.re uses a custom fork of Lua called LuaGLM that extends the language with mathematical types and nonstandard syntax. This extension provides full type support for:
| Type | Fields | Description |
|---|---|---|
vector2 |
x, y (aliases: r, g) |
2D vector with arithmetic operator overloads |
vector3 |
x, y, z (aliases: r, g, b) |
3D vector extending vector2 |
vector4 |
x, y, z, w (aliases: r, g, b, a) |
4D vector extending vector3 |
quat |
x, y, z, w |
Quaternion type extending vector4 |
All vector types support:
- Arithmetic operators:
+,-,*,/, unary- - Length operator:
# - Swizzle access:
.xy,.xyz, etc. - Indexed access:
[1],[2],[3],[4]
The extension configures the Lua Language Server to recognize these Cfx-specific operators:
+= -= *= /= <<= >>= &= |= ^=
`template strings`
/**/ (block comments)Caution
Some of these "power patches" have been known to cause instability. Use extended syntax features with caution in production scripts.
The extension installs a Lua Language Server plugin (plugin.lua) that preprocesses Lua files before the language server analyzes them. This plugin handles several Cfx-specific quirks:
Cfx Lua supports foo?.bar and foo?[index] syntax, which standard Lua does not. The plugin strips the ? character from these expressions to prevent parse errors, and rewrites usage to suppress need-check-nil diagnostics.
Files named fxmanifest.lua and __resource.lua use globals like fx_version, game, client_script, etc., that aren't defined anywhere in user code. The plugin injects ---@diagnostic disable: undefined-global at the top of these files to prevent false positive warnings.
Files beginning with the FXAP header (FiveM asset protection) are encrypted and not valid Lua — the plugin returns an empty string for these files so the language server skips them gracefully.
The plugin ignores files inside .vscode directories and files starting with ---@meta (such as the native definition files themselves) to avoid unnecessary processing.
When the extension activates (triggered by opening any .lua file):
-
File Migration — The bundled
plugin.luaandlibrary/directory are copied from the extension's install location to VS Code's global storage for the extension. This ensures a stable path that persists across extension updates. -
Plugin Registration — The path to
plugin.luais written to theLua.runtime.pluginsetting, telling the Lua Language Server to load it. -
Library Injection — The paths to the appropriate native definition folders (
runtime/,natives/CFX-NATIVE/, and eithernatives/GTAV/ornatives/RDR3/) are appended toLua.workspace.library, making all type information available to the language server. -
Runtime Configuration — The Lua runtime version is set to
5.4, nonstandard symbols are registered, and workspace ignore directories are configured to improve performance. -
Cleanup on Deactivation — When the extension is deactivated or VS Code closes, the plugin path and all library paths added by the extension are removed from settings, leaving your configuration clean.
Settings are applied at the workspace level when a workspace file is present, or at the global (user) level otherwise. This is determined by checking for workspace.workspaceFile.
cfxlua-vscode/
├── src/ # Extension source code (TypeScript)
│ ├── extension.ts # Entry point — activation, deactivation, command registration
│ ├── getLuaConfig.ts # Helper to access the Lua Language Server configuration
│ ├── getSettingsScope.ts # Determines workspace vs. global settings scope
│ ├── moveFile.ts # Copies bundled files to global storage
│ ├── setLibrary.ts # Manages Lua.workspace.library entries
│ ├── setNativeLibrary.ts # Handles game-specific native library switching
│ └── setPlugin.ts # Configures Lua.runtime.plugin and related settings
│
├── plugin/ # Bundled plugin and library definitions
│ ├── plugin.lua # Lua Language Server plugin for Cfx-specific preprocessing
│ ├── config.json # Default Lua Language Server addon configuration
│ └── library/
│ ├── runtime/ # Cfx runtime type definitions
│ │ ├── citizen.lua # Citizen API (CreateThread, Wait, etc.)
│ │ ├── env.lua # Environment globals (events, HTTP, statebags)
│ │ ├── event.lua # Event handling types
│ │ ├── json.lua # JSON encode/decode types
│ │ ├── luaglm.lua # Vector, quaternion, matrix types
│ │ ├── msgpack.lua # MessagePack types
│ │ └── promise.lua # Promise library types
│ └── natives/
│ ├── CFX-NATIVE/ # CFX shared natives (always loaded)
│ │ └── CFX.lua
│ ├── GTAV/ # GTA V natives (43 category files)
│ │ ├── VEHICLE.lua
│ │ ├── PED.lua
│ │ └── ...
│ └── RDR3/ # RDR3 natives (60+ category files)
│ ├── PED.lua
│ ├── ENTITY.lua
│ └── ...
│
├── package.json # Extension manifest
├── tsconfig.json # TypeScript configuration
├── webpack.config.js # Build configuration
└── biome.json # Linting and formatting configuration
- Ensure the Lua Language Server extension is installed and enabled.
- Check that
cfxlua.gameis set to a valid value ("gtav"or"rdr3"). - Open the Command Palette and run Developer: Reload Window to re-trigger activation.
This extension includes migration logic that automatically removes library paths from the original overextended.cfxlua-vscode extension. If you still see duplicates, manually check your Lua.workspace.library setting and remove any paths containing overextended.cfxlua-vscode.
The extension's plugin suppresses undefined-global warnings in manifest files. If you're still seeing them, verify that Lua.runtime.plugin points to the correct plugin.lua path in your settings.
The plugin rewrites safe navigation syntax to prevent parse errors. If it's not working, ensure the plugin is correctly loaded by checking Lua.runtime.plugin in your settings.
The extension applies settings at the workspace level if a .code-workspace file is open, otherwise at the user (global) level. Check the appropriate settings scope for your configuration.
- Clone the repository:
git clone https://github.com/ihyajb/cfxlua-vscode.git
- Install dependencies:
cd cfxlua-vscode yarn install - Open the project in VS Code and press
F5to launch the Extension Development Host. - The
npm: watchtask will automatically compile TypeScript on changes.
yarn run compile # Development build
yarn run package # Production buildpnpm biome lint --write
pnpm biome format --writeThis project builds upon the work of many contributors to the Cfx.re ecosystem:
- Overextended — creators of the original cfxlua-vscode extension
- CitizenFX Collective — developers of FiveM, RedM, and the LuaGLM runtime
- sumneko — author of the Lua Language Server
- gottfriedleibniz — LuaGLM implementation
- alloc8or, iTexZoz, TasoOneAsia — community contributions to native definitions and tooling
This project is licensed under the MIT License.