qsharp-compiler icon indicating copy to clipboard operation
qsharp-compiler copied to clipboard

Extensible diagnostics in design time builds

Open bamarsha opened this issue 5 years ago • 3 comments

Is your feature request related to a problem? Please describe. The compiler has support for running arbitrary code on the Q# syntax tree during compilation in the form of the IRewriteStep interface. Rewrite steps can also generate arbitrary diagnostics that are displayed at build time. Unfortunately, rewrite steps don't run at design time when using the Q# language server, which means things like linters are limited to the command line, and can't provide live feedback in an editor.

Describe the solution you'd like The compiler should provide some mechanism to run arbitrary diagnostic-generating code analysis in design-time builds, similar to Roslyn analyzers.

Describe alternatives you've considered No known alternatives that don't involve modifying the language server.

Additional context This would have been useful for the runtime capabilities diagnostics (#449, #488). Those had to be built into the compiler, but they are not needed for compilation. Extensible diagnostics would make this kind of static analysis easier to add in a modular way.

bamarsha avatar Jul 28 '20 23:07 bamarsha

One important concern that was brought up about invoking too much of the IRewriteStep infrastructure is the overall impact on performance. We definitely want to keep the language server performant, as having the design time feedback be fast is key to providing a good IDE experience.

swernli avatar Jul 30 '20 21:07 swernli

Yes, running all of the rewrite steps in full should probably be avoided. We could add a method that IRewriteSteps could implement that would only return diagnostics, which depending on the rewrite step could be implemented in a more efficient way. Another way is to make a separate plugin interface for analyzers only.

bamarsha avatar Jul 30 '20 22:07 bamarsha

I can think of two hooks in the compiler that could be used to generate diagnostics:

  1. When a specialization is recompiled
  2. When global type checking runs

I feel like having a way to listen for just these two events could take care of a lot of diagnostics in a more modular way.

bamarsha avatar Jan 25 '22 21:01 bamarsha