Skip to content

Add richer LSP server example (#20017) #20187

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

What this PR does

This adds a new “head-start” LSP server example under:
crates/rust-analyzer/examples/rust_analyzer_lsp_example/
It demonstrates how to:

  • Capture document edits with textDocument/didChange and log the URI
  • Stub out textDocument/completion (returns an empty list)
  • Stub out textDocument/formatting (returns no edits)

What the example does

  1. Initialization
    • Opens JSON-RPC over stdio
    • Advertises full text sync, a completion provider, and a formatting provider
  2. Main loop
    • Logs every buffer change (didChange)
    • Replies to completion requests with {"isIncomplete":false,"items":[]}
    • Replies to formatting requests with []
    • Handles clean shutdown on shutdown/exit

This gives anyone embedding rust-analyzer a minimal “plug-in” template for completions and formatting.

About the author’s note

“The current LSP example is a good, minimal demonstration. It shows how to respond to textDocument/definition. I used it to make an example that includes capturing content from textDocument/didChange and using it to provide textDocument/completion and textDocument/formatting functionality…”

  • We’ve taken that idea and upstreamed it as a fresh, in-tree example.
  • No external code was copied verbatim—just a clean re-implementation.

Testing & Validation

  1. Build
    cargo build -p rust-analyzer --example rust_analyzer_lsp_example

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 6, 2025
@shashi1687 shashi1687 force-pushed the add-lsp-server-example branch 2 times, most recently from 00ccfee to fc7a459 Compare July 6, 2025 16:39
@shashi1687 shashi1687 force-pushed the add-lsp-server-example branch from fc7a459 to b39376c Compare July 6, 2025 17:02
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.

2 participants