Roslyn access to CodeLens data?

Topics: APIs, General
Nov 1, 2014 at 6:56 PM
Hey,

I was wondering, how difficult would it be to expose the CodeLens APIs to Roslyn somehow?
Reason for asking: I think it would be very useful to be able to have meta-code diagnostics. For example, warnings such as:
  • This method it not covered by any unittests. {lightbulb} Create test
  • This method has not gone through a code review. {lightbulb} Create review request
Things like that..

Is it possible to do code analysis at this level somehow?
Developer
Nov 13, 2014 at 3:50 PM
Apologies, Ron, I just noticed that this thread hadn't gotten an answer. Unfortunately, regarding exposing CodeLens itself, all I can give is a non-answer at the moment. :-( We don't currently have any plans to do this -- CodeLens lives outside Roslyn, and it's not good for us to hard-code pipes through to it because then they have to be supported going forward, no matter how CodeLens evolves in the future.

With respect to the scenario you mention -- diagnostics are pretty much limited only by your imagination. (I've been joking here recently that the standard answer nowadays for any coding ambiguity we find on the dev team is "let's create a diagnostic for that.") Although the primary intent is for you to be able to interrogate the symbolic/syntactic information available and create a fix to act on it, there's nothing stopping you from (for example) getting the name of a method and using that to look up test runs in some database somewhere, assuming there was access to that DB -- failing to find any such test run, you could then broadcast a warning/error as usual. As far as lightbulbs go -- the way to show a lightbulb is to register a fix, but you want to be careful because, if you register a fix so as to show the lightbulb, we still need to return a Task<Solution> value that isn't null even if you aren't offering any actually code changes, because that will cause an exception and lightbulbs will go away altogether (which is a bug I just found while trying this out, & will file).

--Matt--*
Developer
Nov 13, 2014 at 5:34 PM
(Should have added that, for a "fix" that does nothing, it's OK to simply return the document that you were passed.)