Skip to content

Conversation

@gabritto
Copy link
Member

@gabritto gabritto commented Apr 17, 2025

The new code ports the original findPrecedingToken as faithfully as possible.

From the baselines, there are two differences:

  1. The range of some returned tokens is different in Corsa.
  2. In Strada, when the position is inside a JSDoc comment that has no tags, findPrecedingToken returns undefined. In Corsa, right now, we return the JSDoc. I am not sure if this difference matters or how to properly deal with that, so I thought I should leave this as a future work item.

@gabritto gabritto requested review from andrewbranch, Copilot and navya9singh and removed request for Copilot April 17, 2025 19:45
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (3)

internal/astnav/tokens_test.go:79

  • [nitpick] Consider adding an inline comment to explain the purpose of the 'includeEOF' parameter, which would help clarify its intended effect in token retrieval.
func baselineTokens(t *testing.T, testName string, includeEOF bool, getTSTokens func(fileText string, positions []int) []*tokenInfo, getGoToken func(file *ast.SourceFile, pos int) *tokenInfo) {

internal/astnav/tokens_test.go:239

  • [nitpick] Document the newly introduced 'position' parameter in writeRangeDiff to clarify how it influences the computation of token positions in the diff output.
func writeRangeDiff(output *strings.Builder, file *ast.SourceFile, diff tokenDiff, rng core.TextRange, position int) {

internal/astnav/tokens.go:395

  • Instead of panicking when a whitespace-only token is encountered, consider handling this case gracefully (for example by returning an error or a fallback token) to avoid potential runtime crashes in production.
if result != nil && ast.IsWhitespaceOnlyJsxText(result) { panic("Expected result to be a non-whitespace token.") }

Copy link
Member

@andrewbranch andrewbranch left a comment

Choose a reason for hiding this comment

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

Baseline diff looks good—I think those are Strada bugs (that probably never matter in practice).

@gabritto gabritto added this pull request to the merge queue Apr 18, 2025
Merged via the queue into main with commit 28722fa Apr 18, 2025
23 checks passed
@gabritto gabritto deleted the gabritto/findpreceding branch April 18, 2025 15:08
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