Search code examples
c#csvintellisenseimport-from-excel

C# String Formatting Dictionary Intellisense


I've been trying to bold and italicize a few strings in the following example but it's not working. Is it possible to edit the format of the string?

private TestQuickInfoSourceProvider m_provider;
    private ITextBuffer m_subjectBuffer;
    private Dictionary<string, string> m_dictionary;
    public TestQuickInfoSource(TestQuickInfoSourceProvider provider, ITextBuffer subjectBuffer)
    {
        m_provider = provider;
        m_subjectBuffer = subjectBuffer;

        //Methods and their description, good for unique keywords AKA QuickInfo words
        m_dictionary = new Dictionary<string, string>();
        m_dictionary.Add("adapt", "<b> Process given file </b>\n"

This is the output https://i.sstatic.net/smDUF.png

What is the proper way to format the string?

Edit///

Found an easier way to do it with a large amount of data through CSV.


Solution

  • The essential part of your code (which isn't included in your post) is the implementation of the AugmentQuickInfoSession method. I am assuming you are currently simply returning the string values from your m_dictionary there.

    Getting formatting results in QuickInfo requires a bit more work. Let's take a look at the definition of AugmentQuickInfoSession:

    void AugmentQuickInfoSession(IQuickInfoSession existingQuickInfoSession, IList<object> quickInfoContent, out ITrackin)
    

    The quickInfoContent is a list of object. If you return a String, it'll not be formatted. However, if you return a TextBlock object, you can include formatted text.

    Example code:

    var textBlock = new TextBlock { TextWrapping = TextWrapping.NoWrap };
    
    var boldRun = new Run("This is a bit of bold text.");
    boldRun.FontWeight = FontWeights.Bold;
    textBlock.Inlines.Add(boldRun);
    
    var normalRun = new Run("This is not very bold.);
    textBlock.Inlines.Add(normalRun );
    
    ...
    
    quickInfoContent.Add(textBlock);