Getting language service colorizing to work in custom tool editor window?

Answered Getting language service colorizing to work in custom tool editor window?

  • Sunday, July 29, 2012 5:07 AM
     
     

    I have written a language service for the custom scripting language we use at my company. What I'm trying to do now is make a tool window that contains an editor that uses this language service to provide correct syntax coloring for the tool window. I'm using the SetLanguageServiceId function on the editor window's IVsTextBuffer (VsTextBufferAdapter) and inspecting the object I can see that my language service is correctly getting attached to the text buffer. My language service's methods are getting called to create the colorizer and such.

    However, I don't see any syntax coloring! What do I have to do to get the syntax coloring to show up? Is there something I need to do with the text view to allow the coloring to show up?

     - Dylan

All Replies

  • Monday, July 30, 2012 6:22 AM
    Moderator
     
     

    Hi Dylan,

    Your language service class should inherit the LanguageService class and implement the required methods. You must supply a scanner and parser by implementing the IScanner interface, and return an instance of that interface from the GetScanner method (one of the methods that must be implemented in the LanguageService class).

    More information you can refer to:

    http://msdn.microsoft.com/en-us/library/bb166173.aspx

    Best regards,


    Ego [MSFT]
    MSDN Community Support | Feedback to us

  • Monday, July 30, 2012 6:38 AM
     
     

    Yes, as I said I already wrote my language service and it works just fine. That is not what I am having trouble with.

    What I am having trouble with is creating a custom tool window that USES my language service.

    I don't understand what part of my message implied that I required more information about language services...

    To repeat my original question that has not been answered, how do I get syntax coloring to show up in my custom tool window that uses the language service that I have already written?
  • Monday, July 30, 2012 4:05 PM
    Moderator
     
     

    I am not familiar with the editor bits but if you posted a callstack (mixed mode, turn off Enable Just My Code, set Microsoft symbol servers on resolution path) where your colorizer is being created I could try looking around that code to see when it does the colorization queries and why it might not be applying the results. 

    Ryan

  • Monday, July 30, 2012 5:24 PM
     
      Has Code

    Here's the call stack starting at the point where the content for my tool window is requested:

    >	DCLanguagePackage.dll!NaughtyDog.DCLanguagePackage.DCLanguageService.GetColorizer(Microsoft.VisualStudio.TextManager.Interop.IVsTextLines buffer) Line 97	C#
     	Microsoft.VisualStudio.Package.LanguageService.10.0.dll!Microsoft.VisualStudio.Package.LanguageService.GetColorizer(Microsoft.VisualStudio.TextManager.Interop.IVsTextLines buffer, out Microsoft.VisualStudio.TextManager.Interop.IVsColorizer result) + 0x36 bytes	
     	Microsoft.VisualStudio.Editor.Implementation.dll!Microsoft.VisualStudio.Editor.Implementation.LanguageServiceClassifier.TryCreateClassifier(Microsoft.VisualStudio.Text.ITextBuffer textBuffer, Microsoft.VisualStudio.Editor.IVsFontsAndColorsInformationService fontAndColorInformation, out Microsoft.VisualStudio.Editor.Implementation.LanguageServiceClassifier classifier) + 0x196 bytes	
     	Microsoft.VisualStudio.Editor.Implementation.dll!Microsoft.VisualStudio.Editor.Implementation.LanguageServiceClassifierProvider.GetClassifier(Microsoft.VisualStudio.Text.ITextBuffer buffer) + 0x2d bytes	
     	Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.Classification.Implementation.ClassifierTaggerProvider.CreateTagger<System.__Canon>.AnonymousMethod__0(Microsoft.VisualStudio.Text.Classification.IClassifierProvider provider) + 0x10 bytes	
     	Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.Utilities.GuardedOperations.InvokeMatchingFactories<Microsoft.VisualStudio.Text.Classification.IClassifier,Microsoft.VisualStudio.Text.Classification.IClassifierProvider,Microsoft.VisualStudio.Text.Utilities.IContentTypeMetadata>(System.Collections.Generic.IEnumerable<System.Lazy<Microsoft.VisualStudio.Text.Classification.IClassifierProvider,Microsoft.VisualStudio.Text.Utilities.IContentTypeMetadata>> lazyFactories, System.Func<Microsoft.VisualStudio.Text.Classification.IClassifierProvider,Microsoft.VisualStudio.Text.Classification.IClassifier> getter, Microsoft.VisualStudio.Utilities.IContentType dataContentType, object errorSource) + 0xfc bytes	
     	Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.Classification.Implementation.ClassifierTaggerProvider.CreateTagger<Microsoft.VisualStudio.Text.Tagging.IClassificationTag>(Microsoft.VisualStudio.Text.ITextBuffer buffer) + 0x88 bytes	
     	Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.Tagging.Implementation.TagAggregator<Microsoft.VisualStudio.Text.Tagging.IClassificationTag>.GatherTaggers(Microsoft.VisualStudio.Text.ITextBuffer textBuffer) + 0x152 bytes	
     	Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.Tagging.Implementation.TagAggregator<Microsoft.VisualStudio.Text.Tagging.IClassificationTag>..ctor.AnonymousMethod__0(Microsoft.VisualStudio.Text.ITextBuffer buffer) + 0x19 bytes	
     	Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.Projection.Implementation.BufferGraph.GetTextBuffers(System.Predicate<Microsoft.VisualStudio.Text.ITextBuffer> match) + 0x88 bytes	
     	Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.Tagging.Implementation.TagAggregator<Microsoft.VisualStudio.Text.Tagging.IClassificationTag>.TagAggregator(Microsoft.VisualStudio.Text.Tagging.Implementation.TagAggregatorFactoryService factory, Microsoft.VisualStudio.Text.Editor.ITextView textView, Microsoft.VisualStudio.Text.Projection.IBufferGraph bufferGraph, Microsoft.VisualStudio.Text.Tagging.TagAggregatorOptions options) + 0x12b bytes	
     	Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.Tagging.Implementation.TagAggregatorFactoryService.CreateTagAggregator<Microsoft.VisualStudio.Text.Tagging.IClassificationTag>(Microsoft.VisualStudio.Text.Editor.ITextView textView, Microsoft.VisualStudio.Text.Tagging.TagAggregatorOptions options) + 0x4f bytes	
     	Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.Classification.Implementation.ClassifierAggregator.ClassifierAggregator(Microsoft.VisualStudio.Text.Editor.ITextView textView, Microsoft.VisualStudio.Text.Tagging.IViewTagAggregatorFactoryService viewTagAggregatorFactory, Microsoft.VisualStudio.Text.Classification.IClassificationTypeRegistryService classificationTypeRegistry) + 0x5e bytes	
     	Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.Classification.Implementation.ClassifierAggregatorService.GetClassifier(Microsoft.VisualStudio.Text.Editor.ITextView textView) + 0x29 bytes	
     	Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.Editor.Implementation.WpfTextView.WpfTextView(Microsoft.VisualStudio.Text.Editor.ITextViewModel textViewModel, Microsoft.VisualStudio.Text.Editor.ITextViewRoleSet roles, Microsoft.VisualStudio.Text.Editor.IEditorOptions parentOptions, Microsoft.VisualStudio.Text.Editor.Implementation.WpfTextEditorFactoryService factoryService) + 0x589 bytes	
     	Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.Editor.Implementation.WpfTextEditorFactoryService.CreateAndTrackTextView(Microsoft.VisualStudio.Text.Editor.ITextViewModel viewModel, Microsoft.VisualStudio.Text.Editor.ITextViewRoleSet roles, Microsoft.VisualStudio.Text.Editor.IEditorOptions parentOptions) + 0x3c bytes	
     	Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.Editor.Implementation.WpfTextEditorFactoryService.CreateAndTrackTextView(Microsoft.VisualStudio.Text.ITextDataModel dataModel, Microsoft.VisualStudio.Text.Editor.ITextViewRoleSet roles, Microsoft.VisualStudio.Text.Editor.IEditorOptions parentOptions) + 0xa9 bytes	
     	Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.Editor.Implementation.WpfTextEditorFactoryService.CreateTextView(Microsoft.VisualStudio.Text.ITextDataModel dataModel, Microsoft.VisualStudio.Text.Editor.ITextViewRoleSet roles, Microsoft.VisualStudio.Text.Editor.IEditorOptions parentOptions) + 0x29 bytes	
     	Microsoft.VisualStudio.Editor.Implementation.dll!Microsoft.VisualStudio.Editor.Implementation.VsTextViewAdapter.Init_InitializeWpfTextView() + 0x24b bytes	
     	Microsoft.VisualStudio.Editor.Implementation.dll!Microsoft.VisualStudio.Editor.Implementation.VsTextViewAdapter.Init_OnActivation() + 0x19 bytes	
     	Microsoft.VisualStudio.Editor.Implementation.dll!Microsoft.VisualStudio.Editor.Implementation.VsTextViewAdapter.Init_OnTextBufferInitialized(object sender, System.EventArgs e) + 0x91 bytes	
     	Microsoft.VisualStudio.Editor.Implementation.dll!Microsoft.VisualStudio.Editor.Implementation.VsTextViewAdapter.Init_SetBuffer(Microsoft.VisualStudio.TextManager.Interop.IVsTextLines pBuffer) + 0x149 bytes	
     	Microsoft.VisualStudio.Editor.Implementation.dll!Microsoft.VisualStudio.Editor.Implementation.VsTextViewAdapter.Init_Initialize(Microsoft.VisualStudio.TextManager.Interop.IVsTextLines pBuffer, System.IntPtr hwndParent, uint InitFlags, Microsoft.VisualStudio.TextManager.Interop.INITVIEW[] pInitView) + 0x9e bytes	
     	Microsoft.VisualStudio.Editor.Implementation.dll!Microsoft.VisualStudio.Editor.Implementation.VsTextViewAdapter.Initialize(Microsoft.VisualStudio.TextManager.Interop.IVsTextLines pBuffer, System.IntPtr hwndParent, uint InitFlags, Microsoft.VisualStudio.TextManager.Interop.INITVIEW[] pInitView) + 0x11 bytes	
     	DCListener.dll!NaughtyDog.DCListener.DCListenerWindow.InitializeEditor() Line 70 + 0x22 bytes	C#
     	DCListener.dll!NaughtyDog.DCListener.DCListenerWindow.TextViewHost.get() Line 93 + 0x8 bytes	C#
     	DCListener.dll!NaughtyDog.DCListener.DCListenerWindow.Content.get() Line 84 + 0x9 bytes	C#
     	Microsoft.VisualStudio.Shell.10.0.dll!Microsoft.VisualStudio.Shell.WindowPane.Microsoft.VisualStudio.Shell.Interop.IVsUIElementPane.CreateUIElementPane(out object uiElement) + 0x32 bytes	

    And here's the calling code:

    namespace NaughtyDog.DCListener
    {
        [Guid("566499d9-3b0b-4107-b2c7-0c52dc1c1e94")]
        public class DCListenerWindow : ToolWindowPane
        {
    		private IVsTextView m_textView;
    		private IWpfTextViewHost m_textViewHost;
    
            public DCListenerWindow() :
                base(null)
            {
            }
    
    		protected override void Initialize()
    		{
    			base.Initialize();
    
    			this.Caption = Resources.ToolWindowTitle;
    			this.BitmapResourceID = 301;
    			this.BitmapIndex = 1;
    
    			this.ToolBar = new CommandID(GuidList.guidDCListenerCmdSet, PkgCmdIDList.DCListenerToolbar);
    		}
    
    		private void InitializeEditor()
    		{
    			IComponentModel compMod = GetService(typeof(SComponentModel)) as IComponentModel;
    			IOleServiceProvider oleServiceProvider = (IOleServiceProvider)GetService(typeof(IOleServiceProvider));
    
    			IContentTypeRegistryService registryService = compMod.GetService<IContentTypeRegistryService>();
    			IVsEditorAdaptersFactoryService adapterFactory = compMod.GetService<IVsEditorAdaptersFactoryService>();
    
    			// Create a text buffer adapter and initialize it
    			IVsTextBuffer textBuffer = adapterFactory.CreateVsTextBufferAdapter(oleServiceProvider, registryService.GetContentType("DC"));
    			{
    				Guid dcLangServiceGuid = new Guid("fcf1a2bf-6881-3c1f-979e-25e729fd8f9d");
    				textBuffer.SetLanguageServiceID(dcLangServiceGuid);
    				textBuffer.InitializeContent("", 0);
    			}
    
    			// Create a text view and initialize it
    			m_textView = adapterFactory.CreateVsTextViewAdapter(oleServiceProvider);
    			{
    				IVsTextLines textLines = textBuffer as IVsTextLines;
    				uint textViewInitFlags = (uint)TextViewInitFlags.VIF_DEFAULT | (uint)TextViewInitFlags.VIF_HSCROLL | (uint)TextViewInitFlags.VIF_VSCROLL;
    				m_textView.Initialize(textLines, IntPtr.Zero, textViewInitFlags, null);
    			}
    
    			// Site the text view
    			((IObjectWithSite)m_textView).SetSite(oleServiceProvider);
    
    			// Move the caret to the end of the text
    			//IWpfTextView wpfTextView = adapterFactory.GetWpfTextView(m_textView);
    			//ITextBuffer mefTextBuffer
    			//wpfTextView.Caret.MoveTo(new SnapshotPoint(mefTextBuffer.CurrentSnapshot, mefTextBuffer.CurrentSnapshot.Length));
    		}
    
    		public override object Content
    		{
    			get { return TextViewHost; }
    		}
    
    		public IWpfTextViewHost TextViewHost
    		{
    			get
    			{
    				if (m_textViewHost == null)
    				{
    					InitializeEditor();
    
    					IVsUserData userData = m_textView as IVsUserData;
    					if (userData != null)
    					{
    						Guid g = Microsoft.VisualStudio.Editor.DefGuidList.guidIWpfTextViewHost;
    						object obj;
    						int hr = userData.GetData(ref g, out obj);
    						if (hr == VSConstants.S_OK)
    						{
    							m_textViewHost = obj as IWpfTextViewHost;
    						}
    					}
    				}
    				return m_textViewHost;
    			}
    		}
        }
    }

    Thanks for taking a look, Ryan!

  • Monday, July 30, 2012 6:49 PM
    Moderator
     
     

    And to double check, are you colorizer methods being invoked on the created colorizer and the UI is just never reflecting the tagged spans or are the colorizer methods never even being invoked after its creation?

    Ryan

  • Monday, July 30, 2012 6:51 PM
     
     

    I'm not at the computer with this project on it right now, but I do remember that the scanner methods were getting called to determine what colors each token should have. I did not check when I was looking at it last night if the methods on my language service to return the actual colors for each token type were getting called or not. When I get home I'll check that first thing and get back to you.

    Thank you for taking a look at this!

     - Dylan

  • Tuesday, July 31, 2012 4:11 AM
     
     
    I just checked and yes, GetColorableItem is getting called. So it seems that the UI is never reflecting the tagged spans!
  • Tuesday, July 31, 2012 4:12 PM
    Moderator
     
     

    I haven't yet had time to try and create a repro to debug, but I got some editor devs to look at this thread and they offered the following advice/feedback:

    1: If this is for 2010+ you shouldn't be using LanguageService as that is just a shim over the new editor extensibility APIs.

    2: #1 aside this should work. Are you sure you have the color stuff hooked up right so that the editor would know how to color the spans you are classifying?

    #3: What is the callstack when GetColorableItem is being invoked? Though I believe that method just populates color data, I don't think it means the classifier is being run. Is you IColorizer instance having methods invoked on it?

    Ryan

  • Tuesday, July 31, 2012 5:18 PM
     
      Has Code

    1) I also have to support VS2008, so it must be a LanguageService. Just out of curiosity though, what should I be using if this were 2010+ only?

    2) I'm fairly certain the color stuff is hooked up correctly, since when opening a document of my scripting language's type I do get syntax coloring and all that good stuff.

    3) You're right that it initially calls it to just populate some internal tables, but it also calls it when running the classifier (looks like it's generating a cache of color data). Here's a callstack! This happened when I typed the character that starts a line comment for the first time in my custom editor:

     	DCLanguagePackage.dll!NaughtyDog.DCLanguagePackage.DCLanguageService.GetColorableItem(int index, out Microsoft.VisualStudio.TextManager.Interop.IVsColorableItem item) Line 144	C#
     	Microsoft.VisualStudio.Editor.Implementation.dll!Microsoft.VisualStudio.Editor.Implementation.VsFontsAndColorsInformation.GetClassificationType(int colorableItemIndex) Line 190 + 0x19 bytes	C#
     	Microsoft.VisualStudio.Editor.Implementation.dll!Microsoft.VisualStudio.Editor.Implementation.LanguageServiceClassifier.ClassificationTypeFromAttribute(uint color) Line 77 + 0xf bytes	C#
     	Microsoft.VisualStudio.Editor.Implementation.dll!Microsoft.VisualStudio.Editor.Implementation.LanguageServiceClassifier.ClassifyLine(int lineNo) Line 122 + 0x5a bytes	C#
     	Microsoft.VisualStudio.Editor.Implementation.dll!Microsoft.VisualStudio.Editor.Implementation.LanguageServiceClassifier.GetClassificationSpans(Microsoft.VisualStudio.Text.SnapshotSpan textSpan) Line 204 + 0xc bytes	C#
     	Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.Classification.Implementation.ClassifierTagger.GetTags.MoveNext() Line 41 + 0x150 bytes	C#
     	Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.Tagging.Implementation.TagAggregator<Microsoft.VisualStudio.Text.Tagging.IClassificationTag>.GetTagsForBuffer.MoveNext() Line 280 + 0xf bytes	C#
     	Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.Tagging.Implementation.TagAggregator<Microsoft.VisualStudio.Text.Tagging.IClassificationTag>.InternalGetTags.MoveNext() Line 337 + 0x652 bytes	C#
     	Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.Tagging.Implementation.TagAggregator<Microsoft.VisualStudio.Text.Tagging.IClassificationTag>.GetTags.MoveNext() Line 244 + 0x22e bytes	C#
     	Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.Classification.Implementation.ClassifierAggregator.GetClassificationSpans(Microsoft.VisualStudio.Text.SnapshotSpan span) Line 93 + 0x150 bytes	C#
     	Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.Formatting.Implementation.NormalizedSpanGenerator.CreateClassifiedRuns(Microsoft.VisualStudio.Text.SnapshotSpan span, Microsoft.VisualStudio.Text.Classification.IClassifier classifier, Microsoft.VisualStudio.Text.Classification.IClassificationFormatMap classificationFormatMap) Line 76 + 0x17 bytes	C#
     	Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.Formatting.Implementation.NormalizedSpanGenerator.Create(Microsoft.VisualStudio.Text.Formatting.ITextAndAdornmentCollection elements, Microsoft.VisualStudio.Text.ITextSnapshot sourceSnapshot, Microsoft.VisualStudio.Text.Classification.IClassifier classifier, Microsoft.VisualStudio.Text.Classification.IClassificationFormatMap classificationFormatMap) Line 37 + 0x30 bytes	C#
     	Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.Formatting.Implementation.FormattedLineSource.Format(Microsoft.VisualStudio.Text.Formatting.ITextAndAdornmentCollection elements, Microsoft.VisualStudio.Text.ITextSnapshotLine line) Line 68 + 0x33 bytes	C#
     	Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.Formatting.Implementation.FormattedLineSource.FormatLineInVisualBuffer(Microsoft.VisualStudio.Text.ITextSnapshotLine visualLine) Line 123 + 0x33 bytes	C#
     	Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.Editor.Implementation.WpfTextView.FormatSnapshotLine(Microsoft.VisualStudio.Text.ITextSnapshotLine visualLine) Line 536 + 0x12 bytes	C#
     	Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.Editor.Implementation.WpfTextView.DoAnchorLayout(Microsoft.VisualStudio.Text.ITextSnapshotLine visualLine, Microsoft.VisualStudio.Text.SnapshotPoint anchorPosition, double referenceLine, Microsoft.VisualStudio.Text.Editor.ViewRelativePosition relativeTo, out double distanceAboveReferenceLine, out double distanceBelowReferenceLine) Line 395 + 0xc bytes	C#
     	Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.Editor.Implementation.WpfTextView.DoCompleteLayout(Microsoft.VisualStudio.Text.SnapshotPoint anchorPosition, double verticalDistance, Microsoft.VisualStudio.Text.Editor.ViewRelativePosition relativeTo, double effectiveViewportHeight, out double referenceLine, out double distanceAboveReferenceLine, out double distanceBelowReferenceLine) Line 432 + 0x28 bytes	C#
     	Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.Editor.Implementation.WpfTextView.InnerPerformLayout(Microsoft.VisualStudio.Text.SnapshotPoint anchorPosition, double verticalDistance, Microsoft.VisualStudio.Text.Editor.ViewRelativePosition relativeTo, double effectiveViewportWidth, double effectiveViewportHeight) Line 748 + 0x41 bytes	C#
     	Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.Editor.Implementation.WpfTextView.PerformLayout(Microsoft.VisualStudio.Text.ITextSnapshot newSnapshot, Microsoft.VisualStudio.Text.ITextSnapshot newVisualSnapshot, Microsoft.VisualStudio.Text.SnapshotPoint anchorPosition, double verticalDistance, Microsoft.VisualStudio.Text.Editor.ViewRelativePosition relativeTo, double effectiveViewportWidth, double effectiveViewportHeight) Line 1443 + 0x32 bytes	C#
     	Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.Editor.Implementation.WpfTextView.PerformLayout(Microsoft.VisualStudio.Text.ITextSnapshot newSnapshot, Microsoft.VisualStudio.Text.ITextSnapshot newVisualSnapshot) Line 1348	C#
     	Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.Editor.Implementation.WpfTextView.AdvanceSnapshot(Microsoft.VisualStudio.Text.TextSnapshotChangedEventArgs e) Line 231	C#
     	Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.Editor.Implementation.WpfTextView.AdvanceSnapshotOnUIThread(Microsoft.VisualStudio.Text.TextSnapshotChangedEventArgs e) Line 251	C#
     	Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.Editor.Implementation.WpfTextView.OnVisualBufferChanged(object sender, Microsoft.VisualStudio.Text.TextContentChangedEventArgs e) Line 1326	C#
     	Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.Utilities.GuardedOperations.RaiseEvent<Microsoft.VisualStudio.Text.TextContentChangedEventArgs>(object sender, System.EventHandler<Microsoft.VisualStudio.Text.TextContentChangedEventArgs> eventHandlers, Microsoft.VisualStudio.Text.TextContentChangedEventArgs args) Line 215 + 0x11 bytes	C#
     	Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.Implementation.BaseBuffer.RawRaiseEvent(Microsoft.VisualStudio.Text.TextContentChangedEventArgs args, bool immediate) Line 257	C#
     	Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.Implementation.BaseBuffer.TextContentChangedEventRaiser.RaiseEvent(Microsoft.VisualStudio.Text.Implementation.BaseBuffer baseBuffer, bool immediate) Line 1156	C#
     	Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.Implementation.BufferGroup.RaiseEvents() Line 353	C#
     	Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.Implementation.BufferGroup.FinishEdit() Line 134	C#
     	Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.Implementation.BaseBuffer.TextBufferEdit.Apply() Line 1110 + 0x11 bytes	C#
     	Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.Operations.Implementation.EditorOperations.InsertText(string text, bool final, string undoText) Line 1517 + 0xc bytes	C#
     	Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.Operations.Implementation.EditorOperations.InsertText(string text, bool final) Line 1407 + 0x2e bytes	C#
    >	Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.Operations.Implementation.EditorOperations.InsertText(string text) Line 1402 + 0xe bytes	C#
    

    And here's a callstack of the actual IColorizer object having its ColorizeLine function called:

    >	Microsoft.VisualStudio.Package.LanguageService.10.0.dll!Microsoft.VisualStudio.Package.Colorizer.ColorizeLine(int line, int length, System.IntPtr ptr, int state, uint[] attrs) Line 41	C#
     	Microsoft.VisualStudio.Package.LanguageService.10.0.dll!Microsoft.VisualStudio.Package.Colorizer.GetStateAtEndOfLine(int line, int length, System.IntPtr ptr, int state) Line 169 + 0x19 bytes	C#
     	Microsoft.VisualStudio.Editor.Implementation.dll!Microsoft.VisualStudio.Editor.Implementation.LanguageServiceClassifier.FixForwardStateCache(int startLine, int endLine) Line 158 + 0x44 bytes	C#
     	Microsoft.VisualStudio.Editor.Implementation.dll!Microsoft.VisualStudio.Editor.Implementation.LanguageServiceClassifier.textBuffer_Changed(object sender, Microsoft.VisualStudio.Text.TextContentChangedEventArgs e) Line 322 + 0xe bytes	C#
     	Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.Utilities.GuardedOperations.RaiseEvent<Microsoft.VisualStudio.Text.TextContentChangedEventArgs>(object sender, System.EventHandler<Microsoft.VisualStudio.Text.TextContentChangedEventArgs> eventHandlers, Microsoft.VisualStudio.Text.TextContentChangedEventArgs args) Line 215 + 0x11 bytes	C#
     	Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.Implementation.BaseBuffer.RawRaiseEvent(Microsoft.VisualStudio.Text.TextContentChangedEventArgs args, bool immediate) Line 257	C#
     	Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.Implementation.BaseBuffer.TextContentChangedEventRaiser.RaiseEvent(Microsoft.VisualStudio.Text.Implementation.BaseBuffer baseBuffer, bool immediate) Line 1156	C#
     	Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.Implementation.BufferGroup.RaiseEvents() Line 353	C#
     	Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.Implementation.BufferGroup.FinishEdit() Line 134	C#
     	Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.Implementation.BaseBuffer.TextBufferEdit.Apply() Line 1110 + 0x11 bytes	C#
     	Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.Operations.Implementation.EditorOperations.InsertText(string text, bool final, string undoText) Line 1517 + 0xc bytes	C#
     	Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.Operations.Implementation.EditorOperations.InsertText(string text, bool final) Line 1407 + 0x2e bytes	C#
     	Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.Operations.Implementation.EditorOperations.InsertText(string text) Line 1402 + 0xe bytes	C#

    Thanks for checking this out, Ryan!

     - Dylan

  • Tuesday, July 31, 2012 5:30 PM
    Moderator
     
     

    And this same codepath is hit in the editor outside of your toolwindow (the one that works)?  I am just trying to make sure your IVsColorableItem objects are 'proper' and the only difference between the working and non-working cases are the fact you are embedded in a toolwindow.

    I have to get some more info on the 2010+ APIs, but they are generally the MEF based ones like IClassifierProvider and the like.

    Ryan

  • Wednesday, August 01, 2012 2:19 AM
     
      Has Code

    Here's the callstack from opening a document in the normal VS editor, where the coloring works just fine:

    >	Microsoft.VisualStudio.Package.LanguageService.10.0.dll!Microsoft.VisualStudio.Package.Colorizer.ColorizeLine(int line, int length, System.IntPtr ptr, int state, uint[] attrs) Line 41	C#
     	Microsoft.VisualStudio.Package.LanguageService.10.0.dll!Microsoft.VisualStudio.Package.Colorizer.GetStateAtEndOfLine(int line, int length, System.IntPtr ptr, int state) Line 169 + 0x19 bytes	C#
     	Microsoft.VisualStudio.Editor.Implementation.dll!Microsoft.VisualStudio.Editor.Implementation.LanguageServiceClassifier.FixForwardStateCache(int startLine, int endLine) Line 158 + 0x20 bytes	C#
     	Microsoft.VisualStudio.Editor.Implementation.dll!Microsoft.VisualStudio.Editor.Implementation.LanguageServiceClassifier.ForceReclassifyLines(int startLine, int endLine) Line 181 + 0xa bytes	C#
     	Microsoft.VisualStudio.Editor.Implementation.dll!Microsoft.VisualStudio.Editor.Implementation.LanguageServiceClassifier.LanguageServiceClassifier(Microsoft.VisualStudio.Text.ITextBuffer textBuffer, Microsoft.VisualStudio.Editor.Implementation.VsTextBufferAdapter bufferAdapter, System.Guid languageServiceID, Microsoft.VisualStudio.TextManager.Interop.IVsColorizer colorizer, Microsoft.VisualStudio.Editor.IVsFontsAndColorsInformation fontsAndColorsInformation) + 0xd1 bytes	
     	Microsoft.VisualStudio.Editor.Implementation.dll!Microsoft.VisualStudio.Editor.Implementation.LanguageServiceClassifier.TryCreateClassifier(Microsoft.VisualStudio.Text.ITextBuffer textBuffer, Microsoft.VisualStudio.Editor.IVsFontsAndColorsInformationService fontAndColorInformation, out Microsoft.VisualStudio.Editor.Implementation.LanguageServiceClassifier classifier) Line 397 + 0x31 bytes	C#
     	Microsoft.VisualStudio.Editor.Implementation.dll!Microsoft.VisualStudio.Editor.Implementation.LanguageServiceClassifierProvider.GetClassifier(Microsoft.VisualStudio.Text.ITextBuffer buffer) Line 19 + 0x2d bytes	C#
     	Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.Classification.Implementation.ClassifierTaggerProvider.CreateTagger<System.__Canon>.AnonymousMethod__0(Microsoft.VisualStudio.Text.Classification.IClassifierProvider provider) + 0x10 bytes	
     	Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.Utilities.GuardedOperations.InvokeMatchingFactories<Microsoft.VisualStudio.Text.Classification.IClassifier,Microsoft.VisualStudio.Text.Classification.IClassifierProvider,Microsoft.VisualStudio.Text.Utilities.IContentTypeMetadata>(System.Collections.Generic.IEnumerable<System.Lazy<Microsoft.VisualStudio.Text.Classification.IClassifierProvider,Microsoft.VisualStudio.Text.Utilities.IContentTypeMetadata>> lazyFactories, System.Func<Microsoft.VisualStudio.Text.Classification.IClassifierProvider,Microsoft.VisualStudio.Text.Classification.IClassifier> getter, Microsoft.VisualStudio.Utilities.IContentType dataContentType, object errorSource) Line 174	C#
     	Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.Classification.Implementation.ClassifierTaggerProvider.CreateTagger<Microsoft.VisualStudio.Text.Tagging.IClassificationTag>(Microsoft.VisualStudio.Text.ITextBuffer buffer) Line 19 + 0x88 bytes	C#
     	Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.Tagging.Implementation.TagAggregator<Microsoft.VisualStudio.Text.Tagging.IClassificationTag>.GatherTaggers(Microsoft.VisualStudio.Text.ITextBuffer textBuffer) Line 167 + 0x32 bytes	C#
     	Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.Tagging.Implementation.TagAggregator<Microsoft.VisualStudio.Text.Tagging.IClassificationTag>..ctor.AnonymousMethod__0(Microsoft.VisualStudio.Text.ITextBuffer buffer) Line 50 + 0xc bytes	C#
     	Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.Projection.Implementation.BufferGraph.GetTextBuffers(System.Predicate<Microsoft.VisualStudio.Text.ITextBuffer> match) Line 168 + 0xc bytes	C#
     	Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.Tagging.Implementation.TagAggregator<Microsoft.VisualStudio.Text.Tagging.IClassificationTag>.TagAggregator(Microsoft.VisualStudio.Text.Tagging.Implementation.TagAggregatorFactoryService factory, Microsoft.VisualStudio.Text.Editor.ITextView textView, Microsoft.VisualStudio.Text.Projection.IBufferGraph bufferGraph, Microsoft.VisualStudio.Text.Tagging.TagAggregatorOptions options) Line 49 + 0x12b bytes	C#
     	Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.Tagging.Implementation.TagAggregatorFactoryService.CreateTagAggregator<Microsoft.VisualStudio.Text.Tagging.IClassificationTag>(Microsoft.VisualStudio.Text.Editor.ITextView textView, Microsoft.VisualStudio.Text.Tagging.TagAggregatorOptions options) Line 34	C#
     	Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.Classification.Implementation.ClassifierAggregator.ClassifierAggregator(Microsoft.VisualStudio.Text.Editor.ITextView textView, Microsoft.VisualStudio.Text.Tagging.IViewTagAggregatorFactoryService viewTagAggregatorFactory, Microsoft.VisualStudio.Text.Classification.IClassificationTypeRegistryService classificationTypeRegistry) Line 37 + 0x1f bytes	C#
     	Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.Classification.Implementation.ClassifierAggregatorService.GetClassifier(Microsoft.VisualStudio.Text.Editor.ITextView textView) Line 18	C#
     	Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.Editor.Implementation.WpfTextView.WpfTextView(Microsoft.VisualStudio.Text.Editor.ITextViewModel textViewModel, Microsoft.VisualStudio.Text.Editor.ITextViewRoleSet roles, Microsoft.VisualStudio.Text.Editor.IEditorOptions parentOptions, Microsoft.VisualStudio.Text.Editor.Implementation.WpfTextEditorFactoryService factoryService) Line 209 + 0x15 bytes	C#
     	Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.Editor.Implementation.WpfTextEditorFactoryService.CreateAndTrackTextView(Microsoft.VisualStudio.Text.Editor.ITextViewModel viewModel, Microsoft.VisualStudio.Text.Editor.ITextViewRoleSet roles, Microsoft.VisualStudio.Text.Editor.IEditorOptions parentOptions) Line 31 + 0x1e bytes	C#
     	Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.Editor.Implementation.WpfTextEditorFactoryService.CreateAndTrackTextView(Microsoft.VisualStudio.Text.ITextDataModel dataModel, Microsoft.VisualStudio.Text.Editor.ITextViewRoleSet roles, Microsoft.VisualStudio.Text.Editor.IEditorOptions parentOptions) Line 51 + 0xf bytes	C#
     	Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.Editor.Implementation.WpfTextEditorFactoryService.CreateTextView(Microsoft.VisualStudio.Text.ITextDataModel dataModel, Microsoft.VisualStudio.Text.Editor.ITextViewRoleSet roles, Microsoft.VisualStudio.Text.Editor.IEditorOptions parentOptions) Line 129 + 0x7 bytes	C#
     	Microsoft.VisualStudio.Editor.Implementation.dll!Microsoft.VisualStudio.Editor.Implementation.VsTextViewAdapter.Init_InitializeWpfTextView() Line 3052 + 0x26 bytes	C#
     	Microsoft.VisualStudio.Editor.Implementation.dll!Microsoft.VisualStudio.Editor.Implementation.VsTextViewAdapter.Init_OnActivation() Line 3106	C#
     	Microsoft.VisualStudio.Editor.Implementation.dll!Microsoft.VisualStudio.Editor.Implementation.VsTextViewAdapter.ShimHostNowVisible(object sender, System.EventArgs e) Line 7016 + 0x5 bytes	C#
     	Microsoft.VisualStudio.Editor.Implementation.dll!Microsoft.VisualStudio.Editor.Implementation.VsTextViewAdapter.TextViewShimHost.OnLayoutUpdated(object sender, System.EventArgs e) Line 8558 + 0x1c bytes	C#
    

  • Wednesday, August 01, 2012 10:05 AM
     
     

    For what it's worth, I tried setting the language service to be the C# one and I still don't get any coloring.

    This leads me to believe this has something to do with how I'm creating the editor window, rather than the language service itself...

  • Monday, August 06, 2012 5:05 PM
    Moderator
     
     

    Sorry, I haven't had any time to look into this yet :(  Also, this is a complex enough scenario I am not confident that me trying to put together a repro would be feasible, there are too many subtle things I could do differently that make it work.  I took a look at some internal code that calls SetLanguageServiceId explicitly to see if the followed any different patterns than you did, I noticed that (at least the one I am looking at) creates the text lines object and sites it before calling SetLanguageServiceId. Above you site it at the end, if during initialization/setup it ends up needing any services it would fail if it hadn't been sited. Also, in the code above, you are ignoring all the return codes from various calls like Initialize and SetLanguageServiceId, can you double check they are all returning S_OK?

    Ryan

  • Wednesday, August 08, 2012 11:02 AM
     
     
    I tried rearranging the calls with no difference in outcome. I've also checked the return values and all are returning 0 (S_OK). :\
  • Saturday, August 18, 2012 8:34 AM
     
     Answered Has Code

    I figured out the solution! It turns out that by default, the text view that is created by the text view adapter factory is set up to be a tool output view - meaning it looks and behaves just like the build output window does. This means no colors!

    To fix it, you have to manually tell it to use the text editor font and color categories:

    IVsTextEditorPropertyCategoryContainer propCategoryContainer = (IVsTextEditorPropertyCategoryContainer)m_textView;
    IVsTextEditorPropertyContainer ppProp;
    propCategoryContainer.GetPropertyCategory(Microsoft.VisualStudio.Editor.DefGuidList.guidEditPropCategoryViewMasterSettings, out ppProp);
    
    ppProp.SetProperty(VSEDITPROPID.VSEDITPROPID_ViewGeneral_ColorCategory, Microsoft.VisualStudio.Editor.DefGuidList.guidTextEditorFontCategory);
    ppProp.SetProperty(VSEDITPROPID.VSEDITPROPID_ViewGeneral_FontCategory, Microsoft.VisualStudio.Editor.DefGuidList.guidTextEditorFontCategory);

    BAM! Colors!

    • Marked As Answer by Dylan Barrie Saturday, August 18, 2012 8:34 AM
    •  
  • Saturday, August 18, 2012 5:57 PM
    Moderator
     
     
    Nice! Sorry I couodn't offer any help, glad you got it working. I will file this bit of info away for future questions.