Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
118 changes: 118 additions & 0 deletions internal/fourslash/baselineutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,124 @@ func (f *FourslashTest) getBaselineOptions(command baselineCommand, testPath str
return strings.ReplaceAll(s, "bundled:///libs/", "")
},
}
case findAllReferencesCmd:
return baseline.Options{
Subfolder: subfolder,
IsSubmodule: true,
DiffFixupOld: func(s string) string {
var commandLines []string
commandPrefix := regexp.MustCompile(`^// === ([a-z\sA-Z]*) ===`)
filePrefix := regexp.MustCompile(`^// === ([^ ]*) ===`)
testFilePrefix := "/tests/cases/fourslash"
serverTestFilePrefix := "/server"
contextSpanOpening := "<|"
contextSpanClosing := "|>"
replacer := strings.NewReplacer(
testFilePrefix, "",
serverTestFilePrefix, "",
contextSpanOpening, "",
contextSpanClosing, "",
)
// Match location data like {| isWriteAccess: true, isDefinition: true |}
objectRangeRegex := regexp.MustCompile(`{\| [^|]* \|}`)
definitionsStr := "// === Definitions ==="
detailsStr := "// === Details ==="
lines := strings.Split(s, "\n")
var isInCommand bool
var isInDetails bool
var isInDefinitions bool

// Track file sections for sorting
type fileSection struct {
fileName string
lines []string
}
var fileSections []fileSection
var currentFileName string
var currentFileLines []string

for _, line := range lines {
matches := commandPrefix.FindStringSubmatch(line)
if len(matches) > 0 {
isInDetails = false
isInDefinitions = false
commandName := matches[1]
if commandName == string(findAllReferencesCmd) {
isInCommand = true
// Starting a new findAllReferences command block
if currentFileName != "" {
fileSections = append(fileSections, fileSection{fileName: currentFileName, lines: currentFileLines})
}
currentFileName = ""
currentFileLines = nil
slices.SortFunc(fileSections, func(a, b fileSection) int {
return strings.Compare(a.fileName, b.fileName)
})
for _, section := range fileSections {
section.lines = dropTrailingEmptyLines(section.lines)
commandLines = append(commandLines, section.lines...)
commandLines = append(commandLines, "")
}
fileSections = nil
if len(commandLines) > 0 {
commandLines = append(commandLines, "", "")
}
commandLines = append(commandLines, replacer.Replace(line))
continue
} else {
isInCommand = false
}
}
if isInCommand {
if strings.Contains(line, definitionsStr) || strings.Contains(line, detailsStr) {
isInDefinitions = strings.Contains(line, definitionsStr)
isInDetails = strings.Contains(line, detailsStr)
// Drop blank line before definitions/details
if len(currentFileLines) > 0 && currentFileLines[len(currentFileLines)-1] == "" {
currentFileLines = currentFileLines[:len(currentFileLines)-1]
}
}
// We don't diff the definitions or details sections
if !(isInDefinitions || isInDetails) {
fixedLine := replacer.Replace(line)
fixedLine = objectRangeRegex.ReplaceAllString(fixedLine, "")

fileMatches := filePrefix.FindStringSubmatch(fixedLine)
if len(fileMatches) > 0 {
if currentFileName != "" {
fileSections = append(fileSections, fileSection{fileName: currentFileName, lines: currentFileLines})
}
currentFileName = fileMatches[1]
currentFileLines = []string{fixedLine}
} else {
currentFileLines = append(currentFileLines, fixedLine)
}
} else if isInDetails && line == " ]" {
isInDetails = false
}
}
}

// Save any remaining file section
if currentFileName != "" {
fileSections = append(fileSections, fileSection{fileName: currentFileName, lines: currentFileLines})
}

// Sort and add remaining file sections
if len(fileSections) > 0 {
slices.SortFunc(fileSections, func(a, b fileSection) int {
return strings.Compare(a.fileName, b.fileName)
})
for _, section := range fileSections {
section.lines = dropTrailingEmptyLines(section.lines)
commandLines = append(commandLines, section.lines...)
commandLines = append(commandLines, "")
}
}

return strings.Join(dropTrailingEmptyLines(commandLines), "\n")
},
}
default:
return baseline.Options{
Subfolder: subfolder,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--- old.autoImportProvider_referencesCrash.baseline.jsonc
+++ new.autoImportProvider_referencesCrash.baseline.jsonc
@@= skipped -0, +0 lines =@@
// === findAllReferences ===
+// === /home/src/workspaces/project/a/index.ts ===
+// class A {}[||]
+
// === /home/src/workspaces/project/b/b.ts ===
// /// <reference path="../a/index.d.ts" />
// new [|A|]/*FIND ALL REFS*/();
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
--- old.explainFilesNodeNextWithTypesReference.baseline.jsonc
+++ new.explainFilesNodeNextWithTypesReference.baseline.jsonc
@@= skipped -0, +0 lines =@@
// === findAllReferences ===
// === /node_modules/react-hook-form/dist/index.d.ts ===
-// /// <reference types="[|react|]/*FIND ALL REFS*/" />
+// /// <reference types="react/*FIND ALL REFS*/" />
// export type Foo = React.Whatever;
// export function useForm(): any;
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--- old.findAllReferencesFromLinkTagReference2.baseline.jsonc
+++ new.findAllReferencesFromLinkTagReference2.baseline.jsonc
@@= skipped -1, +1 lines =@@
// === /a.ts ===
// enum E {
// /** {@link /*FIND ALL REFS*/[|Foo|]} */
-// Foo
+// [|Foo|]
// }
-// interface [|Foo|] {
-// foo: E.Foo;
+// interface Foo {
+// foo: E.[|Foo|];
// }
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--- old.findAllReferencesFromLinkTagReference3.baseline.jsonc
+++ new.findAllReferencesFromLinkTagReference3.baseline.jsonc
@@= skipped -0, +0 lines =@@
// === findAllReferences ===
// === /a.ts ===
-// interface [|Foo|] {
-// foo: E.Foo;
+// interface Foo {
+// foo: E.[|Foo|];
// }

// === /b.ts ===
// enum E {
// /** {@link /*FIND ALL REFS*/[|Foo|]} */
-// Foo
+// [|Foo|]
// }
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
--- old.findAllReferencesJSDocFunctionNew.baseline.jsonc
+++ new.findAllReferencesJSDocFunctionNew.baseline.jsonc
@@= skipped -0, +0 lines =@@
// === findAllReferences ===
// === /Foo.js ===
-// /** @type {function (/*FIND ALL REFS*/[|new|]: string, string): string} */
+// /** @type {function (/*FIND ALL REFS*/new: string, string): string} */
// var f;
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--- old.findAllReferencesJsRequireDestructuring.baseline.jsonc
+++ new.findAllReferencesJsRequireDestructuring.baseline.jsonc
@@= skipped -0, +0 lines =@@
// === findAllReferences ===
// === /bar.js ===
// const { /*FIND ALL REFS*/[|foo|]: bar } = require('./foo');
-
-// === /foo.js ===
-// module.exports = {
-// [|foo|]: '1'
-// };
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
--- old.findAllReferencesJsRequireDestructuring1.baseline.jsonc
+++ new.findAllReferencesJsRequireDestructuring1.baseline.jsonc
@@= skipped -0, +0 lines =@@
// === findAllReferences ===
-// === /X.js ===
-// module.exports = { [|x|]: 1 };
-
// === /Y.js ===
// const { /*FIND ALL REFS*/[|x|]: { y } } = require("./X");
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--- old.findAllReferencesLinkTag1.baseline.jsonc
+++ new.findAllReferencesLinkTag1.baseline.jsonc
@@= skipped -174, +174 lines =@@
// */
// r() { }
// }
-//
-// interface I {
-// a()
-// --- (line: 38) skipped ---
+// --- (line: 35) skipped ---



@@= skipped -33, +30 lines =@@
// */
// d()
// }
-//
-// function nestor() {
-// /** {@link r2} */
-// --- (line: 59) skipped ---
+// --- (line: 56) skipped ---
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
--- old.findAllReferencesTripleSlash.baseline.jsonc
+++ new.findAllReferencesTripleSlash.baseline.jsonc
@@= skipped -0, +0 lines =@@
// === findAllReferences ===
// === /a.ts ===
-// /// <reference path="[|b.ts|]/*FIND ALL REFS*/" />
+// /// <reference path="b.ts/*FIND ALL REFS*/" />
// /// <reference types="globals" />

-// === /c.js ===
-// require([|"./b"|]);
-// require("globals");
-


// === findAllReferences ===
// === /a.ts ===
// /// <reference path="b.ts" />
-// /// <reference types="[|globals|]/*FIND ALL REFS*/" />
-
-// === /c.js ===
-// require("./b");
-// require([|"globals"|]);
+// /// <reference types="globals/*FIND ALL REFS*/" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--- old.findAllReferencesUmdModuleAsGlobalConst.baseline.jsonc
+++ new.findAllReferencesUmdModuleAsGlobalConst.baseline.jsonc
@@= skipped -5, +5 lines =@@


// === findAllReferences ===
+// === /node_modules/@types/three/index.d.ts ===
+// export * from "[|./three-core|]";
+// export as namespace THREE;
+
// === /typings/global.d.ts ===
// import * as _THREE from '/*FIND ALL REFS*/[|three|]';
// declare global {
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
--- old.findAllRefsClassExpression1.baseline.jsonc
+++ new.findAllRefsClassExpression1.baseline.jsonc
@@= skipped -1, +1 lines =@@
// === /a.js ===
// module.exports = class /*FIND ALL REFS*/[|A|] {};

-// === /b.js ===
-// import [|A|] = require("./a");
-// [|A|];
-


// === findAllReferences ===
-// === /a.js ===
-// module.exports = class [|A|] {};
-
// === /b.js ===
// import /*FIND ALL REFS*/[|A|] = require("./a");
// [|A|];
@@= skipped -17, +10 lines =@@


// === findAllReferences ===
-// === /a.js ===
-// module.exports = class [|A|] {};
-
// === /b.js ===
// import [|A|] = require("./a");
// /*FIND ALL REFS*/[|A|];
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--- old.findAllRefsCommonJsRequire3.baseline.jsonc
+++ new.findAllRefsCommonJsRequire3.baseline.jsonc
@@= skipped -0, +0 lines =@@
// === findAllReferences ===
-// === /a.js ===
-// function [|f|]() { }
-// module.exports = { [|f|] }
-
// === /b.js ===
// const { [|f|] } = require('./a')
// /*FIND ALL REFS*/[|f|]
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
--- old.findAllRefsConstructorFunctions.baseline.jsonc
+++ new.findAllRefsConstructorFunctions.baseline.jsonc
@@= skipped -12, +12 lines =@@
// === findAllReferences ===
// === /a.js ===
// function f() {
-// this./*FIND ALL REFS*/[|x|] = 0;
+// this./*FIND ALL REFS*/x = 0;
// }
// f.prototype.setX = function() {
-// this.[|x|] = 1;
+// this.x = 1;
// }
-// f.prototype.useX = function() { this.[|x|]; }
+// f.prototype.useX = function() { this.x; }



@@= skipped -24, +24 lines =@@
// === findAllReferences ===
// === /a.js ===
// function f() {
-// this.[|x|] = 0;
+// this.x = 0;
// }
// f.prototype.setX = function() {
-// this./*FIND ALL REFS*/[|x|] = 1;
+// this./*FIND ALL REFS*/x = 1;
// }
-// f.prototype.useX = function() { this.[|x|]; }
+// f.prototype.useX = function() { this.x; }



// === findAllReferences ===
// === /a.js ===
-// function f() {
-// this.[|x|] = 0;
-// }
+// --- (line: 3) skipped ---
// f.prototype.setX = function() {
-// this.[|x|] = 1;
+// this.x = 1;
// }
-// f.prototype.useX = function() { this./*FIND ALL REFS*/[|x|]; }
+// f.prototype.useX = function() { this./*FIND ALL REFS*/x; }
Loading
Loading