Skip to content

Jumping to method with tracing::instrument macro fails #12206

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

Closed
gcohara opened this issue May 10, 2022 · 11 comments
Closed

Jumping to method with tracing::instrument macro fails #12206

gcohara opened this issue May 10, 2022 · 11 comments

Comments

@gcohara
Copy link

gcohara commented May 10, 2022

With the following example

use tracing;

fn main() {
    println!("Hello, world!");
    Foo::bar()
}

struct Foo {}

impl Foo {
    #[tracing::instrument]
    fn bar() {}
}

attempting to jump to the definition of bar using M-. in Emacs fails with No definitions found for: bar.

However, with the attribute macro removed:

use tracing;

fn main() {
    println!("Hello, world!");
    Foo::bar()
}

struct Foo {}

impl Foo {
    fn bar() {}
}

this jumps successfully to bar.

rust-analyzer version: 2022-05-02, installed via HomeBrew

rustc version: 1.58.1

Please let me know if any further information would be useful for debugging.

@lnicola
Copy link
Member

lnicola commented May 10, 2022

This works for me. Does lsp-mode enable proc macro attribute support?

It does: https://emacs-lsp.github.io/lsp-mode/page/lsp-rust-analyzer/#lsp-rust-analyzer-experimental-proc-attr-macros.

@lnicola
Copy link
Member

lnicola commented May 10, 2022

CC @flodiebold ^

@Veykril
Copy link
Member

Veykril commented May 10, 2022

This might be #12050 Actually no it shouldnt be

@gcohara
Copy link
Author

gcohara commented May 10, 2022

Here are some relevant sections from the LSP mode logs:

Failing with the attribute macro

[Trace - 02:42:18 PM] Sending request 'textDocument/definition - (1423)'.
Params: {
  "textDocument": {
    "uri": "file:///Users/stuff/ra_test/src/main.rs"
  },
  "position": {
    "line": 4,
    "character": 9
  }
}


[Trace - 02:42:18 PM] Received response 'textDocument/definition - (1423)' in 0ms.
Result: []

Succeeding without the attribute macro:

Params: {
  "textDocument": {
    "uri": "file:///Users/stuff/ra_test/src/main.rs"
  },
  "position": {
    "line": 4,
    "character": 10
  }
}


[Trace - 02:43:23 PM] Received response 'textDocument/definition - (1438)' in 0ms.
Result: [
  {
    "targetSelectionRange": {
      "end": {
        "character": 10,
        "line": 11
      },
      "start": {
        "character": 7,
        "line": 11
      }
    },
    "targetRange": {
      "end": {
        "character": 15,
        "line": 11
      },
      "start": {
        "character": 4,
        "line": 10
      }
    },
    "targetUri": "file:///Users/stuff/ra_test/src/main.rs",
    "originSelectionRange": {
      "end": {
        "character": 12,
        "line": 4
      },
      "start": {
        "character": 9,
        "line": 4
      }
    }
  }
]```

@lnicola
Copy link
Member

lnicola commented May 10, 2022

Do you have any relevant LSP config? Is lsp-mode up to date?

@gcohara
Copy link
Author

gcohara commented May 10, 2022

I'm on LSP mode 8.0.0 which is the most recent. I don't have any LSP mode stuff in my init.el that I think could be relevant.

(setq lsp-ui-sideline-show-hover nil)
(setq lsp-ui-sideline-show-code-actions nil)
(setq lsp-ui-doc-enable nil)
(setq lsp-ui-sideline-enable nil)
(setq lsp-ui-doc-show-with-mouse nil)
(setq lsp-diagnostics-provider :flymake)
(setq lsp-signature-render-documentation nil)
(setq lsp-signature-auto-activate nil)

is about it.

I checked the variable you mentioned - it was set to nil. I tried setting it to t but this didn't help sadly.

@lnicola
Copy link
Member

lnicola commented May 10, 2022

You might have to restart RA/LSP/emacs. Don't set it to nil.

@flodiebold
Copy link
Member

If it was just a matter of proc macro expansion being disabled, go to definition would still work, wouldn't it? It might be the expansion failing instead for some reason? 🤔

@gcohara
Copy link
Author

gcohara commented May 10, 2022

Restarted Emacs and RA with lsp-rust-analyzer-experimental-proc-attr-macros set to t but still no luck

@Veykril
Copy link
Member

Veykril commented May 10, 2022

Can't repro this either in my VSCode. I assume you are using the latest tracing version? As flodiebold said, a disabled expansion shouldn't cause that. So the expansion is most likely failing in some way. Are there any errors in your logs?

@gcohara
Copy link
Author

gcohara commented May 11, 2022

It turns out that lsp-rust-analyzer-proc-macro-enable was set to nil. Setting it to t solved it!

Apologies for wasting your time, and many thanks to all of you for being so helpful.

@gcohara gcohara closed this as completed May 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants