Skip to content

Commit 10cc19f

Browse files
authored
Diff findAllReferences (microsoft#2605)
1 parent 9541870 commit 10cc19f

397 files changed

Lines changed: 1710 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

internal/fourslash/baselineutil.go

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,124 @@ func (f *FourslashTest) getBaselineOptions(command baselineCommand, testPath str
324324
return strings.ReplaceAll(s, "bundled:///libs/", "")
325325
},
326326
}
327+
case findAllReferencesCmd:
328+
return baseline.Options{
329+
Subfolder: subfolder,
330+
IsSubmodule: true,
331+
DiffFixupOld: func(s string) string {
332+
var commandLines []string
333+
commandPrefix := regexp.MustCompile(`^// === ([a-z\sA-Z]*) ===`)
334+
filePrefix := regexp.MustCompile(`^// === ([^ ]*) ===`)
335+
testFilePrefix := "/tests/cases/fourslash"
336+
serverTestFilePrefix := "/server"
337+
contextSpanOpening := "<|"
338+
contextSpanClosing := "|>"
339+
replacer := strings.NewReplacer(
340+
testFilePrefix, "",
341+
serverTestFilePrefix, "",
342+
contextSpanOpening, "",
343+
contextSpanClosing, "",
344+
)
345+
// Match location data like {| isWriteAccess: true, isDefinition: true |}
346+
objectRangeRegex := regexp.MustCompile(`{\| [^|]* \|}`)
347+
definitionsStr := "// === Definitions ==="
348+
detailsStr := "// === Details ==="
349+
lines := strings.Split(s, "\n")
350+
var isInCommand bool
351+
var isInDetails bool
352+
var isInDefinitions bool
353+
354+
// Track file sections for sorting
355+
type fileSection struct {
356+
fileName string
357+
lines []string
358+
}
359+
var fileSections []fileSection
360+
var currentFileName string
361+
var currentFileLines []string
362+
363+
for _, line := range lines {
364+
matches := commandPrefix.FindStringSubmatch(line)
365+
if len(matches) > 0 {
366+
isInDetails = false
367+
isInDefinitions = false
368+
commandName := matches[1]
369+
if commandName == string(findAllReferencesCmd) {
370+
isInCommand = true
371+
// Starting a new findAllReferences command block
372+
if currentFileName != "" {
373+
fileSections = append(fileSections, fileSection{fileName: currentFileName, lines: currentFileLines})
374+
}
375+
currentFileName = ""
376+
currentFileLines = nil
377+
slices.SortFunc(fileSections, func(a, b fileSection) int {
378+
return strings.Compare(a.fileName, b.fileName)
379+
})
380+
for _, section := range fileSections {
381+
section.lines = dropTrailingEmptyLines(section.lines)
382+
commandLines = append(commandLines, section.lines...)
383+
commandLines = append(commandLines, "")
384+
}
385+
fileSections = nil
386+
if len(commandLines) > 0 {
387+
commandLines = append(commandLines, "", "")
388+
}
389+
commandLines = append(commandLines, replacer.Replace(line))
390+
continue
391+
} else {
392+
isInCommand = false
393+
}
394+
}
395+
if isInCommand {
396+
if strings.Contains(line, definitionsStr) || strings.Contains(line, detailsStr) {
397+
isInDefinitions = strings.Contains(line, definitionsStr)
398+
isInDetails = strings.Contains(line, detailsStr)
399+
// Drop blank line before definitions/details
400+
if len(currentFileLines) > 0 && currentFileLines[len(currentFileLines)-1] == "" {
401+
currentFileLines = currentFileLines[:len(currentFileLines)-1]
402+
}
403+
}
404+
// We don't diff the definitions or details sections
405+
if !(isInDefinitions || isInDetails) {
406+
fixedLine := replacer.Replace(line)
407+
fixedLine = objectRangeRegex.ReplaceAllString(fixedLine, "")
408+
409+
fileMatches := filePrefix.FindStringSubmatch(fixedLine)
410+
if len(fileMatches) > 0 {
411+
if currentFileName != "" {
412+
fileSections = append(fileSections, fileSection{fileName: currentFileName, lines: currentFileLines})
413+
}
414+
currentFileName = fileMatches[1]
415+
currentFileLines = []string{fixedLine}
416+
} else {
417+
currentFileLines = append(currentFileLines, fixedLine)
418+
}
419+
} else if isInDetails && line == " ]" {
420+
isInDetails = false
421+
}
422+
}
423+
}
424+
425+
// Save any remaining file section
426+
if currentFileName != "" {
427+
fileSections = append(fileSections, fileSection{fileName: currentFileName, lines: currentFileLines})
428+
}
429+
430+
// Sort and add remaining file sections
431+
if len(fileSections) > 0 {
432+
slices.SortFunc(fileSections, func(a, b fileSection) int {
433+
return strings.Compare(a.fileName, b.fileName)
434+
})
435+
for _, section := range fileSections {
436+
section.lines = dropTrailingEmptyLines(section.lines)
437+
commandLines = append(commandLines, section.lines...)
438+
commandLines = append(commandLines, "")
439+
}
440+
}
441+
442+
return strings.Join(dropTrailingEmptyLines(commandLines), "\n")
443+
},
444+
}
327445
default:
328446
return baseline.Options{
329447
Subfolder: subfolder,

testdata/baselines/reference/fourslash/findAllReferences/ambientShorthandFindAllRefs.baseline.jsonc renamed to testdata/baselines/reference/submodule/fourslash/findAllReferences/ambientShorthandFindAllRefs.baseline.jsonc

File renamed without changes.

testdata/baselines/reference/fourslash/findAllReferences/autoImportProvider_referencesCrash.baseline.jsonc renamed to testdata/baselines/reference/submodule/fourslash/findAllReferences/autoImportProvider_referencesCrash.baseline.jsonc

File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--- old.autoImportProvider_referencesCrash.baseline.jsonc
2+
+++ new.autoImportProvider_referencesCrash.baseline.jsonc
3+
@@= skipped -0, +0 lines =@@
4+
// === findAllReferences ===
5+
+// === /home/src/workspaces/project/a/index.ts ===
6+
+// class A {}[||]
7+
+
8+
// === /home/src/workspaces/project/b/b.ts ===
9+
// /// <reference path="../a/index.d.ts" />
10+
// new [|A|]/*FIND ALL REFS*/();

testdata/baselines/reference/fourslash/findAllReferences/constructorFindAllReferences1.baseline.jsonc renamed to testdata/baselines/reference/submodule/fourslash/findAllReferences/constructorFindAllReferences1.baseline.jsonc

File renamed without changes.

testdata/baselines/reference/fourslash/findAllReferences/constructorFindAllReferences2.baseline.jsonc renamed to testdata/baselines/reference/submodule/fourslash/findAllReferences/constructorFindAllReferences2.baseline.jsonc

File renamed without changes.

testdata/baselines/reference/fourslash/findAllReferences/constructorFindAllReferences3.baseline.jsonc renamed to testdata/baselines/reference/submodule/fourslash/findAllReferences/constructorFindAllReferences3.baseline.jsonc

File renamed without changes.

testdata/baselines/reference/fourslash/findAllReferences/constructorFindAllReferences4.baseline.jsonc renamed to testdata/baselines/reference/submodule/fourslash/findAllReferences/constructorFindAllReferences4.baseline.jsonc

File renamed without changes.

testdata/baselines/reference/fourslash/findAllReferences/duplicatePackageServices.baseline.jsonc renamed to testdata/baselines/reference/submodule/fourslash/findAllReferences/duplicatePackageServices.baseline.jsonc

File renamed without changes.

testdata/baselines/reference/fourslash/findAllReferences/esModuleInteropFindAllReferences.baseline.jsonc renamed to testdata/baselines/reference/submodule/fourslash/findAllReferences/esModuleInteropFindAllReferences.baseline.jsonc

File renamed without changes.

0 commit comments

Comments
 (0)