Skip to main content

Overview

GMod addons use hooks to respond to game events. GLuaLS understands hook.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 in hook.Add and hook.Remove trigger a diagnostic:
GLuaLS recognizes built-in GMod hooks from the downloaded API definitions. It also tracks custom hook names used by your workspace.

Parameter type inference

When GLuaLS knows the hook name, it types the callback parameters:

Callback snippet completion

When you type hook.Add("HookName", and trigger completion on the callback argument, GLuaLS inserts a typed function snippet:
The snippet includes the correct number of parameters with their names.

GM: hook definitions

Files in a gamemode context, such as gamemodes/*/gamemode/, define GM as the gamemode table. GLuaLS recognizes function GM:HookName() as a hook override:
A GM: definition gives a custom hook a clear signature and definition target.

hook.Run and hook.Call completions

When typing the first argument to hook.Run or hook.Call, GLuaLS autocompletes from known hook names:

Custom hooks

GLuaLS also tracks hooks created by your code or your library:
Add annotations to a custom GM: method when you want stable parameter types and hover documentation across the project.

Hook wrappers

Framework wrappers around hook registration and execution can provide the same features. GLuaLS reads wrapper behavior from the Garry’s Mod annotations instead of requiring a specific function name. See @call_arg when you need to describe your own wrapper.

VS Code integration

Hook intelligence works when you use hook.Add, hook.Run, or define GM: methods. Configure validation behavior in the settings panel. See Garry’s Mod settings for the full reference.

Configuration

Control hook validation and mappings through the gmod section in .gluarc.json, especially gmod.hookMappings and the global diagnostics settings.