Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Order code actions #1078

Merged
merged 15 commits into from
Jan 10, 2018
Merged

Order code actions #1078

merged 15 commits into from
Jan 10, 2018

Conversation

akshita31
Copy link
Contributor

@akshita31 akshita31 commented Jan 2, 2018

Fixes : #758

To order code actions we can order the providers based on the ExtensionOrder attribute in roslyn.There are two types of providers - CodeFixProvider and CodeRefactoringProvider. For each of these categories we perform the following on a list of providers :

  1. For each provider create a ProviderNode that includes the Before and After strings and the ProviderName
  2. Create a dictionary that includes a mapping from the provider name to the providernode
  3. Create a graph based on the Before and After properties of the node using the dictionary created above
  4. Perform topological sorting on the nodes.

Please review @DustinCampbell @TheRealPiotrP @rchande @filipw


namespace OmniSharp.Roslyn.CSharp.Services.Refactoring.V2
{
internal class Graph<T>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this adapted from Roslyn?

Copy link
Contributor Author

@akshita31 akshita31 Jan 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is taken from Extension Orderer used by Roslyn and modified a bit for the current case.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, we might want to add a comment stating as such.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DustinCampbell can we get that API opened up publicly? 😀

}
}

var graph = Graph<CodeFixProvider>.GetGraph(nodesList);
return graph.TopologicalSort();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we cache this? (Eg, does the total set of CodeFixProviders change)

@@ -23,6 +23,8 @@ public abstract class BaseCodeActionService<TRequest, TResponse> : IRequestHandl
{
protected readonly OmniSharpWorkspace Workspace;
protected readonly IEnumerable<ICodeActionProvider> Providers;
protected List<CodeFixProvider> OrderedCodeFixProviders;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can make this a Lazy<IEnumerable<CodeFixProvider> and initialize it like

_lazyFixProviders = new Lazy(() => GetOrderedProviders)```

That will let you avoid some of the crazy exception handling below.

private void SetOrderedProviders()
{
try
{
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this in a try/catch? What are you expecting to fail?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the GetSortedCodeFixProviders() will return an exception if there are cycles in the graph. This try catch will handle the exception and return the unordered list if that exception occurs

Copy link
Member

@david-driscoll david-driscoll left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rchande your last comments seem to be resolved. Change looks good to me. 👍

Copy link

@rchande rchande left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM-Thanks!

@filipw
Copy link
Member

filipw commented Jan 10, 2018

green!

@filipw filipw merged commit e00f370 into OmniSharp:master Jan 10, 2018
@akshita31 akshita31 deleted the order_codeProviders branch January 10, 2018 18:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants