Cfx Lua IntelliSenseA 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.
Table of Contents
What It DoesWhen you open a Lua file in VS Code with this extension active, it will:
Supported Platforms
Prerequisites
InstallationFrom the VS Code Marketplace
Getting StartedOnce installed, the extension activates automatically whenever you open a By default, GTA V (FiveM) natives are loaded. To switch to RedM natives, use the Command Palette:
Your selection is persisted in your VS Code settings. ConfigurationThe extension exposes a single setting:
You can change this in your VS Code
Or use the provided commands from the Command Palette:
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 LibrariesNative function definitions are organized into three sets: CFX Shared Natives (
|
| 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]
Nonstandard Operators
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 Plugin System
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:
Safe Navigation Operator
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.
Manifest File Support
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.
FX Asset Protection
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.
.vscode and @meta Filtering
The plugin ignores files inside .vscode directories and files starting with ---@meta (such as the native definition files themselves) to avoid unnecessary processing.
How It Works Under the Hood
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.
Project Structure
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
Troubleshooting
IntelliSense isn't working
- 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.
Natives from the old Overextended extension are duplicating
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.
Diagnostics appear in fxmanifest.lua
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.
Safe navigation (?.) shows errors
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.
Extension settings aren't applying
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.
Contributing
- 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.
Building
yarn run compile # Development build
yarn run package # Production build
Linting & Formatting
pnpm biome lint --write
pnpm biome format --write
Credits
This 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
License
This project is licensed under the MIT License.