How to set the color for the placeholders in a format string
Asked Answered
T

3

8

I have Resharper installed in Visual Studio, and am using the standard 'dark' theme, and somehow I managed to change something so that the '{0}' characters in a format string are no longer colored differently than the rest of the string.

For example, in the following line:

Console.WriteLine("Hello {0}", Environment.UserName);

The quoted string is entirely the same rust color (as it appears in this SO editor), whereas previously the '{0}' was highlighted with a bright greenish color.

EDIT

The settings under 'Resharper Format String Item' appear correct:

enter image description here

Also, the R# Code Annotations is set to JetBrains.Annotations, and is set as the default:

enter image description here

Would some other setting override this? Is there an easy way to just reset everything back to defaults?

Trounce answered 17/12, 2014 at 15:40 Comment(6)
Options -> Environment -> General -> Fonts and Colors -> choose 'Resharper Format String Item' from Display ItemsCodify
Thank you, but that is set correctly (bright green). Not sure why it isn't working, something else must be overriding it. :(Trounce
That's weird. Have you tried changing the theme and setting it back again?Codify
@JoonasKoski Yep. :(Trounce
I'm having the same problem. Any movement on this?Redroot
Hahahaha! Nabs!Wilfordwilfred
F
1

I've found the element in the change font dialog. It was a nightmare, hope it helps.

enter image description here

Fleda answered 14/9, 2016 at 19:6 Comment(0)
P
1

Try this so Visual Studio can highlight it for args like 'string.Format()' now acting as a custom 'foo.Format()':

internal class foo
{
    public static string Format(
      #if NET7_0_OR_GREATER
      [StringSyntax(StringSyntaxAttribute.CompositeFormat)]
      #endif
      string str, params object?[] args) => string.Format(str, args);
}
Patman answered 28/6, 2024 at 5:12 Comment(0)
P
0

As you've already noted, Resharper knows what color to use for this according to the setting here:

Options > Environment > General > Fonts and Colors — the Resharper Format String Item setting.

However, R# knows which methods to apply that color to by using its internal Code Annotations feature.

Check under Resharper > Options > Code Inspection > Code Annotations , and make sure that JetBrains.Annotations is checked, and that it is selected as the default annotation namespace at the bottom of that screen.

Penetration answered 17/12, 2014 at 19:10 Comment(3)
Thank you for the suggestion! Unfortunately, those settings are also set correctly. I'm really stumped by this one!Trounce
Pretty strange. If you change {0} to {1}, does R# warn about a non-existent argument?Penetration
It suggests that the problem does rest with Resharper not recognizing the code annotations for some reason, so it doesn't know that the arguments are format parameters. You may be able to confirm this further by following R# help here: jetbrains.com/resharper/webhelp80/…Penetration

© 2022 - 2025 — McMap. All rights reserved.