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