Roslyn: Instant feedback on the editor of interpolated strings

Created on 17 Mar 2016  路  8Comments  路  Source: dotnet/roslyn

Version Used: C# 7 new feature request

Steps to Reproduce:

If I type the following code in the editor the IDE will be smart enough to translate or resolve the interpolated string and show me the result in a tooltip when I hold my mouse pointer for a second or two.

var price = 500
var message = "The price is @price" // The tooltip will show: The price is 500



    1. 2.
  1. 3.

Expected Behavior:

Actual Behavior:

Area-IDE Resolution-Won't Fix

Most helpful comment

  1. That's not an interpolated string. $"The price is {price}" is.
  2. Those expressions are not constants, it's not possible for the compiler to know what the result will be at compile time because string interpolation is affected by locale.
  3. The C# compiler does not even offer this support for constants (that are the result of constant expressions), although that might be a useful proposal on its own.

All 8 comments

Syntax aside (which, if you follow your own thread at #9772, especially @mgravel's comment should make it clear why it won't happen), it is more or less not possible to evaluate variables like that, to produce meaningful data without incurring side effects (aka evaluation).

You should look at Alive (also built on top of Roslyn). It takes a nontrivial amount of work to support this, and not just for interpolated strings.

  1. That's not an interpolated string. $"The price is {price}" is.
  2. Those expressions are not constants, it's not possible for the compiler to know what the result will be at compile time because string interpolation is affected by locale.
  3. The C# compiler does not even offer this support for constants (that are the result of constant expressions), although that might be a useful proposal on its own.

@HaloFour I believe you might be wrong on 3., with Roslyn IDE now shows constant and enum values in tooltips. It does not evaluate the constant expressions but it seems to infer the enum values.

@miloush Yes, it does for simple constants, but not for constants that are the result of constant expressions, e.g. const string BAR = "FOO" + BAZ;. I should have been more clear about that.

String.Format Diagnostics had the capability of display the potential output as a Info diagnostic.

Looks to be a troll having some fun; see all suggested issues: https://github.com/josejmoran

Thanks for the suggestion. We're not planning to build this into Visual Studio, but you should take a look at http://comealive.io.

Thanks Dustin, I like comealive.io it is great!! awesome!!

Was this page helpful?
0 / 5 - 0 ratings