SQL Language Server for OpenCode with Trino/StarRocks dialect support
Project description
opencode-sql-lsp-server
SQL LSP server (stdio) intended for OpenCode, with dialect-aware parsing/formatting.
Install
From PyPI (recommended)
pipx install opencode-sql-lsp-server
From source
Recommended: pipx (or a venv)
pipx install -e .
If you don't have pipx, use a virtualenv or uv tool install.
Or pip:
python3 -m pip install -e .
OpenCode config
opencode.json:
{
"$schema": "https://opencode.ai/config.json",
"lsp": {
"opencode-sql": {
"command": ["opencode-sql-lsp", "--stdio"],
"extensions": [".sql"]
}
}
}
VS Code wrapper extension
This repository now also carries a minimal VS Code wrapper extension under:
extensions/vscode-opencode-sql-lsp-wrapper/
The wrapper is a thin frontend only. It launches the existing Python server with:
opencode-sql-lsp --stdio
Build and package the wrapper locally with:
cd extensions/vscode-opencode-sql-lsp-wrapper
npm install
npm run verify
If opencode-sql-lsp is not on PATH, configure opencodeSql.serverPath in VS Code settings.
Dialect config
Create .opencode/sql-lsp.json in your project:
{
"defaultDialect": "starrocks",
"excludedRules": ["LT05", "ST06"],
"overrides": {
"trino/**/*.sql": "trino"
}
}
Dialect keys are sqlfluff dialect labels, e.g.:
trinostarrocks
Notes
- Diagnostics and formatting are powered by
sqlfluff. - Dialect keys (sqlfluff):
trino,starrocks. - By default, style-only sqlfluff rules
LT05(long lines) andST06(select target ordering) are excluded to avoid noisy diagnostics for practical StarRocks queries. Override with.opencode/sql-lsp.jsonif you want a different policy. - The server also provides lightweight SQL keyword completion, hover help, code actions, and document/workspace symbols for agent-driven editing.
- When
defaultDialectresolves tostarrocks, completion and hover include StarRocks-oriented phrases such asCREATE MATERIALIZED VIEW,CREATE ROUTINE LOAD,CREATE CATALOG,INSERT OVERWRITE,PARTITION BY,DISTRIBUTED BY,UNNEST, andJSON_EACH. - Document/workspace symbols recognize named StarRocks entities like materialized views, routine load jobs, catalogs, and common DDL statements, which makes multi-file agent navigation less blind than line-only statement symbols.
- Formatting and code-action failures degrade safely to empty results and are reported through the server error channel.
Optional performance controls
You can tune large-file lint skipping per workspace:
{
"defaultDialect": "starrocks",
"maxLintLines": 5000,
"maxLintBytes": 200000
}
When a document exceeds either limit, linting is skipped and the server publishes a warning diagnostic instead.
StarRocks-focused coverage
The server is still intentionally lightweight, but it now covers more of the StarRocks workflow surface that matters for agent-driven editing:
- lint/format delegation through
sqlfluffwith StarRocks as the degraded default dialect - false-positive mitigation for
LATERAL UNNEST(...) AS alias(col)andLATERAL JSON_EACH(...) AS alias(k, v)patterns - StarRocks-aware completion/hover entries for materialized views, routine load, catalogs, partitioning/distribution clauses, and table functions
- named document/workspace symbols for
CREATE MATERIALIZED VIEW,CREATE ROUTINE LOAD,CREATE CATALOG,CREATE/ALTER/DROP TABLE, and related statements
This is not a full StarRocks parser or semantic engine. It is a practical LSP layer tuned to be useful for SQL authoring agents without pretending to cover the entire StarRocks product surface.
Verify dialects
sqlfluff dialects
Contributor workflow
Install the editable package with dev dependencies:
python3 -m pip install -e ".[dev]"
Run the local verification gates before opening a PR:
bash scripts/verify_fast.sh
bash scripts/verify_full.sh
Verification ladder
- Fast — default loop for small code changes:
bash scripts/verify_fast.sh
- Targeted — when only one area changed:
- Config/cache work:
python3 -m pytest tests/test_config.py tests/test_workspace_config.py -q - Server behavior work:
python3 -m pytest tests/test_server_behaviors.py tests/test_lsp_helpers.py -q - Diagnostics scheduling work:
python3 -m pytest tests/test_server_behaviors.py tests/test_diagnostics_scheduler.py -q - sqlfluff adapter work:
python3 -m pytest tests/test_sqlfluff_adapter.py -q - Docs/workflow consistency:
python3 -m pytest tests/test_docs_consistency.py -q - Smoke-only:
python3 -m pytest -m smoke -q
- Config/cache work:
- Full — before handoff/PR:
bash scripts/verify_full.sh
- VS Code wrapper — when changing
extensions/vscode-opencode-sql-lsp-wrapper/**:bash scripts/verify_vscode_wrapper.sh
Marker-driven verification lanes
@pytest.mark.config- Owns:
tests/test_config.py,tests/test_workspace_config.py - Use when changing
config.pyorworkspace_config.py
- Owns:
@pytest.mark.server- Owns:
tests/test_server_behaviors.py,tests/test_diagnostics_scheduler.py - Use when changing
server.pyor diagnostics scheduling behavior
- Owns:
@pytest.mark.lsp_helpers- Owns:
tests/test_lsp_helpers.py - Use when changing
lsp_utils.pyorsymbol_provider.py
- Owns:
@pytest.mark.sqlfluff- Owns:
tests/test_sqlfluff_adapter.py - Use when changing
sqlfluff_adapter.py
- Owns:
@pytest.mark.docs- Owns:
tests/test_docs_consistency.py - Use when changing
README.md,src/opencode_sql_lsp_server/AGENTS.md, verification scripts, or.github/workflows/ci.yml
- Owns:
@pytest.mark.smoke- Owns:
tests/test_smoke_stdio.py - Use before handoff when transport or end-to-end behavior may be affected
- Owns:
Multi-agent handoff guide
- Handler changes in
src/opencode_sql_lsp_server/server.py- Also inspect:
src/opencode_sql_lsp_server/lsp_utils.py,src/opencode_sql_lsp_server/symbol_provider.py,src/opencode_sql_lsp_server/diagnostics_scheduler.py - Do not change: CLI transport contract in
cli.py - Verify:
python3 -m pytest tests/test_server_behaviors.py tests/test_lsp_helpers.py tests/test_diagnostics_scheduler.py -q
- Also inspect:
- Dialect/config changes in
src/opencode_sql_lsp_server/config.pyorsrc/opencode_sql_lsp_server/workspace_config.py- Also inspect: workspace-root precedence and cached config fallback behavior
- Do not change: default degraded fallback to
starrocks - Verify:
python3 -m pytest tests/test_config.py tests/test_workspace_config.py -q
- sqlfluff integration changes in
src/opencode_sql_lsp_server/sqlfluff_adapter.py- Do not import
sqlfluffdirectly intoserver.py - Verify:
python3 -m pytest tests/test_sqlfluff_adapter.py tests/test_server_behaviors.py -q
- Do not import
- Diagnostics scheduling changes in
src/opencode_sql_lsp_server/diagnostics_scheduler.py- Also inspect: cancellation/version behavior in
src/opencode_sql_lsp_server/server.py - Do not change: debounce semantics for didOpen/didChange/didSave
- Verify:
python3 -m pytest tests/test_server_behaviors.py tests/test_diagnostics_scheduler.py -q
- Also inspect: cancellation/version behavior in
- Release/build workflow changes in
scripts/or.github/workflows/- Verify:
python3 -m pytest tests/test_docs_consistency.py -q && bash scripts/build_dist.sh
- Verify:
- VS Code wrapper changes in
extensions/vscode-opencode-sql-lsp-wrapper/- Do not change:
pyproject.tomlpackaging boundaries or theopencode-sql-lsp --stdioserver contract - Verify:
bash scripts/verify_vscode_wrapper.sh && bash scripts/verify_fast.sh
- Do not change:
Docs-only changes now take a lighter CI path: .github/workflows/ci.yml always runs quick-validate, but the full matrix job only runs when code-affecting files change. Docs-only changes still run python -m pytest tests/test_docs_consistency.py -q in CI.
The GitHub Actions workflow in .github/workflows/ci.yml runs the same checks on Python 3.10, 3.11, and 3.12.
Release workflow
Build and validate the distribution:
bash scripts/build_dist.sh
Upload to PyPI with a token supplied via environment variable:
export TWINE_USERNAME=__token__
export TWINE_PASSWORD=pypi-***
bash scripts/publish_pypi.sh
If TWINE_PASSWORD is unset and the script is run in an interactive terminal, it will prompt for the token. In CI or other non-interactive environments, the token must be provided via environment variables.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file opencode_sql_lsp_server-0.1.7.tar.gz.
File metadata
- Download URL: opencode_sql_lsp_server-0.1.7.tar.gz
- Upload date:
- Size: 28.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
212a2641dade475de050f49a4fdec3d37c1d1e089570dcab050a488afa90dbe7
|
|
| MD5 |
6ab1659d740f2477045fa5083dbd1d8e
|
|
| BLAKE2b-256 |
f13d8cdca3d6aa19c292e7aaec133bb6b62532f8859158993ed7ca30fa733490
|
File details
Details for the file opencode_sql_lsp_server-0.1.7-py3-none-any.whl.
File metadata
- Download URL: opencode_sql_lsp_server-0.1.7-py3-none-any.whl
- Upload date:
- Size: 20.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
deb49129db60579b5781119e4b41caf710bf0d8aaff2d04ad7ee88f641046f8d
|
|
| MD5 |
39d0d40fd0aff912e4d4157101229259
|
|
| BLAKE2b-256 |
47f4a347097f197281d74b1d0c1ab0c2953f88d777bff34666e67debd21d4ac6
|