-
Notifications
You must be signed in to change notification settings - Fork 659
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
base: main
Are you sure you want to change the base?
Conversation
…o fourslash-baseline
…o fourslash-baseline
There was a problem hiding this 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 |
There was a problem hiding this 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. |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Position: f.currentCaretPosition, | ||
}, | ||
Context: &lsproto.CompletionContext{}, | ||
TextDocumentPositionParams: f.currentTextDocumentPositionParams(), |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
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 { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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), |
There was a problem hiding this comment.
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 === |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
VerifyBaselinefindAllReferences
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