# Language server tools

Three tools ask a language server what a type checker knows about the working tree as it stands, without running tests.

| Tool | Arguments | Answers |
| --- | --- | --- |
| `lsp_diagnostics` | `file` | Errors and warnings for that file |
| `lsp_references` | `file`, `line`, `column` | Every use of the symbol at that position |
| `lsp_definition` | `file`, `line`, `column` | Where that symbol is declared |

`file` is absolute. `line` and `column` are 1-based, as `read` and tracebacks show, and must point at the symbol itself. Long results stop at 50 entries with a count of the rest; narrow the question.

```
runner.py: 2 diagnostics
14:5 warning: "requests" is not accessed [pyright]
27:12 error: "widget" is not defined [pyright]
```

```
3 references
openprogram/runtime/agent/loop/loop.py:88:9   result = dispatch(call)
openprogram/runtime/agent/loop/loop.py:140:5  dispatch(retry)
tests/unit/test_loop.py:31:11    monkeypatch.setattr(loop, "dispatch", fake)
```

`lsp_definition` has the same `path:line:column` form. Paths are relative to the workspace root.

## Install a server

| Language | Extensions | Binary | Install |
| --- | --- | --- | --- |
| Python | `.py`, `.pyi` | `pyright-langserver` | `npm install -g pyright` |
| TypeScript / JavaScript | `.ts`, `.tsx`, `.js`, `.jsx`, `.mts`, `.cts` | `typescript-language-server` | `npm install -g typescript-language-server typescript` |

The tools are always registered. Without a server they answer `unavailable: install …` with the command. Other extensions get a result saying so.

## How servers run

- One server per language per workspace. The workspace is the nearest ancestor holding `pyproject.toml`, `setup.py`, `package.json`, `tsconfig.json` or `.git`.
- Starts on first use, stays cached for the process, shuts down when OpenProgram exits.
- The configured [sandbox](https://fzkuji.github.io/OpenProgram/docs/reference/design/runtime/security/sandbox-architecture.html) applies. `sandbox.mode` defaults to `off`, so a server is unconfined unless a conversation turns Sandbox on. Under `workspace-write`, it reads the workspace and writes nothing outside it.

## Compared to grep and CodeGraph

| Tool | Finds | Misses or adds |
| --- | --- | --- |
| `grep` | Text | Reports same-named strings in comments; misses calls through an alias |
| `lsp_references` | Resolved symbols | Neither mistake |
| CodeGraph | Pre-built index of a whole codebase, best for reading unfamiliar code top down | Language servers add live diagnostics against the file on disk |
