-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
base: master
Are you sure you want to change the base?
Conversation
00ccfee
to
fc7a459
Compare
fc7a459
to
b39376c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this example should be located under lib/lsp-server/examples/
like the previous one
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for catching that! You’re absolutely right—I’ve now moved the example into lib/lsp-server/examples/ alongside goto_def.rs. The file is renamed to completion_and_formatting.rs, and I’ve updated the crates/lsp-server/Cargo.toml manifest accordingly. Let me know if you spot anything else!
Well, I think that the original intention of the OP in #20017 is asking opinions about adding their existing
Besides that, I think this example is not that "richer" than existing |
Yeah, I think a single example would be better. |
- Move the completion/formatting example from crates/rust-analyzer/examples/ to crates/lsp-server/examples/ - Rename file to completion_and_formatting.rs to match snake_case and clearly indicate both features - Add anyhow = "1.0" under [dev-dependencies] in crates/lsp-server/Cargo.toml so the example compiles without error
Thank you so much for raising these points—I really appreciate your insight! 🙏 As for the filename, would you be comfortable with completion_and_formatting.rs? It follows our snake_case style and clearly indicates the two features it covers, sitting neatly beside goto_def.rs. If you’d prefer a different name or any other tweaks, I’m more than happy to update—just let me know what you’d like! |
Thank you again for all your feedback! 🙏 At this point, would you prefer that I close this PR, or is there anything else you’d like me to adjust before we merge it? Please let me know what you’d recommend, and I’ll act accordingly. |
@lnicola and I pondered upon this and we think in current status, this would be best to be merged into existing I'll comment on some details though if you take the "merging" suggestion most of them wouldn't be needed 😅 |
|
||
[[example]] | ||
name = "completion_and_formatting" | ||
path = "examples/completion_and_formatting.rs" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need this because the new example code is located inside examples/
//! rust-analyzer LSP example | ||
//! | ||
//! A minimal Language Server Protocol server demonstrating how to embed | ||
//! `rust-analyzer` as a library. To run it: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"embed rust-analyzer
" is not a right term here. This lsp-server
is just a crate that rust-analyzer dogfoods on to handle lsp requests and responses.
So, the examples are not for rust-analyer or embedding. They just show how to use this "library"
Summary
Adds a new “head-start” LSP server example inside
crates/lsp-server/examples/
. This fresh example shows how to:textDocument/didChange
)Details
Setup
Message Loop
didChange
URI{"isIncomplete":false,"items":[]}
[]
This minimal template makes it easy to embed rust-analyzer as an LSP server with basic completion and formatting hooks.
Testing & Validation