Skip to content

examples: add minimal_lsp.rs and FIFO test script #20233

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/lsp-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ crossbeam-channel.workspace = true
[dev-dependencies]
lsp-types = "=0.95"
ctrlc = "3.4.7"
anyhow.workspace = true
rustc-hash.workspace = true
toolchain.workspace = true

[lints]
workspace = true
132 changes: 0 additions & 132 deletions lib/lsp-server/examples/goto_def.rs

This file was deleted.

53 changes: 53 additions & 0 deletions lib/lsp-server/examples/manual_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env bash
# Simple nine-packet LSP test for examples/minimal_lsp.rs
# Usage (two tabs):
#
# mkfifo /tmp/lsp_pipe # one-time setup
# # tab 1 – run the server
# cat /tmp/lsp_pipe | cargo run --example minimal_lsp
#
# # tab 2 – fire the packets (this script)
# bash examples/manual_test.sh # blocks until server exits
#
# If you don’t use a second tab, run the script in the background:
#
# bash examples/manual_test.sh & # writer in background
# cat /tmp/lsp_pipe | cargo run --example minimal_lsp
#
# The script opens /tmp/lsp_pipe for writing (exec 3>) and sends each JSON
# packet with a correct Content-Length header.
#
# One-liner alternative (single terminal, no FIFO):
#
# cargo run --example minimal_lsp <<'EOF'
# … nine packets …
# EOF
#
# Both approaches feed identical bytes to minimal_lsp via stdin.

set -eu
PIPE=${1:-/tmp/lsp_pipe}

mkfifo -m 600 "$PIPE" 2>/dev/null || true # create once, ignore if exists

# open write end so the fifo stays open
exec 3> "$PIPE"

send() {
local body=$1
local len=$(printf '%s' "$body" | wc -c)
printf 'Content-Length: %d\r\n\r\n%s' "$len" "$body" >&3
}

send '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"capabilities":{}}}'
send '{"jsonrpc":"2.0","method":"initialized","params":{}}'
send '{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"file:///tmp/foo.rs","languageId":"rust","version":1,"text":"fn main( ){println!(\"hi\") }"}}}'
send '{"jsonrpc":"2.0","id":2,"method":"textDocument/completion","params":{"textDocument":{"uri":"file:///tmp/foo.rs"},"position":{"line":0,"character":0}}}'
send '{"jsonrpc":"2.0","id":3,"method":"textDocument/hover","params":{"textDocument":{"uri":"file:///tmp/foo.rs"},"position":{"line":0,"character":0}}}'
send '{"jsonrpc":"2.0","id":4,"method":"textDocument/definition","params":{"textDocument":{"uri":"file:///tmp/foo.rs"},"position":{"line":0,"character":0}}}'
send '{"jsonrpc":"2.0","id":5,"method":"textDocument/formatting","params":{"textDocument":{"uri":"file:///tmp/foo.rs"},"options":{"tabSize":4,"insertSpaces":true}}}'
send '{"jsonrpc":"2.0","id":6,"method":"shutdown","params":null}'
send '{"jsonrpc":"2.0","method":"exit","params":null}'

exec 3>&-
echo "Packets sent – watch the other terminal for responses."
Loading
Loading