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

API request: IOperation ancestor extension methods #52583

Open
jnm2 opened this issue Apr 12, 2021 · 1 comment
Open

API request: IOperation ancestor extension methods #52583

jnm2 opened this issue Apr 12, 2021 · 1 comment
Assignees
Labels
Area-Analyzers Concept-Design Debt Engineering Debt, Design Debt, or poor product code quality Need Design Review The end user experience design needs to be reviewed and approved.
Milestone

Comments

@jnm2
Copy link
Contributor

jnm2 commented Apr 12, 2021

Please provide public extension methods Ancestors(), AncestorsAndSelf(), and FirstAncestorOrSelf<T> on IOperation just like the ones publicly provided on SyntaxNode.

I write these helpers in many of my own projects and just recently added them inside an IDE enhancement I contributed.

Here's a usage example from one of the recent times I wrote my own Ancestors extension method:

public static bool IsInsideExpressionTree(IOperation operation)
{
    return operation.Ancestors()
        .Select(ancestor => (ancestor as IAnonymousFunctionOperation)?.Parent as IConversionOperation)
        .FirstOrDefault(functionConversion => functionConversion is not null) is
        {
            Type: { OriginalDefinition: { } anonymousFunctionType },
        }
        && anonymousFunctionType.HasFullName("System", "Linq", "Expressions", nameof(System.Linq.Expressions.Expression));
}
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Analyzers untriaged Issues and PRs which have not yet been triaged by a lead labels Apr 12, 2021
@CyrusNajmabadi
Copy link
Member

I strongly think we should do this. We have a put forth a very opinionated tree-api with our syntax models. That tree api comes with lots of niceties in terms of things like navigation/querying. As much as is sensible, the same tree-oriented apis should be available for IOp.

@jinujoseph jinujoseph added Concept-Design Debt Engineering Debt, Design Debt, or poor product code quality Need Design Review The end user experience design needs to be reviewed and approved. and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Apr 20, 2021
@jinujoseph jinujoseph added this to In Queue in IDE: Design review via automation Apr 20, 2021
@jinujoseph jinujoseph added this to the Backlog milestone Apr 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Analyzers Concept-Design Debt Engineering Debt, Design Debt, or poor product code quality Need Design Review The end user experience design needs to be reviewed and approved.
Projects
Status: In Queue
IDE: Design review
  
In Queue
Development

No branches or pull requests

4 participants