locked
VS Extension - disabling errors from embedded code editor RRS feed

  • Question

  • Hi,

    I'm embedding a c# code editor in a wpf control. I'm loading into it a temp file that is not part of the solution. 

    The problem is that the loaded code have parsing errors which shows up in the error list.

    Is there a way to set those errors to not appear in the error list?

    Here is the code:

    IVsInvisibleEditorManager invisibleEditorManager = (IVsInvisibleEditorManager)ServiceProvider.GlobalProvider.GetService(typeof(SVsInvisibleEditorManager));
    
    ErrorHandler.ThrowOnFailure(invisibleEditorManager.RegisterInvisibleEditor(csTempFilePath, pProject: null,dwFlags: (uint)_EDITORREGFLAGS.RIEF_ENABLECACHING,
    																		   pFactory: null, ppEditor: out this.invisibleEditor));
    
    //The doc data is the IVsTextLines that represents the in-memory version of the file we opened in our invisibe editor, we need
    //to extract that so that we can create our real (visible) editor.
    IntPtr docDataPointer = IntPtr.Zero;
    Guid guidIVSTextLines = typeof(IVsTextLines).GUID;
    ErrorHandler.ThrowOnFailure(this.invisibleEditor.GetDocData(fEnsureWritable: 1, riid: ref guidIVSTextLines, ppDocData: out docDataPointer));
    
    try
    {
    	IVsTextLines docData = (IVsTextLines)Marshal.GetObjectForIUnknown(docDataPointer);
    
    	//Get the component model so we can request the editor adapter factory which we can use to spin up an editor instance.
    	IComponentModel componentModel = (IComponentModel)ServiceProvider.GlobalProvider.GetService(typeof(SComponentModel));
    	IVsEditorAdaptersFactoryService editorAdapterFactoryService = componentModel.GetService<IVsEditorAdaptersFactoryService>();
    
    	//Create a code window adapter.
    	this.codeWindow = editorAdapterFactoryService.CreateVsCodeWindowAdapter(OleServiceProvider);
    
    	IVsCodeWindowEx codeWindowEx = (IVsCodeWindowEx)this.codeWindow;
    	INITVIEW[] initView = new INITVIEW[1];
    	codeWindowEx.Initialize((uint)_codewindowbehaviorflags.CWB_DISABLESPLITTER,
    							 VSUSERCONTEXTATTRIBUTEUSAGE.VSUC_Usage_Filter,
    							 szNameAuxUserContext: "",
    							 szValueAuxUserContext: "",
    							 InitViewFlags: 0,
    							 pInitView: initView);
    
    	ErrorHandler.ThrowOnFailure(this.codeWindow.SetBuffer((IVsTextLines)docData));
    
    	//Get our text view for our editor which we will use to get the WPF control that hosts said editor.
    	ErrorHandler.ThrowOnFailure(this.codeWindow.GetPrimaryView(out this.textView));
    
    	//Get our WPF host from our text view (from our code window).
    	IWpfTextViewHost textViewHost = editorAdapterFactoryService.GetWpfTextViewHost(this.textView);
    
    	textViewHost.TextView.Options.SetOptionValue(DefaultTextViewHostOptions.ChangeTrackingId, false);
    	textViewHost.TextView.Options.SetOptionValue(DefaultTextViewOptions.ViewProhibitUserInputId, true);
    
    	var dte = ContainerFactory.GetContainer().Resolve<DTE2>();
    	var projectItem = dte.Solution.FindProjectItem(csTempFilePath);
    	projectItem.Properties.Item("BuildAction").Value = prjBuildAction.prjBuildActionNone;
    
    	return textViewHost.HostControl;
    }
    finally
    {
    	if (docDataPointer != IntPtr.Zero)
    	{
    		//Release the doc data from the invisible editor since it gave us a ref-counted copy.
    		Marshal.Release(docDataPointer);
    	}
    }

    Thanks,

    Yoel


    Tuesday, July 22, 2014 10:09 AM

Answers

  • For future reference: 

    I solved it partially -

    The parsing errors were caused because the code was a method without a class. So i wrapped the method in a class and used an elision buffer to show only the method without the wrapper class

    • Marked as answer by Typemock Team Thursday, July 31, 2014 12:40 PM
    Thursday, July 31, 2014 12:40 PM

All replies

  • Hi,

    According to your description, you want to do something related with the VS error list. Please read this blog "Writing to the VS ErrorList" to lean how to manipulate error list window. It includes detailed code example.

    The Shell provides a class to gain access to the ErrorList pane : ErrorListProvider. It implements the Add/Remove of ErrorList items in the ErrorList pane. To gain access to this provider it expects a ServiceProvider in the constructor. This provider can be the GlobalService of the Package class.

    An ErrorList item is a class (called ErrorTask) where you can set all needed properties to navigate to the location in the document, categorize it and show the message.

    We have the ErrorListProvider in place, we have to make the helper class to add and remove items from the list: this includes, creating a ErrorTask object and handle the event to navigate to the context document’s position.

    To remove the ErrorTask from the list, make use of the same Guid/Name to re-instantiate the ErrorListProvider.  The context argument in the write method can be used to remove all ErrorTasks for this context. The handling with the context is not covered here, because this post is focussed on the element to make this work.

    When removing you should use the SuspendRefresh() before removing and ResumeRefresh() after the items are removed to avoid flickering.

    Best regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    • Edited by Anna Cc Thursday, July 24, 2014 6:36 AM
    Thursday, July 24, 2014 6:29 AM
  • This doesn't seem to work, maybe because i can't remove errors generated by a different error provider.

    Here is the code i tried using

            public void RemoveTempFileErrors()
            {
                var provider = new ErrorListProvider(ServiceProvider.GlobalProvider)
                    {
                        ProviderName = "MyProvider",
                        ProviderGuid = new Guid("41C0915D-A0F4-42B2-985F-D1CC5F65BFFC") // my provider guid
                    };
    
                var vsTaskList1 = (IVsTaskList) Package.GetGlobalService(typeof (IVsTaskList));
                uint providerCookie;
                vsTaskList1.RegisterTaskProvider(provider, out providerCookie);
                
                vsTaskList1.RefreshTasks(providerCookie);
    
                var vsTaskList2 = (IVsTaskList2)Package.GetGlobalService(typeof(IVsTaskList));
    
                provider.SuspendRefresh();
                IVsEnumTaskItems enumerator;
                vsTaskList1.EnumTaskItems(out enumerator);
                IVsTaskItem[] arr = new IVsTaskItem[1];
                while (enumerator.Next(1, arr, null) == 0)
                {
                    string doc;
                    arr[0].Document(out doc);
                    if (doc == csTempFilePath)
                    {
                        vsTaskList2.RemoveTasks(providerCookie, 1, arr);
                    }            
                }
    
                provider.ResumeRefresh();
                provider.Refresh();
                vsTaskList1.UnregisterTaskProvider(providerCookie);
            }
    

    Thursday, July 24, 2014 8:57 AM
  • For future reference: 

    I solved it partially -

    The parsing errors were caused because the code was a method without a class. So i wrapped the method in a class and used an elision buffer to show only the method without the wrapper class

    • Marked as answer by Typemock Team Thursday, July 31, 2014 12:40 PM
    Thursday, July 31, 2014 12:40 PM