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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

shashi1687
Copy link

@shashi1687 shashi1687 commented Jul 12, 2025

Adds a single example, examples/minimal_lsp.rs, plus a tiny FIFO test script.
The sample now shows:

- completion textDocument/completion
- hover textDocument/hover
- goto-definition textDocument/definition
- full-doc formatting (rustfmt) textDocument/formatting
- dummy diagnostics textDocument/publishDiagnostics
- UTF-8 offsetEncoding in the initialize response

Quick test

one-shot, all nine packets

cargo build --example minimal_lsp
target/debug/examples/minimal_lsp < examples/nine_packets.txt

Also includes examples/manual_test.sh, a tiny FIFO script that sends the canonical 9 LSP packets so the server can be verified from two terminals.

Two-terminal test

mkfifo /tmp/lsp_pipe
terminal A
cat /tmp/lsp_pipe | cargo run --example minimal_lsp
terminal B
bash examples/manual_test.sh # pumps the same nine packets

We should see, in order: capabilities → diagnostics → completion → hover → definition → formatting → shutdown.
(anyhow stays under [dev-dependencies]).

Fixes #20017

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 12, 2025
@rustbot

This comment has been minimized.

@shashi1687 shashi1687 force-pushed the lsp-minimal-example-clean branch from 4cec573 to 7f7f6a2 Compare July 12, 2025 18:49
@rustbot

This comment has been minimized.

@shashi1687 shashi1687 force-pushed the lsp-minimal-example-clean branch from 7f7f6a2 to 2e5a50b Compare July 12, 2025 21:09
@rustbot

This comment has been minimized.

@shashi1687 shashi1687 changed the title examples: add minimal_lsp.rs and FIFO test script (#20017) examples: add minimal_lsp.rs and FIFO test script Jul 12, 2025
@shashi1687 shashi1687 force-pushed the lsp-minimal-example-clean branch from 2e5a50b to 31e2f81 Compare July 12, 2025 21:16
@rustbot

This comment has been minimized.

@shashi1687 shashi1687 force-pushed the lsp-minimal-example-clean branch 6 times, most recently from e906c23 to b1d8293 Compare July 12, 2025 22:05
* `examples/minimal_lsp.rs` – compact LSP server showing definition,
  completion, hover, rustfmt-based formatting, and dummy diagnostics.
  Advertises UTF-8 offset encoding.

* `examples/manual_test.sh` – FIFO script that streams the canonical
  nine LSP packets so anyone can validate the server from two terminals.

No new runtime deps; `anyhow` stays under [dev-dependencies].
@shashi1687 shashi1687 force-pushed the lsp-minimal-example-clean branch from b1d8293 to f11d8da Compare July 12, 2025 22:09
@shashi1687
Copy link
Author

shashi1687 commented Jul 12, 2025

Hi @ShoyuVanilla @lnicola ,

Thank you for the helpful guidance on my last attempt on #20187
As you suggested, I’ve folded the logic from goto_def.rs and my earlier demo into a single file, examples/minimal_lsp.rs.
The new example now covers

  • completion
  • hover
  • goto-definition
  • full-file formatting via rustfmt
  • a dummy diagnostic push
  • UTF-8 offsetEncoding in the initialize

I’ve also added a tiny FIFO helper (examples/manual_test.sh) to replay the nine canonical packets, so the whole round-trip can be tested in two terminals.
Whenever you have a moment, I’d really appreciate another look.
Thanks again for your time and feedback!

— Shashi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Adding a new LSP server example
2 participants