Skip to content
This repository has been archived by the owner on Nov 18, 2022. It is now read-only.

Use ImplementationProvider API #288

Closed
jrieken opened this issue Mar 28, 2018 · 6 comments
Closed

Use ImplementationProvider API #288

jrieken opened this issue Mar 28, 2018 · 6 comments

Comments

@jrieken
Copy link

jrieken commented Mar 28, 2018

This extension comes with a command that find implementations for traits, structs, and enums. That's pretty cool but even cooler would be if the ImplementationProvider-api would be used. That gives a nicer integration and prevents double commands as shown below:

screen shot 2018-03-28 at 15 43 28

The implementation should be straight forward and is more or less swapping the command with a provider here. Error handling, showing results in peek or jumping to the first implementation then comes for free.

Something like this:

const findImplsDisposable = languages.registerImplementationProvider('rust', {
  provideImplementation(doc, pos, token) {
    const params = lc.code2ProtocolConverter.asTextDocumentPositionParams(doc, pos);
    return await lc.sendRequest<Location[]>('rustDocument/implementations', params);
  }
});
@jrieken
Copy link
Author

jrieken commented Mar 28, 2018

Alternatively, albeit a bigger change, you can implement the implementation-provider logic in the LSP, not the client. Then all editor will benefit from this.

@egamma
Copy link

egamma commented Mar 28, 2018

FYI @jonathandturner

@chuck-flowers
Copy link
Contributor

Hi I'm looking to get started contributing to the Rust community, specifically with regards to improving the tools I'm currently using to develop Rust. This seems like an easy enough issue for me to start on. Hopefully I'll get it taken care of this week. Just wanted to stake my claim on it so that two people aren't working on it at the same time.

@chuck-flowers
Copy link
Contributor

I swapped out the API calls but I can't seem to get it to work on any of my projects. Up until now I haven't used this feature of the extension. Can someone give a simple example of the rust code this feature should work on and the expected results?

My understanding is that in the below example when Go To Implementation is called on Foo it should jump to the impl Display block

struct Foo {
    bar: i32
}

impl Display for Foo {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
        ...
    }
}

@Xanewok
Copy link
Member

Xanewok commented Jul 21, 2018

@chuck-flowers hey, great to see more people involved!

However, the timing is (un?)fortunate, since we moved to LSP 3.6 textDocument/implementation message (instead of using our custom) just a few days ago with rust-lang/rls#936 and #369; since we use vscode-languageserver-node as our VSCode LSP client, on receiving appropriate server capability from the server, the underlying client automatically registers an implementation provider and the feature works as expected (e.g. when selected from the Command Pallete).

I've tagged few more issues with good-first-issue label - might I suggest looking at few of these instead? Some are going to be easier than others - I'll try and help get you started if you want to work on any of these!

In the meantime, closing this since it's implemented and new version containing the fix should be published now.

@Xanewok Xanewok closed this as completed Jul 21, 2018
@Xanewok
Copy link
Member

Xanewok commented Jul 21, 2018 via email

Xanewok pushed a commit to Xanewok/rls-vscode that referenced this issue Mar 27, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants