Skip to content

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

Merged
mmanela merged 6 commits into
mainfrom
mmanela-support-enclosing-range-for-constructors
Sep 30, 2024
Merged

fix(graph): Support enclosing range for constructors#372
mmanela merged 6 commits into
mainfrom
mmanela-support-enclosing-range-for-constructors

Conversation

@mmanela

@mmanela mmanela commented Sep 19, 2024

Copy link
Copy Markdown
Contributor

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

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

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

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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.

Comment thread 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
Copy Markdown
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?

@mmanela mmanela Sep 23, 2024

Copy link
Copy Markdown
Contributor Author

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
@mmanela mmanela deleted the mmanela-support-enclosing-range-for-constructors branch September 30, 2024 14:26
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.

3 participants