Basically, what I'm trying to do is to add errors/items to the Error List in VisualStudio based on Code Analysis (either at solution or file level).
If you want to read the solution, it is here https://gist.github.com/3185313 (also included at the end of this post). This script was executed from an O2 REPL Script environment running inside VisualStudio.
The next text is from an email I wrote asking for help to a MS guru on VS Extensibility.
----start----
I was expecting this to be something like this (in pseudo C# code):
VisualStudio.Editor.OnTextChange( ()=>{var code = VisualStudio.Editor.GetCode();var errorListPane = VisualStudio.ErrorPane;var issues = AnalyzeAndGetIssues(code);foreach(var issue in issues)errorListPane.Add(issue.Text, issue.Span, issue.Severity) });
VisualStudio.Editor.OnTextChange( (code)=>{var issues = code.AnalyzeAndGetIssues();VisualStudio.ErrorPane.add(issues) });
VisualStudio.Editor.OnCompile((assemblies)=>{var issues = assemblies.AnalyzeAndGetIssues(); VisualStudio.ErrorPane.add(issues) });
Here is a thread about what I'm trying to do and with the same problems that I have: How to add parsing errors to ErrorList window?
- I have written an VS Add-in which gives me access to the DTE2 and AddIn objects inside a REPL environment on a running VisualStudio instance (think of it as a mix of Interactive Window + Roslyn REPL)
- I have a VSPackage/VSIX that gives me access to the Package object and MEF exports from a similar REPL environment.
- From the Addin I can create VisualStudio native dockable panels (with an WinForms or WPF control inside). Take a look at the video here http://diniscruz.blogspot.co.uk/2012/06/real-time-vulnerability-creation.html to see an Code Editor (from SharpDevelop) running natively in VisualStudio with a couple extra panels showing security vulnerabilities information (note that these controls are hosted natively in VisualStudio windows created using DTE's CreateToolWindow2 method)
- One of the problems I had was in gaining access to the live instance of the Error Panel, since in one of my tests I had the error: The service "Microsoft.VisualStudio.Shell.Interop.IVsTaskList" must be installed for this feature to work"
- I could try to access the actually ListView control via the WPF/WinForms GUI controls, but that would be a massive hack
- I was able to create a PoC that did exactly what I wanted using a variation of the Roslyn's CodeIssue example. This did exactly what I wanted since I had a callback from Roslyn that expected to receive a List of CodeIssue objects (which where then added to the VisualStudio Error List). I have looked at Roslyn code, but can't figure out its connection with the actually error list (there are too many layers of callbacks).
- One key objective that we have is to able to distribute our solution in one file installer. At the moment a VSIX seems like a perfect solution since it allows the easy distribution and install of VisualStudio plugins (vs the Addin model which requires the user to copy it to correct location)
----end----
Here are a number of good resources on this topic (note: which helped find the solution):
- http://www.mztools.com/articles/2008/MZ2008022.aspx
- http://social.msdn.microsoft.com/Forums/en-US/vsx/thread/81c2959c-a21a-4baa-88b2-757ce0769532/
- http://social.msdn.microsoft.com/forums/en-US/vsx/thread/a1d37fdf-09e0-41f9-a045-52a8109b8943
- http://social.msdn.microsoft.com/Forums/en/vsx/thread/806682c2-6c2d-42ac-9efd-696eb66080c2
- http://social.msdn.microsoft.com/Forums/en-US/vsx/thread/b1c37c03-f92b-46b1-83f5-7d54a1bbf5e6/