Stream: t-compiler/wg-rls-2.0

Topic: MBE: mapping spans in IDE


matklad (Apr 11 2019 at 10:12, on Zulip):

cc @Igor Matuszewski

So, the high level goal here is to make this work:

macro_rules! s {
    ($i:ident) => { struct $i; }
}

s!(Foo); // arrive here

fn foo(_: Foo) { // press go to definition on `Foo` here

}
matklad (Apr 11 2019 at 10:14, on Zulip):

Currently, go to definition gives the wrong span (which is actually by itself is pretty cool!)

matklad (Apr 11 2019 at 10:15, on Zulip):

key code pointers:

TokenMap: https://github.com/rust-analyzer/rust-analyzer/blob/e6e2571bdf780d304c792d4317bbaf1d6f5d7a0a/crates/ra_mbe/src/syntax_bridge.rs#L9-L23

matklad (Apr 11 2019 at 10:16, on Zulip):

Original FIle function: https://github.com/rust-analyzer/rust-analyzer/blob/e6e2571bdf780d304c792d4317bbaf1d6f5d7a0a/crates/ra_hir/src/ids.rs#L37-L47

It should be extended to return a span-transofmation function as well

matklad (Apr 11 2019 at 10:18, on Zulip):

and here's the exact place where we get the wrgon span for goto definition: https://github.com/rust-analyzer/rust-analyzer/blob/e6e2571bdf780d304c792d4317bbaf1d6f5d7a0a/crates/ra_ide_api/src/display/navigation_target.rs#L149-L150

matklad (Apr 11 2019 at 10:19, on Zulip):

note that we call original_file here, which returns the source file (as opposed to the maro pseudo file, where the node actually resides), while the ndoe still has offsets in the macro-generated file

matklad (Apr 11 2019 at 10:21, on Zulip):

btw, might be a good idea to create a GitHub issue for this zulip thread as well

Last update: Nov 19 2019 at 17:35UTC