Roslyn: More information about CodeActions (needs UI, can add Documents)

Created on 9 Oct 2016  路  3Comments  路  Source: dotnet/roslyn

I'm looking at providing CodeActions in a simple web editor prototype (example).

Based on my prototype, I feel that there are two pieces of information that would be useful:

  1. Whether an action needs to display any UI. In a perfect world, maybe the UI could be described in terms generic enough for me to generate a web form. However a flag that I could use to filter would be good enough.
  2. Whether an action can add documents to the project (e.g. "Create class in new file"). Since I'm aiming at a single document support only, I would filter those as well.
Area-IDE Question

All 3 comments

For the second case, they code action itself _should_ be checking if the workspace supports ApplyChangesKind.AddDocument and not offering itself if not.

@mattwar @CyrusNajmabadi do you have any thoughts about 1?

For 1: There is CodeActionWithOptions. This is the base class for code actions that want to pop up UI to the user to collect options that will affect the final result.

Cyrus is correct.

To get a UI to appear for your code action, it is expected that you derive your code action from CodeActionWithOptions and implement GetOptions to put up a UI (winforms?) that results in returning some option state object that is then passed into the ComputeOperationsAsync overload that takes the state object parameter.

Kevin is also correct.

The code action can check the capabilities of the workspace before deciding to offer a fix or refactoring.

Was this page helpful?
0 / 5 - 0 ratings