-
Notifications
You must be signed in to change notification settings - Fork 16
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
Migrate to LSP #7
Comments
I think the |
I'd like to quickly show // this is shared data for handlers e.g. config. It must be thread safe
pub struct MyLanguageServer { client: Client /* other fields can go here */ } The #[tower_lsp::async_trait]
impl LanguageServer for MyLanguageServer {
// `InitializeParams` includes client-side configs among other things.
// The crate passes immutable refs, so working with `self` is inconvenient, because it requires
// thread-safe (`Sync`) interior mutability. Both `tokio` and the `once_cell` crate have a `OnceCell`
// which I find make it easier. I prefer the latter because of its cleaner interface.
async fn initialize(&self, params: InitializeParams) -> Result<InitializeResult> {
Ok(InitializeResult::default())
}
// called upon requesting graceful shut down. This is different from process exit.
async fn shutdown(&self) -> Result<()> { Ok(()) }
// LSP events are modeled as functions on this trait, which makes implementing them straightforward,
// but all references are immutable so they have have the same inconveniences as `initialize`
async fn did_open(&self, params: DidOpenTextDocumentParams) {}
} This is how to start the server let rt = tokio::runtime::Runtime::new().unwrap();
rt.block_on(async {
let stdin = tokio::io::stdin();
let stdout = tokio::io::stdout();
let (service, socket) = LspService::new(MyLanguageServer::new); // MyLanguageServer::new(Client) -> Self
Server::new(stdin, stdout, socket).serve(service).await;
}) |
@PolyMeilex Would you be open to a PR migrating the current functionality of |
Sure, as long as we have vscode PR for that as well, my implementation got stuck on that as far as I remember, as I was too lazy to port the extension 😄 I did not see the need for tower-lsp when doing my impl, but if that makes your life or code simpler, then sure feel free to go ahead with that. |
|
Considering that the vsc extension might need a significant rewrite, it might be a good idea to "move" it into this repo as well. Might make versioning and updating easier. |
We should probably migrate the server to LSP, so we can support more editors instead of being vs-code specific.
Potentially useful crates:
Notes:
The text was updated successfully, but these errors were encountered: