Skip to content

fourslash baselines and VerifyBaselinefindAllReferences #1274

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

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

iisaduan
Copy link
Member

@iisaduan iisaduan commented Jun 23, 2025

Ports most of the baselining for fourslash (the functions that format FS content with range and location markers). There are features I did not port because they were not used in the baselines that I was porting/the functions I know that are planned on be ported pretty directly. I'm leaving those features unimplemented for now in case they are used differently/no longer used

Also adds VerifyBaselineFindAllReferences as an example of how to use the new baseline

@iisaduan iisaduan marked this pull request as ready for review July 3, 2025 22:17
@Copilot Copilot AI review requested due to automatic review settings July 3, 2025 22:17
Copy link
Contributor

@Copilot 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.

Pull Request Overview

Adds a comprehensive suite of draft “find all references” tests to the fourslash harness, covering TSX, runtime imports, JS exports, and many language constructs.

  • Introduces TSX-specific findAllReferences test (tsxFindAllReferences10_test.go).
  • Adds path-mapped tslib import reference tests and JS export rename tests.
  • Generates dozens of new tests under internal/fourslash/tests/gen/ to exercise edge cases.

Reviewed Changes

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

Show a summary per file
File Description
internal/fourslash/tests/gen/tsxFindAllReferences10_test.go Add TSX component findAllReferences baseline test
internal/fourslash/tests/gen/tslibFindAllReferencesOnRuntimeImportWithPaths1_test.go Add findAllReferences test for tslib imports with custom paths
internal/fourslash/tests/gen/renameJsExports03_test.go Add JS export renaming reference test
internal/fourslash/tests/gen/renameJsExports02_test.go Add second JS export rename test
internal/fourslash/tests/gen/remoteGetReferences_test.go Add remote reference resolution tests
internal/fourslash/tests/gen/referencesToStringLiteralValue_test.go Add string-literal reference tests
... Many additional generated tests covering properties, keywords, merges, modules, enums, JSX, JSDoc, and more

Copy link
Member

@gabritto gabritto left a comment

Choose a reason for hiding this comment

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

Some minor comments (mostly about recent updates I made that may conflict, sorry) and a question, but in general looks good.

// If the actual position was not found, the binary search returns where the target line start would be inserted
// if the target was in the slice.
// e.g. if the line starts at [5, 10, 23, 80] and the position requested was 20
// then the search will return -3.
Copy link
Member

Choose a reason for hiding this comment

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

This comment probably needs updating, since the Corsa version will return (3, false) instead of -3.

f.ensureActiveFile(t, fileName)
f.currentCaretPosition = pos
f.activeFilename = fileName
// !!! this.selectionEnd = -1
Copy link
Member

Choose a reason for hiding this comment

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

I recently added selectionEnd in #1310 and GoToRangeStart in #1357, so this probably needs updating.

Position: f.currentCaretPosition,
},
Context: &lsproto.CompletionContext{},
TextDocumentPositionParams: f.currentTextDocumentPositionParams(),
Copy link
Member

Choose a reason for hiding this comment

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

:)

referenceLocations = core.Map(markers, func(markerName string) MarkerOrRange {
marker, ok := f.testData.MarkerPositions[markerName]
if !ok {
t.Fatalf("Marker %s not found", markerName)
Copy link
Member

Choose a reason for hiding this comment

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

nit:

Suggested change
t.Fatalf("Marker %s not found", markerName)
t.Fatalf("Marker '%s' not found", markerName)

@@ -75,8 +105,12 @@ func ParseTestData(t *testing.T, contents string, fileName string) TestData {
markers = append(markers, file.markers...)
ranges = append(ranges, file.ranges...)
for _, marker := range file.markers {
if _, ok := markerPositions[marker.Name]; ok {
t.Fatalf("Duplicate marker name: %s", marker.Name)
if marker.Name == "" && marker.Data != nil {
Copy link
Member

Choose a reason for hiding this comment

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

I fixed this in #1357 by having a marker name be *string instead of string, since in Strada, so probably no need for this change now except for the improved error message.


func (f *FourslashTest) getBaselineForGroupedLocationsWithFileContents(groupedLocations *collections.MultiMap[lsproto.DocumentUri, *lsproto.Location], options baselineFourslashLocationsOptions) string {
baselineEntries := []string{}
err := f.server.FS().WalkDir("/", func(path string, d vfs.DirEntry, e error) error {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
err := f.server.FS().WalkDir("/", func(path string, d vfs.DirEntry, e error) error {
err := f.vfs.WalkDir("/", func(path string, d vfs.DirEntry, e error) error {


readableContents: &strings.Builder{},

isLibFile: regexp.MustCompile(`/lib.*\.d\.ts$/`).MatchString(fileName),
Copy link
Member

Choose a reason for hiding this comment

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

Should this be regexp.MustCompile(`lib.*\.d\.ts$`)?

@@ -0,0 +1,12 @@
// === findAllReferences ===
Copy link
Member

Choose a reason for hiding this comment

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

This looks different from the original baseline file in Strada, right? Where in the code are we accounting for those differences such that tests don't fail?

Copy link
Member Author

Choose a reason for hiding this comment

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

The findAllReferences tests aren't being run against the submodule yet, they are just a standard "has the baseline changed" test. For FAR specifically, in corsa we currently only compute the locations of references--so most of the stuff that is in corsa's baseline (the json structures) is just info that is no longer computed.

@iisaduan iisaduan changed the title [draft] find all references fourslash fourslash baselines and VerifyBaselinefindAllReferences Jul 4, 2025
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.

2 participants