Skip to content

Commit 2e5a50b

Browse files
committed
examples: add minimal_lsp.rs and FIFO test script (#20017)
* `examples/minimal_lsp.rs` – compact LSP server showing definition, completion, hover, rustfmt-based formatting, and dummy diagnostics. Advertises UTF-8 offset encoding. * `examples/manual_test.sh` – FIFO script that streams the canonical nine LSP packets so anyone can validate the server from two terminals. No new runtime deps; `anyhow` stays under [dev-dependencies].
1 parent a489123 commit 2e5a50b

File tree

4 files changed

+324
-132
lines changed

4 files changed

+324
-132
lines changed

lib/lsp-server/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ crossbeam-channel.workspace = true
1616
[dev-dependencies]
1717
lsp-types = "=0.95"
1818
ctrlc = "3.4.7"
19+
anyhow = "1.0.98"
1920

2021
[lints]
2122
workspace = true

lib/lsp-server/examples/goto_def.rs

Lines changed: 0 additions & 132 deletions
This file was deleted.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env bash
2+
# Simple nine-packet LSP test for examples/minimal_lsp.rs
3+
# Usage: bash examples/manual_test.sh # defaults to /tmp/lsp_pipe
4+
# bash examples/manual_test.sh mypipe # custom fifo name
5+
6+
set -eu
7+
PIPE=${1:-/tmp/lsp_pipe}
8+
9+
mkfifo -m 600 "$PIPE" 2>/dev/null || true # create once, ignore if exists
10+
11+
# open write end so the fifo stays open
12+
exec 3> "$PIPE"
13+
14+
send() {
15+
local body=$1
16+
local len=$(printf '%s' "$body" | wc -c)
17+
printf 'Content-Length: %d\r\n\r\n%s' "$len" "$body" >&3
18+
}
19+
20+
send '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"capabilities":{}}}'
21+
send '{"jsonrpc":"2.0","method":"initialized","params":{}}'
22+
send '{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"file:///tmp/foo.rs","languageId":"rust","version":1,"text":"fn main( ){println!(\"hi\") }"}}}'
23+
send '{"jsonrpc":"2.0","id":2,"method":"textDocument/completion","params":{"textDocument":{"uri":"file:///tmp/foo.rs"},"position":{"line":0,"character":0}}}'
24+
send '{"jsonrpc":"2.0","id":3,"method":"textDocument/hover","params":{"textDocument":{"uri":"file:///tmp/foo.rs"},"position":{"line":0,"character":0}}}'
25+
send '{"jsonrpc":"2.0","id":4,"method":"textDocument/definition","params":{"textDocument":{"uri":"file:///tmp/foo.rs"},"position":{"line":0,"character":0}}}'
26+
send '{"jsonrpc":"2.0","id":5,"method":"textDocument/formatting","params":{"textDocument":{"uri":"file:///tmp/foo.rs"},"options":{"tabSize":4,"insertSpaces":true}}}'
27+
send '{"jsonrpc":"2.0","id":6,"method":"shutdown","params":null}'
28+
send '{"jsonrpc":"2.0","method":"exit","params":null}'
29+
30+
exec 3>&-
31+
echo "Packets sent – watch the other terminal for responses."

0 commit comments

Comments
 (0)