> ## Documentation Index
> Fetch the complete documentation index at: https://glua.bluejutzu.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# IntelliSense and Type Tracking for GLua

> GLua Language Server tracks types through calls, string literals, loops, and metatables so completion always resolves to the right class.

GLua Language Server uses a combination of static analysis and the bundled Garry's Mod wiki dataset to provide precise IntelliSense across your entire workspace. It tracks types through function calls, string literals, loops, and metatables so that completion and hover information always resolve to the correct class.

## Type tracking

The server understands how common GLua functions transform types and propagates that knowledge through your code.

### Player lookup

When you call `player.GetByID`, the server knows the result is a `Player` entity:

```lua theme={null}
local ply = player.GetByID(1)
ply:Kick("Reason") -- completion offers Player methods
```

### Panel creation

`vgui.Create` with a known panel class returns that type:

```lua theme={null}
local frame = vgui.Create("DFrame")
frame:SetTitle("Hello") -- completion offers DFrame methods
```

### Loop iteration

`ipairs` over a player list types each element as `Player`:

```lua theme={null}
for _, ply in ipairs(player.GetAll()) do
    ply:ChatPrint("Hello") -- ply is typed as Player
end
```

### Typed hook sender

When you register a hook with a typed sender parameter, the callback receives the correct type:

```lua theme={null}
hook.Add("PlayerSay", "MyAddon", function(sender, text, teamChat)
    sender:Kick("Spam") -- sender is typed as Player
end)
```

### Entity methods

Inside `ENT` methods, `self` is typed as `Entity`:

```lua theme={null}
function ENT:Initialize()
    self:SetModel("models/props_c17/oildrum001.mdl") -- self is Entity
end
```

## Typing your own functions

You can add explicit types to your own functions with annotations, or let the server infer them from usage.

<CodeGroup>
  ```lua Annotated theme={null}
  ---@param target Player
  ---@param message string
  ---@return boolean
  function NotifyPlayer(target, message)
      target:ChatPrint(message)
      return true
  end
  ```

  ```lua Inferred theme={null}
  function NotifyPlayer(target, message)
      target:ChatPrint(message) -- target inferred as Player from ChatPrint call
      return true               -- return type inferred as boolean
  end
  ```
</CodeGroup>

## Supported annotation tags

GLua Language Server uses the same annotation dialect as Lua Language Server.

| Tag              | Purpose                | Example                              |
| ---------------- | ---------------------- | ------------------------------------ |
| `---@param`      | Declare parameter type | `---@param ply Player`               |
| `---@return`     | Declare return type    | `---@return boolean`                 |
| `---@type`       | Cast an expression     | `---@type Player`                    |
| `---@class`      | Define a custom class  | `---@class MyPanel : DPanel`         |
| `---@field`      | Add a field to a class | `---@field Name string`              |
| `---@deprecated` | Mark as deprecated     | `---@deprecated Use NewFunc instead` |

You can also use union types, optional parameters, and array syntax:

```lua theme={null}
---@param items (string|number)[]
---@param options? table
---@return string|nil
```

## How inference falls back

When the server cannot determine an exact type, it uses the following strategy:

1. **Ambiguous sets** — If an object could be one of several types, the server finds the most specific common base class. For example, a value that is sometimes a `Player` and sometimes an `NPC` falls back to `Entity`.
2. **Unrecognisable values** — If a type cannot be inferred at all, it falls back to `any`. You will still get generic Lua completions, but no Garry's Mod specific methods.
3. **Explicit annotations always win** — If you add a `---@type` or `---@param` annotation, it overrides any inferred type.

<Tip>
  Add explicit annotations at module boundaries (shared files called from multiple realms, library functions used by other addons) to improve completion accuracy across your entire workspace.
</Tip>


## Related topics

- [GLua Language Server: GMod Lua IDE Support](/index.md)
- [Committed Config Files for GLua](/configuration/config-files.md)
- [Get Started with GLua Language Server](/quickstart.md)
- [GLua Annotation Reference](/reference/annotations.md)
