Overview
GMod addons use hooks to respond to game events. GLuaLS understandshook.Add, hook.Remove, hook.Run, hook.Call, and GM: definitions. It provides completions, type inference, and validation for each one.
Hook name validation
Unrecognized hook names inhook.Add and hook.Remove trigger a diagnostic:
hook.Run("MyCustomHook", ...).
For custom hooks, autocomplete works after code uses the hook once. Go to definition, parameter type inference, and other advanced hook features need a
GM: function for that hook.Parameter type inference
When GLuaLS knows the hook name, it types the callback parameters:Callback snippet completion
When you typehook.Add("HookName", and trigger completion on the callback argument, GLuaLS inserts a typed function snippet:
GM: hook definitions
Files in a gamemode context, such asgamemodes/*/gamemode/, define GM as the gamemode table. GLuaLS recognizes function GM:HookName() as a hook override:
GM: hook definition is required for advanced features to work on custom hooks.
hook.Run and hook.Call completions
When typing the first argument tohook.Run or hook.Call, GLuaLS autocompletes from known hook names:
Custom hooks
GLuaLS also tracks hooks created by your code or your library:For advanced features (parameter type inference, hover descriptions, function validation), define a
GM: method for each custom hook.VSCode integration
Hook intelligence works when you usehook.Add, hook.Run, or define GM: methods. Configure validation behavior in the settings panel. See GMod settings for the full reference.
Configuration
Control hook validation and mappings through thegmod section in .gluarc.json, especially gmod.hookMappings and the global diagnostics settings.
| Setting | Default | Description |
|---|---|---|
gmod.hookMappings.methodToHook | {} | Map method names to hook names (e.g. "Think": "Think") |
gmod.hookMappings.emitterToHook | {} | Map custom emitter functions to hook names |
gmod.hookMappings.methodPrefixes | [] | Custom method prefixes for inferred GM: hook methods |
diagnostics.disable | [] | Disable individual diagnostics (e.g., "gmod-invalid-hook-name") |