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

Renaming a trait method fails to rename method on trait impls #621

Closed
ZoeyR opened this issue Dec 8, 2017 · 2 comments
Closed

Renaming a trait method fails to rename method on trait impls #621

ZoeyR opened this issue Dec 8, 2017 · 2 comments
Labels
Milestone

Comments

@ZoeyR
Copy link
Contributor

ZoeyR commented Dec 8, 2017

When invoking rename on a method call to a trait method the language server will not have workspace edits for implmentations of the trait, only the trait definitions and invocations of the function. See below for example code and the parameters sent between the client and the server.

Example Code:

use foo::Baz;

pub fn use_bar() {
    let _ = foo::Bar.baz();
}

mod foo {
    pub struct Bar;

    pub trait Baz {
        fn baz(&self);
    }

    impl Baz for Bar {
        fn baz(&self) {
        }
    }
}

Params sent from client to server

{
    "textDocument": {
        "uri": "file:///C:/my/home/Documents/rust-lsp-tests/src/lib.rs"
    },
    "position": {
        "line": 3,
        "character": 22
    },
    "newName": "buzz"
}

Params sent from server to client:

{
    "changes": {
        "file:///C:/my/home/Documents/rust-lsp-tests/src/lib.rs": [
            {
                "range": {
                    "start": {
                        "line": 10,
                        "character": 11
                    },
                    "end": {
                        "line": 10,
                        "character": 14
                    }
                },
                "newText": "buzz"
            },
            {
                "range": {
                    "start": {
                        "line": 3,
                        "character": 21
                    },
                    "end": {
                        "line": 3,
                        "character": 24
                    }
                },
                "newText": "buzz"
            }
        ]
    },
    "documentChanges": null
}
@ZoeyR ZoeyR changed the title Rename trait method fails to rename method on trait impls Renaming a trait method fails to rename method on trait impls Dec 8, 2017
@nrc nrc added the bug label Dec 11, 2017
@nrc nrc added this to the 1.0 milestone Dec 11, 2017
@nrc
Copy link
Member

nrc commented Dec 11, 2017

We should block these renames in the same way we do with fields using field init sugar, etc.

@algesten
Copy link
Contributor

I've started looking at this. Here's a test case in rls-analysis that does what the rename request does in RLS.

rust-dev-tools/rls-analysis@ab863c5

This may or may not be related to https://internals.rust-lang.org/t/rustdoc2-rls-analysis-and-the-compiler-help-wanted/6592/5

find_impls() currently returns spans for the rows with impl Baz for Bar, which isn't particularly helpful when trying to navigate from def to trait. Next step is probably to understand whether the changes @nrc posted about indeed are enough to support this case. I think it is.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants