Overview
Diagnostics appear as squiggly underlines in the editor and in the Problems panel (Ctrl+Shift+M). Each diagnostic has a severity level and a code identifier you can use for configuration.
Severity levels
| Severity | Appearance | When to use |
|---|
error | Red underline | Hard errors that will likely break your code |
warning | Yellow underline | Probable bugs or type mismatches |
information | Blue underline | Stylistic or best-practice suggestions |
hint | Subtle underline | Minor suggestions, safe to ignore |
Configuring diagnostic severity
Change the severity of any diagnostic code, or disable it:
Use the settings menu instead of editing the JSON file directly. This helps you avoid config mistakes.
{
"diagnostics": {
"severity": {
"unused": "hint",
"undefined-field": "information",
"param-type-mismatch": "warning"
},
"disable": ["redundant-return-value"],
"enables": ["missing-return", "return-type-mismatch"]
}
}
Use the interactive settings panel to toggle diagnostics and change severity with checkboxes and dropdowns. You do not need to edit JSON.
Diagnostic reference
Type checking
| Code | Default | Description |
|---|
param-type-mismatch | Warning | Argument type doesn’t match the expected parameter type |
missing-parameter | Warning | Required parameter not provided |
redundant-parameter | Information | Extra argument passed beyond what the function accepts |
assign-type-mismatch | Warning | Assigned value type doesn’t match the variable type |
return-type-mismatch | Off | Return type doesn’t match the declared return type |
missing-return-value | Warning | Function declared to return a value but doesn’t in all paths |
redundant-return-value | Off | Extra return value beyond what the function declares |
missing-return | Off | Function should return a value but doesn’t |
cast-type-mismatch | Warning | Cast type is incompatible with the actual type |
need-check-nil | Hint | Value may be nil; you should check before using it |
unchecked-nil-access | Warning | Chained access or call through an opaque table member that may be nil |
undefined-field | Warning | Field doesn’t exist on the type |
missing-fields | Warning | Table literal is missing required fields |
undefined-global | Error | Referenced variable is not defined globally or locally |
undefined-global-assignment | Warning | Undefined global used as a function argument or assigned to a variable / table field (alias: undefined-global-argument) |
type-not-found | Warning | A referenced type name doesn’t exist |
generic-constraint-mismatch | Information | Generic type argument violates a constraint |
enum-value-mismatch | Warning | Value doesn’t match a known enum entry |
Code quality
| Code | Default | Description |
|---|
unused | Hint | Local variable or function is never used |
unused-self | Off | self parameter is never used in a method |
unreachable-code | Hint | Code after a return or error() cannot execute |
deprecated | Hint | Using a deprecated function or field |
duplicate-require | Hint | Module is require()d more than once in the same scope |
redefined-local | Hint | Local variable shadows an outer local with the same name |
redefined-label | Warning | Code defines the same goto label more than once |
duplicate-index | Warning | Table literal has the same key more than once |
duplicate-set-field | Off | Code assigns a field more than once |
duplicate-type | Off | Code declares the same type name in multiple places |
unbalanced-assignments | Warning | Left-hand and right-hand sides of an assignment have different counts |
local-const-reassign | Error | Code reassigns a <const> local |
read-only | Warning | Code writes to a value declared as read-only |
Documentation
| Code | Default | Description |
|---|
annotation-usage-error | Error | Annotation has wrong syntax or appears in the wrong context |
doc-syntax-error | Error | Annotation comment has a syntax error |
undefined-doc-param | Warning | Documentation names a parameter that the function does not have |
duplicate-doc-field | Warning | @class documents the same field more than once |
incomplete-signature-doc | Off | Function lacks parameter or return documentation |
missing-global-doc | Off | Global function or variable lacks documentation |
unknown-doc-tag | Off | Unknown @tag in an annotation comment |
inject-field | Off | Code adds a field to a type outside its class definition |
Access control
| Code | Default | Description |
|---|
access-invisible | Warning | Accessing a private or protected member outside its class |
discard-returns | Warning | Code ignores the return value from a @nodiscard function |
GMod-specific
| Code | Default | Description |
|---|
gmod-realm-mismatch | Error | Calling a realm-specific function from the wrong realm |
gmod-realm-mismatch-heuristic | Error | Likely realm mismatch based on inferred evidence |
gmod-unknown-realm | Hint | Realm could not be resolved for a realm-aware call |
gmod-invalid-hook-name | Warning | Hook name does not match a recognized GMod hook |
gmod-unknown-net-message | Warning | net.Start(name) uses an unregistered message name |
gmod-net-missing-network-counterpart | Warning | net.Start lacks a matching net.Receive in the expected opposite realm |
gmod-net-read-write-order-mismatch | Warning | net.Read* calls don’t match the order of net.Write* calls |
gmod-net-read-write-type-mismatch | Warning | net.Read* type doesn’t match the corresponding net.Write* |
gmod-net-read-write-bits-mismatch | Warning | Literal bit-width differs between a matched write/read pair |
gmod-duplicate-system-registration | Hint | Duplicate registration (concommand, net, timer, etc.) |
Suppressing individual diagnostics
Use ---@diagnostic annotations to suppress warnings for specific lines or blocks:
-- Suppress for the next line only
---@diagnostic disable-next-line: undefined-global
print(someExternalGlobal)
-- Suppress for the current line
print(x) ---@diagnostic disable-line: undefined-global
-- Suppress for an entire block
---@diagnostic disable: undefined-global
SOME_GLOBAL = "value"
ANOTHER_GLOBAL = 42
---@diagnostic enable: undefined-global
See the @diagnostic annotation reference for full details.
Global whitelist
Add globals that your code uses but GLuaLS does not know about, such as globals from a module loaded by another file:
Use the settings menu instead of editing the JSON file directly. This helps you avoid config mistakes.
{
"diagnostics": {
"globals": ["MyFramework", "PLUGIN_REGISTRY"],
"globalsRegex": ["^LIB_.*"]
}
}