Visual Studio Free addin or resharper plugin to show constant value in tooltip
Asked Answered
R

4

23

Is there a free addin or resharper plugin that will let me see the actual value of a constant value when you hover over a reference to it ?

Since the compiler forces const fields or properties to be a concrete compile-time constant, it is only logical that it show it straight in the tooltip.

eg:

 
   const int DISPLAY_MODE_SIMPLE = 0x02;
   const int DISPLAY_MODE_ADVANCED = 0x04;

   void DoSomething(int displayMode) 
   {
      if (displayMode == DISPLAY_MODE_SIMPLE) {
         ShowSimpleDialog();
      }
   }

I want to hover over DISPLAY_MODE_SIMPLE and see in the tooltip: int MyType.DISPLAY_MODE_SIMPLE = 0x02

I am dealing with a lot of code lately that doesn't use Enums (Java converted with IKVMC), and constantly having to go back and forth when examining old code using it is very irritating.

Neither ReSharper 5 nor Visual Studio 2010 seem to have this feature.

Edit: I am not talking about the debugger. It works with that of course.

Reinertson answered 30/6, 2010 at 13:10 Comment(4)
I get the desired behaviour with R# 5 in both VS 2005 and VS 2008... I don't see any R# options which immediately suggest how it could be turned off, either.Whipperin
I don't get the desired behavior with R# 5 and VS 2008.Mendez
And... 3.5 years later and such a simple thing is still not available.Reinertson
Yes... I would pay a decent wadge to have a VS extension that did this for me... so much time wasted. Surely super easy considering all the dynamic compilation going on between VS and and R#. Some of the AI supported IDE features I see are really impressive... then at same time we are missing crazy easy to do, really useful features !Sprint
R
15

What about using "Code Definition Windows". View -> Code Definition WIndow in Visual Studio?

Ratchford answered 30/6, 2010 at 13:59 Comment(3)
Doesn't help when the constant is in a 3rd party library.Reinertson
Just tried. Works for .NET system libraries as well as 3rdparty libraries. I have ReSharper installed. Maybe that's the reason. I'm also trying that in VS 2010. Just tried in VS 2008, it works.Ratchford
I was unaware of this VS feature. Very nice - click on a method, variable, etc, and it's code is shown in another window. I've been doing it the hard way, with RightClick -> Go To DeclarationMendez
F
3

When I hover over the DISPLAY_MODE_SIMPLE reference in DoSomething, I see "(constant) int MyType.DISPLAY_MODE_SIMPLE = 2" in the tooltip. This does not appear when I suspend R# 5, so there must be some R# setting that you're not using...

Farver answered 30/6, 2010 at 13:21 Comment(7)
I don't have that with R#5 in VS2008. Maybe there's a setting to turn it on?Ake
@Ake I don't remember changing any settings (or installing any plugins) that I would expect to affect that...Farver
it works in debug mode of course, I was asking about the regular code editor.Reinertson
Weird. I've modified my settings, so maybe I turned it off accidentally.Ake
Doesn't work with R# 5 and VS 2008 for me either. I've also modified my settings, but could not find any that seemed related to this.Mendez
I'm not seeing this myself anymore (on R# 7 EAP and VS 11 Beta); I used to use the Agent Smith and Agent Johnson plugins, perhaps one of those was doing it.Farver
I DO see this in VS2022 with R# suspended, so seems maybe it's baked into VS now.Sprint
E
1

In current Resharper versions you can enable this.

  1. Resharper -> Options -> Settings:

Activate "Color identifiers". Might change your color highlightning colors

  1. Resharper -> Options -> Environment -> Editor -> Editor Appearance -> Tooltip:

Activate "Replace Visual Studio tooltip".

Exclaim answered 13/6, 2018 at 17:14 Comment(1)
see below for VS2022 location of this optionSprint
S
0

In VS2022 (community) I see the same behaviour as @bdukes with R# suspended so seems this is now a VS feature.

Only for const e.g.

const int testConst = 1;

Not for any of these:

   int test = 1;
   int test1 { get; } = 1;  
   static int test2 = 1;
   static int test3 { get; } = 1;
   readonly int test4 = 1;
   public static int test5 => 1;

   [DebuggerDisplay("test6 = {_test6}")]
   int test6 => 2;

If I resume R#, and try @Jens suggestion (slightly diff R# opts location now)

Environment > Editor > Visual Studio Features > Replace Visual Studio tooltips

I do get the const value in the tooltip (which it seems VS without R# does) but still get nothing for the others. (also get loads of other junk in the tooltips I personally do NOT want, and ludicrous colours that make me want to vomit through my nose).

So back to good o'l summary comments which we have to v. annoyingly keep in sync with changes to the actual values (which often we made into class members exactly to avoid needing to deal with refactor-tooling-unfriendly-strings-and-or-magic-unlabelled-values-in-code in the first place) erggg...

///<summary>[whatever-I-want-in-my-tooltip-which-in-this-case-is-the-initial-value-for-a-private-get-only-auto-prop-so-we-get-codesense-number-of-references-tips-and-links-for-AND-we-do-not-want-to-be-a-compile-time-literal-value-baked-into-our-dll(s)]</summary>

I'd love to have this in R# or (better) raw VS.

The @Ivan G. suggestion kind of does what I want/need but also is a whole other window cluttering my life, and also fails to achieve this basic want much of the time.

Oh well... back to whatever dull programming task I should be doing...

N.B. before some 1.2M-SO-points-holding-chatGpt-loving-soydev tells me I should be using a const... here's one reason why not

Sprint answered 27/3 at 18:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.