|
| 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