Skip to content
Open
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
116 changes: 116 additions & 0 deletions internal/fourslash/tests/statecallhierarchy_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package fourslash_test

import (
"testing"

"github.com/microsoft/typescript-go/internal/fourslash"
"github.com/microsoft/typescript-go/internal/testutil"
)

func TestCallHierarchyAcrossProject(t *testing.T) {
t.Parallel()

defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `
// @stateBaseline: true
// @Filename: /projects/temp/temp.ts
/*temp*/let x = 10
// @Filename: /projects/temp/tsconfig.json
{}
// @Filename: /projects/container/lib/tsconfig.json
{
"compilerOptions": {
"composite": true,
},
references: [],
files: [
"index.ts",
"bar.ts",
"baz.ts"
],
}
// @Filename: /projects/container/lib/index.ts
export function /*call*/createModelReference() {}
// @Filename: /projects/container/lib/bar.ts
import { createModelReference } from "./index";
function openElementsAtEditor() {
createModelReference();
}
// @Filename: /projects/container/lib/baz.ts
import { createModelReference } from "./index";
function registerDefaultLanguageCommand() {
createModelReference();
}
// @Filename: /projects/container/exec/tsconfig.json
{
"files": ["./index.ts"],
"references": [
{ "path": "../lib" },
],
}
// @Filename: /projects/container/exec/index.ts
import { createModelReference } from "../lib";
function openElementsAtEditor1() {
createModelReference();
}
// @Filename: /projects/container/compositeExec/tsconfig.json
{
"compilerOptions": {
"composite": true,
},
"files": ["./index.ts"],
"references": [
{ "path": "../lib" },
],
}
// @Filename: /projects/container/compositeExec/index.ts
import { createModelReference } from "../lib";
function openElementsAtEditor2() {
createModelReference();
}
// @Filename: /projects/container/tsconfig.json
{
"files": [],
"include": [],
"references": [
{ "path": "./exec" },
{ "path": "./compositeExec" },
],
}
// @Filename: /projects/container/tsconfig.json
{
"files": [],
"include": [],
"references": [
{ "path": "./exec" },
{ "path": "./compositeExec" },
],
}
// @Filename: /projects/container/tsconfig.json
{
"files": [],
"include": [],
"references": [
{ "path": "./exec" },
{ "path": "./compositeExec" },
],
}`
f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content)
defer done()
f.GoToMarker(t, "call")
// Open temp file and verify all projects alive
f.GoToMarker(t, "temp")

// Ref projects are loaded after as part of this command
f.GoToMarker(t, "call")
f.VerifyBaselineCallHierarchy(t)

// Open temp file and verify all projects alive
f.CloseFileOfMarker(t, "temp")
f.GoToMarker(t, "temp")

// Close all files and open temp file, only inferred project should be alive
f.CloseFileOfMarker(t, "call")
f.CloseFileOfMarker(t, "temp")
f.GoToMarker(t, "temp")
}
186 changes: 186 additions & 0 deletions internal/fourslash/tests/statecodelens_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
package fourslash_test

import (
"testing"

"github.com/microsoft/typescript-go/internal/fourslash"
"github.com/microsoft/typescript-go/internal/ls/lsutil"
"github.com/microsoft/typescript-go/internal/testutil"
)

func TestCodeLensAcrossProjects(t *testing.T) {
t.Parallel()
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
content := `
// @stateBaseline: true
// @Filename: /projects/temp/temp.ts
/*temp*/let x = 10
// @Filename: /projects/temp/tsconfig.json
{}
// @Filename: /projects/container/lib/tsconfig.json
{
"compilerOptions": {
"composite": true,
},
references: [],
files: [
"index.ts",
"bar.ts"
],
}
// @Filename: /projects/container/lib/index.ts
/*impl*/
export interface Pointable {
getX(): number;
getY(): number;
}
export const val = 42;
// @Filename: /projects/container/lib/bar.ts
import { Pointable } from "./index";
class Point implements Pointable {
getX(): number {
return 0;
}
getY(): number {
return 0;
}
}
// @Filename: /projects/container/exec/tsconfig.json
{
"files": ["./index.ts"],
"references": [
{ "path": "../lib" },
],
}
// @Filename: /projects/container/exec/index.ts
import { Pointable } from "../lib";
class Point1 implements Pointable {
getX(): number {
return 0;
}
getY(): number {
return 0;
}
}
// @Filename: /projects/container/compositeExec/tsconfig.json
{
"compilerOptions": {
"composite": true,
},
"files": ["./index.ts"],
"references": [
{ "path": "../lib" },
],
}
// @Filename: /projects/container/compositeExec/index.ts
import { Pointable } from "../lib";
class Point2 implements Pointable {
getX(): number {
return 0;
}
getY(): number {
return 0;
}
}
// @Filename: /projects/container/tsconfig.json
{
"files": [],
"include": [],
"references": [
{ "path": "./exec" },
{ "path": "./compositeExec" },
],
}
// @Filename: /projects/container/tsconfig.json
{
"files": [],
"include": [],
"references": [
{ "path": "./exec" },
{ "path": "./compositeExec" },
],
}
// @Filename: /projects/container/tsconfig.json
{
"files": [],
"include": [],
"references": [
{ "path": "./exec" },
{ "path": "./compositeExec" },
],
}
`
f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content)
defer done()
f.GoToMarker(t, "impl")
// Open temp file and verify all projects alive
f.GoToMarker(t, "temp")

// Ref projects are loaded after as part of this command
f.VerifyBaselineCodeLens(t, &lsutil.UserPreferences{
CodeLens: lsutil.CodeLensUserPreferences{
ReferencesCodeLensEnabled: true,
ReferencesCodeLensShowOnAllFunctions: true,

ImplementationsCodeLensEnabled: true,
ImplementationsCodeLensShowOnInterfaceMethods: true,
ImplementationsCodeLensShowOnAllClassMethods: true,
},
})

// Open temp file and verify all projects alive
f.CloseFileOfMarker(t, "temp")
f.GoToMarker(t, "temp")

// Close all files and open temp file, only inferred project should be alive
f.CloseFileOfMarker(t, "impl")
f.CloseFileOfMarker(t, "temp")
f.GoToMarker(t, "temp")
}

func TestCodeLensOnFunctionAcrossProjects1(t *testing.T) {
t.Parallel()
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `
// @filename: ./a/tsconfig.json
{
"compilerOptions": {
"composite": true,
"declaration": true,
"declarationMaps": true,
"outDir": "./dist",
"rootDir": "src"
},
"include": ["./src"]
}

// @filename: ./a/src/foo.ts
export function aaa() {}
aaa();

// @filename: ./b/tsconfig.json
{
"compilerOptions": {
"composite": true,
"declaration": true,
"declarationMaps": true,
"outDir": "./dist",
"rootDir": "src"
},
"references": [{ "path": "../a" }],
"include": ["./src"]
}

// @filename: ./b/src/bar.ts
import * as foo from '../../a/dist/foo.js';
foo.aaa();
`
f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content)
defer done()

f.VerifyBaselineCodeLens(t, &lsutil.UserPreferences{
CodeLens: lsutil.CodeLensUserPreferences{
ReferencesCodeLensEnabled: true,
},
})
}
Loading
Loading