Skip to content

Commit 1fdfe8e

Browse files
committed
examples: merge demos into minimal_lsp.rs and add test script
* Folded completion / formatting example into one file. * Covers definition, completion, hover, formatting, diagnostics, UTF-8 offsets. * Added examples/manual_test.sh for a reproducible nine-packet FIFO test.
1 parent cba35f6 commit 1fdfe8e

File tree

5 files changed

+374
-203
lines changed

5 files changed

+374
-203
lines changed

lib/lsp-server/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ 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
2223

2324
[[example]]
24-
name = "completion_and_formatting"
25-
path = "examples/completion_and_formatting.rs"
25+
name = "minimal_lsp"
26+
path = "examples/minimal_lsp.rs"

lib/lsp-server/examples/completion_and_formatting.rs

Lines changed: 0 additions & 69 deletions
This file was deleted.

lib/lsp-server/examples/goto_def.rs

Lines changed: 0 additions & 132 deletions
This file was deleted.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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."
32+

0 commit comments

Comments
 (0)