Skip to content

fix(graph): Support enclosing range for constructors #372

New issue

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

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

Already on GitHub? # to your account

Merged
merged 6 commits into from
Sep 30, 2024

Conversation

mmanela
Copy link
Contributor

@mmanela mmanela commented Sep 19, 2024

Fixed GRAPH-909

When testing enclosing range, I noticed in the snapshot test the constructor was missing the enclosing data. In order to add the change I had to handle some of the forking constructor logic that is in a few places. Getting the range of a constructor node is special-cased so to get the enclosing range, I made a new enclosing range method explicitly excludes the special casing logic.

(I also checked in the vscode launch config that makes it easier to debug this, happy to revert that if needed)

Test plan

  • Validate snapshot
  • Run manually on local index and validate

src/Range.ts Outdated
return Range.getRangeFromNode(rangeNode)
}

public static fromNodeForEnclosing(node: ts.Node): Range {
Copy link
Member

Choose a reason for hiding this comment

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

Any reason to keep this method when it's equivalent to getRangeFromNode?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the comment, it was confusing and I refactored to simplify this.

src/Range.ts Outdated
Comment on lines 38 to 39
// When getting a range of a node a special case is needed for
// the constructor case because it does not have a name node.
Copy link
Contributor

Choose a reason for hiding this comment

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

What is a "name node" here? Nothing else in this diff mentions names. More generally, if we have 2-3 similarly named functions, we should have clear doc comments explain the differences between them.

Looking at the code below, it seems weird that we are falling back to node when getFirstToken() is falsey. Is it even possible to hit that case?

Copy link
Contributor Author

@mmanela mmanela Sep 23, 2024

Choose a reason for hiding this comment

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

  1. Thanks for the feedback, I moved this logic and updated the comment. There is an asymmetry between how function declarations and constructor declarations are handled here. For function declarations the identifierNode is passed into visitSymbolOccurrence while for constructor declarations it's the declaration node itself. This logic (which is now moved) is meant to handle that difference. This logic predates my change.

  2. As for the second point on if firstToken can ever be null. I don't think so in this case, however since the type system requires it to be handled (since its nullable) we can either keep the coalescing or throw beforehand. This coalescing behavior was not added as part of my change here but happy to make this cleaner as part of this.

@mmanela mmanela changed the title Support enclosing range for constructors fix(graph): Support enclosing range for constructors Sep 23, 2024
@mmanela mmanela merged commit 1daf86c into main Sep 30, 2024
7 checks passed
@mmanela mmanela deleted the mmanela-support-enclosing-range-for-constructors branch September 30, 2024 14:26
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants