ebkalderon / tower-lsp

Language Server Protocol implementation written in Rust
Apache License 2.0
1k stars 55 forks source link

Add lines about server capabilities on example #304

Closed tsukimizake closed 2 years ago

tsukimizake commented 2 years ago

Hi. I tried to make a mock lsp server following the example in https://github.com/ebkalderon/tower-lsp/blob/4cf39815e7e9e82c96bb267144f17e7b25415db3/src/lib.rs , but its hover and completion didn't work at first.

I tried to update the capabilities in the initialize function, and it works.

    async fn initialize(&self, _: InitializeParams) -> Result<InitializeResult> {
        let mut res = InitializeResult::default();
        res.capabilities.hover_provider = Some(HoverProviderCapability::Simple(true));
        res.capabilities.completion_provider = Some(CompletionOptions::default());
        Ok(res)
    }

Seems like the doc should be updated? (Perhaps also the example on README.md?)

My environment is macOS catalina10.15.7 neovim v0.6.1 lsp client is nvim-lspconfig

tsukimizake commented 2 years ago

Seems like I should have investigated https://github.com/ebkalderon/tower-lsp/blob/master/examples/stdio.rs at first hand...

ebkalderon commented 2 years ago

No, that's a perfectly valid point! The rustdoc example code was intentionally made simplistic to avoid taking up too much vertical space in docs.rs, drawing attention away from the actual documentation. But it is indeed misleading, so I agree it should be updated.

Perhaps something like this?

async fn initialize(&self, _: InitializeParams) -> Result<InitializeResult> {
    Ok(InitializeResult {
        hover_provider: Some(HoverProviderCapability::Simple(true)),
        completion_provider: Some(CompletionOptions::default()),
        ..Default::default()
    })
}

I'd be happy to accept a pull request, if you're down for it!