Skip to content

Commit f73ce3c

Browse files
authored
Merge pull request #20233 from shashforge/lsp-minimal-example-clean
examples: add `minimal_lsp.rs` and FIFO test script
2 parents 1520876 + 4541495 commit f73ce3c

File tree

4 files changed

+391
-132
lines changed

4 files changed

+391
-132
lines changed

lib/lsp-server/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ crossbeam-channel.workspace = true
1616
[dev-dependencies]
1717
lsp-types = "=0.95"
1818
ctrlc = "3.4.7"
19+
anyhow.workspace = true
20+
rustc-hash.workspace = true
21+
toolchain.workspace = true
1922

2023
[lints]
2124
workspace = true

lib/lsp-server/examples/goto_def.rs

Lines changed: 0 additions & 132 deletions
This file was deleted.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env bash
2+
# Simple nine-packet LSP test for examples/minimal_lsp.rs
3+
# Usage (two tabs):
4+
#
5+
# mkfifo /tmp/lsp_pipe # one-time setup
6+
# # tab 1 – run the server
7+
# cat /tmp/lsp_pipe | cargo run --example minimal_lsp
8+
#
9+
# # tab 2 – fire the packets (this script)
10+
# bash examples/manual_test.sh # blocks until server exits
11+
#
12+
# If you don’t use a second tab, run the script in the background:
13+
#
14+
# bash examples/manual_test.sh & # writer in background
15+
# cat /tmp/lsp_pipe | cargo run --example minimal_lsp
16+
#
17+
# The script opens /tmp/lsp_pipe for writing (exec 3>) and sends each JSON
18+
# packet with a correct Content-Length header.
19+
#
20+
# One-liner alternative (single terminal, no FIFO):
21+
#
22+
# cargo run --example minimal_lsp <<'EOF'
23+
# … nine packets …
24+
# EOF
25+
#
26+
# Both approaches feed identical bytes to minimal_lsp via stdin.
27+
28+
set -eu
29+
PIPE=${1:-/tmp/lsp_pipe}
30+
31+
mkfifo -m 600 "$PIPE" 2>/dev/null || true # create once, ignore if exists
32+
33+
# open write end so the fifo stays open
34+
exec 3> "$PIPE"
35+
36+
send() {
37+
local body=$1
38+
local len=$(printf '%s' "$body" | wc -c)
39+
printf 'Content-Length: %d\r\n\r\n%s' "$len" "$body" >&3
40+
}
41+
42+
send '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"capabilities":{}}}'
43+
send '{"jsonrpc":"2.0","method":"initialized","params":{}}'
44+
send '{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"file:///tmp/foo.rs","languageId":"rust","version":1,"text":"fn main( ){println!(\"hi\") }"}}}'
45+
send '{"jsonrpc":"2.0","id":2,"method":"textDocument/completion","params":{"textDocument":{"uri":"file:///tmp/foo.rs"},"position":{"line":0,"character":0}}}'
46+
send '{"jsonrpc":"2.0","id":3,"method":"textDocument/hover","params":{"textDocument":{"uri":"file:///tmp/foo.rs"},"position":{"line":0,"character":0}}}'
47+
send '{"jsonrpc":"2.0","id":4,"method":"textDocument/definition","params":{"textDocument":{"uri":"file:///tmp/foo.rs"},"position":{"line":0,"character":0}}}'
48+
send '{"jsonrpc":"2.0","id":5,"method":"textDocument/formatting","params":{"textDocument":{"uri":"file:///tmp/foo.rs"},"options":{"tabSize":4,"insertSpaces":true}}}'
49+
send '{"jsonrpc":"2.0","id":6,"method":"shutdown","params":null}'
50+
send '{"jsonrpc":"2.0","method":"exit","params":null}'
51+
52+
exec 3>&-
53+
echo "Packets sent – watch the other terminal for responses."

0 commit comments

Comments
 (0)