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

Conversation

shashforge
Copy link
Contributor

@shashforge shashforge 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.

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

This comment has been minimized.

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

This comment has been minimized.

@shashforge shashforge 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
@shashforge shashforge force-pushed the lsp-minimal-example-clean branch from 2e5a50b to 31e2f81 Compare July 12, 2025 21:16
@rustbot

This comment has been minimized.

@shashforge shashforge force-pushed the lsp-minimal-example-clean branch 7 times, most recently from b1d8293 to f11d8da Compare July 12, 2025 22:09
@shashforge
Copy link
Contributor Author

shashforge 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

@ShoyuVanilla
Copy link
Member

ShoyuVanilla commented Jul 14, 2025

Thanks! I'll take a look before not too late 😅

@ShoyuVanilla
Copy link
Member

Overally looks good but some nits and a question:

@shashforge shashforge force-pushed the lsp-minimal-example-clean branch from f11d8da to d60ca00 Compare July 16, 2025 22:09
@shashforge
Copy link
Contributor Author

Hi @ShoyuVanilla

Thanks so much for the careful review!

  1. Header tidy-up – I removed the SPDX line and the banner underline.
  2. goto_def.rs mention – dropped, since that file is gone now.
  3. manual_test.sh – added a short note that the FIFO only feeds stdin, so the code path is the same as a direct pipe.

Ran cargo fmt; the example builds and clippy is clean.

If the extra script still feels like overkill, I’m happy to delete it and rely on the one-liner here-doc instead—just say the word.

Really appreciate your time and feedback. Let me know if there’s anything else you’d like tweaked!

@shashforge shashforge requested a review from ShoyuVanilla July 16, 2025 22:28
@shashforge shashforge force-pushed the lsp-minimal-example-clean branch 2 times, most recently from ed08b10 to 7e224c2 Compare July 17, 2025 08:55
* `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].
@shashforge shashforge force-pushed the lsp-minimal-example-clean branch from 7e224c2 to 4541495 Compare July 17, 2025 09:04
@shashforge shashforge requested a review from ShoyuVanilla July 17, 2025 09:05
Copy link
Member

@ShoyuVanilla ShoyuVanilla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Sorry for being too picky on this PR. As this is adding an example that serves as a documentation for newcomers, I had to be sensitive on accuracy 😅

@ShoyuVanilla ShoyuVanilla enabled auto-merge July 17, 2025 09:07
@shashforge
Copy link
Contributor Author

Thanks! Sorry for being too picky on this PR. As this is adding an example that serves as a documentation for newcomers, I had to be sensitive on accuracy 😅

Absolutely, and thanks again for the careful review — it only makes the example stronger.

If there are other bite-sized issues or examples that could use a fresh set of eyes, I’d be happy to tackle them next. I’m already browsing the issue tracker, but please feel free to point me toward anything you think would be especially helpful for the project. I’m keen to contribute wherever it adds the most value.

@ShoyuVanilla ShoyuVanilla added this pull request to the merge queue Jul 17, 2025
Merged via the queue into rust-lang:master with commit f73ce3c Jul 17, 2025
15 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Adding a new LSP server example
3 participants