0

I have a Roslyn code analyzer that takes a lot of time to run, so running it either at compilation start or as a whole tree analysis is not appropriate.

Instead I would like to have the analysis trigger when the user clicks on a button in the menu (or toolbar/keyboard shortcut).

Is this possible? If not, is there a way for a traditional MEF extension to access the Roslyn tree of an opened document and to add errors/warnings to the Error List and corresponding squigglies under the syntax nodes in the document?

Petr Hudeček
  • 1,623
  • 19
  • 30

1 Answers1

0

Roslyn analyzers can only be triggered by Roslyn; you can't do that.

You can access Roslyn from traditional VS extensions by injecting VisualStudioWorkspace in any MEF component. There are a bunch of extension methods in Microsoft.CodeAnalysis.EditorFeatures.Text to map between Roslyn nodes / documents and VS buffers / snapshots.

You can report errors using the standard VS error APIs; you may also want to look at the code in Roslyn that reports Roslyn errors.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964