简体   繁体   中英

Show function names in vscode "Find All References?"

Shift+F12 in Visual Studio Code shows the references to a function or variable. Is it possible to make it also show what function each hit belongs to?

Current right side view:

main.c
  close()
  close()
runner.c
  close()
system.c
  void close()

What I want:

main.c
  main(): close()
  control(): close()
runner.c
  abort(): close()
system.c
  void close()

At the moment, I find that I need to click each hit and scroll a bit to see what function it belongs to.

This question mentions Resharper, but I'm writing C code: Show method name in "Find all references" - C# Visual Studio

The same problem. source insight has this feature.

The short answer is "No," there is no current mechanism by which to make VSCode show what you are requesting.

I prefer to use VisualStudio for c and c++, but sadly there also is no current mechanism to make VisualStudio show anything more than the definition, project, file, and line/column at which a reference was found. IMO it is reasonable to consider both VS and VSCode together here because I believe it highly likely that if this particular feature makes it into one, it will make it into both.

It appears that users of VisualStudio have been requesting the name of the function (or method) in which the reference was found (ie, the exact same feature you are seeking) for many years. The request has repeatedly been closed with a statement that insufficient upvotes show this is not a high enough priority.

In general, feature requests are prioritized against everything the dev team already needs/wants to do and everything else that has been requested by users and has made it through some preliminary screening. If you really care about this functionality you probably would need to re-submit it and mobilize community support to upvote it as a requested feature. Here's the wiki link explaining the process

IMO this shortcoming of is one of a group of failings that together create the market for add-on products like Resharper and competing products such as Source Insight.

There is a dumb workaround that I use in VisualStudio. I do not know whether it will have the same effect in VSCode, but I will share it here in case it helps somebody. In VS, each displayed reference also displays any comment that was placed on the same line as the reference. This means I can do something like:

void funcOne()
{
   // your code here
   close(); //[Call from funcOne]
}
void funcTwo()
{
   // your code here
   close(); //[Call from funcTwo]
}

The FindReferences window then makes it possible to see the source of each reference without needing to open each one. The attached image shows what this looks like in VisualStudio CommunityEdition 2022 (I happen to be working in c++ for embedded processors using the VisualMicro add-on, but the described behavior is innate to VisualStudio's Find References function).

屏幕截图

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM