srf-lsp/README.md

116 lines
2.6 KiB
Markdown

# srf-lsp
Language Server Protocol implementation for [SRF (Simple Record Format)](https://git.lerch.org/lobo/srf), written in Zig.
Provides real-time parse error diagnostics using the SRF library's parser directly.
## Features
- Parse error diagnostics on open and edit, using the SRF library's parser
directly: missing or duplicate `#!srfv1`, bad type hints, unparseable values,
data after `#!eof`, and so on.
- All errors from a parse are reported, not just the first.
- Position encoding is negotiated during `initialize` (`utf-8`, `utf-16` or
`utf-32`), so columns line up even on lines containing multi-byte characters.
- Full-document sync, which matches SRF's single-pass parser.
- stdio transport.
Not implemented: hover, completion, document symbols, formatting, goto
definition, semantic tokens, and pull diagnostics
(`textDocument/diagnostic`). Requests for them are answered with
`MethodNotFound` rather than left unanswered, and none of them are advertised as
server capabilities.
## Setup
```sh
mise install
```
## Build & Test
```sh
zig build
zig build test
```
The binary is at `zig-out/bin/srf-lsp`.
## Install
The Neovim config below expects `srf-lsp` on `PATH`:
```sh
zig build && install -m755 zig-out/bin/srf-lsp ~/.local/bin/srf-lsp
```
## Neovim Integration
Neovim 0.11 or newer. Add to your config:
```lua
vim.filetype.add({
extension = {
srf = "srf",
},
})
vim.lsp.config("srf_lsp", {
cmd = { "srf-lsp" },
filetypes = { "srf" },
root_markers = { ".git", "/" }, -- single file server
})
vim.lsp.enable("srf_lsp")
```
Check it attached with `:checkhealth vim.lsp` on a `.srf` buffer. Server logs go
to stderr, which Neovim captures in `:LspLog`.
## Combined Setup (with srf-tree-sitter)
For both syntax highlighting and error detection:
```lua
vim.filetype.add({
extension = {
srf = "srf",
},
})
-- Diagnostics
vim.lsp.config("srf_lsp", {
cmd = { "srf-lsp" },
filetypes = { "srf" },
root_markers = { ".git", "/" },
})
vim.lsp.enable("srf_lsp")
-- Syntax highlighting
vim.api.nvim_create_autocmd("User", {
pattern = "TSUpdate",
callback = function()
require("nvim-treesitter.parsers").srf = {
install_info = {
url = "https://github.com/elerch/srf-tree-sitter",
branch = "master",
queries = "queries",
},
}
end,
})
vim.api.nvim_create_autocmd("FileType", {
pattern = "srf",
callback = function(args)
pcall(vim.treesitter.start, args.buf)
end,
})
```
Then install the tree-sitter parser (`:TSInstall srf` no-ops if it is already
present, so use `:TSUpdate srf` to pick up a newer grammar):
```vim
:TSUpdate srf
```