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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions tsc/internal/fourslash/fourslash.go
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@ func (f *FourslashTest) goToPosition(t *testing.T, position lsproto.Position) {

func (f *FourslashTest) GoToEachMarker(t *testing.T, markerNames []string, action func(marker *Marker, index int)) {
var markers []*Marker
if len(markers) == 0 {
if len(markerNames) == 0 {
markers = f.Markers()
} else {
markers = make([]*Marker, 0, len(markerNames))
Expand Down Expand Up @@ -4896,7 +4896,10 @@ func (f *FourslashTest) VerifyRenameSucceeded(t *testing.T, preferences *lsutil.
Position: f.currentCaretPosition,
NewName: "RENAME_SUCCEEDED_TEST",
})
if renameResult.WorkspaceEdit == nil || renameResult.WorkspaceEdit.Changes == nil || len(*renameResult.WorkspaceEdit.Changes) == 0 {
edit := renameResult.WorkspaceEdit
if edit == nil ||
((edit.Changes == nil || len(*edit.Changes) == 0) &&
(edit.DocumentChanges == nil || len(*edit.DocumentChanges) == 0)) {
t.Fatal(prefix + "prepareRename succeeded but textDocument/rename returned no changes")
}
}
Expand Down Expand Up @@ -5229,7 +5232,10 @@ func (f *FourslashTest) VerifyRenameFailed(t *testing.T, preferences *lsutil.Use
if renameMsg != nil && renameMsg.AsResponse().Error != nil {
return
}
if renameResult.WorkspaceEdit != nil && renameResult.WorkspaceEdit.Changes != nil && len(*renameResult.WorkspaceEdit.Changes) > 0 {
edit := renameResult.WorkspaceEdit
if edit != nil &&
((edit.Changes != nil && len(*edit.Changes) > 0) ||
(edit.DocumentChanges != nil && len(*edit.DocumentChanges) > 0)) {
t.Fatalf("%sprepareRename returned null but textDocument/rename returned changes", prefix)
}
}
Expand Down
49 changes: 49 additions & 0 deletions tsc/internal/fourslash/fourslash_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package fourslash

import (
"slices"
"testing"

"github.com/microsoft/TypeScript/tsc/internal/lsp/lsproto"
)

func newMarkerTest(t *testing.T) *FourslashTest {
data := ParseTestData(t, `const /*first*/x = /*second*/1; /*third*/`, "markers.ts")
return &FourslashTest{
testData: &data,
activeFilename: data.Markers[0].FileName(),
}
}

func TestGoToEachMarker(t *testing.T) {
t.Parallel()
for _, tt := range []struct {
name string
selected []string
want []string
}{
{name: "all", want: []string{"first", "second", "third"}},
{name: "empty", selected: []string{}, want: []string{"first", "second", "third"}},
{name: "subset", selected: []string{"second"}, want: []string{"second"}},
{name: "ordered duplicates", selected: []string{"third", "first", "third"}, want: []string{"third", "first", "third"}},
} {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
f := newMarkerTest(t)
var visited []string
f.GoToEachMarker(t, tt.selected, func(marker *Marker, index int) {
if index != len(visited) {
t.Errorf("callback index = %d, want %d", index, len(visited))
}
if f.currentCaretPosition != marker.LSPos() || f.lastKnownMarkerName != marker.GetName() || f.selectionEnd != nil {
t.Error("callback did not observe navigation to its marker")
}
visited = append(visited, *marker.Name)
f.selectionEnd = new(lsproto.Position{})
})
if !slices.Equal(visited, tt.want) {
t.Fatalf("visited %v, want %v", visited, tt.want)
}
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ func TestFindAllRefs_importType_js(t *testing.T) {
const content = `// @allowJs: true
// @checkJs: true
// @Filename: /a.js
/**/module.exports = class C {};
module.exports.D = class D {};
class C {}
C.D = class D {};
/**/module.exports = C;
// @Filename: /b.js
/** @type {import("./a")} */
const x = 0;
/** @type {import("./a").D} */
/** @type {InstanceType<typeof import("./a").D>} */
const y = 0;`
f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content)
defer done()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ export const x = 0;
// @Filename: /dir/index.ts
export const x = 0;
// @Filename: /b.ts
import * as a from "./[|a|]";
import * as dir from "./[|dir|]";
import * as dir2 from "./dir/[|index|]";
import * as a from "./[|/*a*/a|]";
import * as dir from "./[|/*dir*/dir|]";
import * as dir2 from "./dir/[|/*index*/index|]";
// @Filename: /c.js
const a = require("./[|a|]");
`
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// === findAllReferences ===
// === /a.js ===
// /** @template /*FIND ALL REFS*/T */
// class C {
// constructor() {
// /** @type {T} */
// --- (line: 5) skipped ---



// === findAllReferences ===
// === /a.js ===
// /** @template T */
// class C {
// constructor() {
// /** @type {/*FIND ALL REFS*/[|T|]} */
// this.x = null;
// }
// }
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// === findAllReferences ===
// === /a.js ===
// /**
// * @template /*FIND ALL REFS*/T
// * @return {T}
// */
// function f() {}



// === findAllReferences ===
// === /a.js ===
// /**
// * @template T
// * @return {/*FIND ALL REFS*/[|T|]}
// */
// function f() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// === findAllReferences ===
// === /a.js ===
// /** /*FIND ALL REFS*/@typedef {number} T */
//
// /**
// * @return {T}
// --- (line: 5) skipped ---



// === findAllReferences ===
// === /a.js ===
// /** @typedef {number} /*FIND ALL REFS*/[|T|] */
//
// /**
// * @return {[|T|]}
// */
// function f(obj) { return 0; }
//
// /**
// * @return {[|T|]}
// */
// function f2(obj) { return 0; }



// === findAllReferences ===
// === /a.js ===
// /** @typedef {number} [|T|] */
//
// /**
// * @return {/*FIND ALL REFS*/[|T|]}
// */
// function f(obj) { return 0; }
//
// /**
// * @return {[|T|]}
// */
// function f2(obj) { return 0; }



// === findAllReferences ===
// === /a.js ===
// /** @typedef {number} [|T|] */
//
// /**
// * @return {[|T|]}
// */
// function f(obj) { return 0; }
//
// /**
// * @return {/*FIND ALL REFS*/[|T|]}
// */
// function f2(obj) { return 0; }
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// === findAllReferences ===
// === /a.js ===
// class C {}
// C.D = class D {};
// /*FIND ALL REFS*/[|module|].exports = C;

// === /b.js ===
// /** @type {import("[|./a|]")} */
// const x = 0;
// /** @type {InstanceType<typeof import("./a").D>} */
// const y = 0;
Loading