# BSL Language Server

Production-quality BSL diagnostics via [BSL Language Server](https://github.com/1c-syntax/bsl-language-server).

## Prerequisites

- Java 17+ on the gateway host
- Exported EDT/Designer project or git checkout with `.bsl` files

## Install on Linux (production)

```bash
sudo bash deploy/prod/install-bsl-ls.sh
```

The script downloads the latest release JAR to `/opt/bsl-language-server/` and prints the env line for `/etc/onec-mcp-gateway/env`:

```bash
ONEC_BSL_LS_PATH=/opt/bsl-language-server/bsl-language-server.jar
```

Restart gateway after updating env:

```bash
sudo systemctl restart onec-mcp-gateway
```

## Manual install

1. Download `bsl-language-server-*-exec.jar` from GitHub releases.
2. Set `ONEC_BSL_LS_PATH` to the JAR path or a wrapper script.
3. Optional: `ONEC_BSL_LS_JAVA=java` if Java is not on default PATH.

## Verify

MCP tools `bsl_run_diagnostics` and `code.run_bsl_checks` use the adapter:

- With LS: real diagnostics from language server
- Without LS: heuristic fallback (unbalanced procedures, basic syntax)

```bash
curl -sS https://mwi.yatsuk.pro/readyz
# Check gateway logs after calling bsl_run_diagnostics
journalctl -u onec-mcp-gateway -n 50 --no-pager
```

## Security

- LS runs locally on the gateway host; it reads files only from paths supplied by authorized MCP callers.
- Keep `ONEC_PRODUCTION=1` and restrict write tools in production profiles.

## Navigation vs diagnostics

BSL Language Server is used for **diagnostics** and **LSP navigation**:

- `bsl_run_diagnostics`, `run_bsl_checks` — analyze reporter
- `bsl_go_to_definition`, `bsl_find_references` — LSP `textDocument/definition` / `references` with heuristic fallback when `ONEC_BSL_LS_DISABLE=1`

Native indexed navigation remains available offline; LSP improves accuracy when the JAR is installed.

## Related

- [EDT_DESIGNER_EXPORT.md](./EDT_DESIGNER_EXPORT.md)
- [AGENT_RESULT_LOOP.md](./AGENT_RESULT_LOOP.md)
- [TROUBLESHOOTING.md](./TROUBLESHOOTING.md)
