|
| 1 | +package fourslash_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/microsoft/typescript-go/internal/fourslash" |
| 7 | + "github.com/microsoft/typescript-go/internal/ls/lsutil" |
| 8 | + "github.com/microsoft/typescript-go/internal/testutil" |
| 9 | +) |
| 10 | + |
| 11 | +func TestCodeLensAcrossProjects(t *testing.T) { |
| 12 | + t.Parallel() |
| 13 | + defer testutil.RecoverAndFail(t, "Panic on fourslash test") |
| 14 | + content := ` |
| 15 | +// @stateBaseline: true |
| 16 | +// @Filename: /projects/temp/temp.ts |
| 17 | +/*temp*/let x = 10 |
| 18 | +// @Filename: /projects/temp/tsconfig.json |
| 19 | +{} |
| 20 | +// @Filename: /projects/container/lib/tsconfig.json |
| 21 | +{ |
| 22 | + "compilerOptions": { |
| 23 | + "composite": true, |
| 24 | + }, |
| 25 | + references: [], |
| 26 | + files: [ |
| 27 | + "index.ts", |
| 28 | + "bar.ts" |
| 29 | + ], |
| 30 | +} |
| 31 | +// @Filename: /projects/container/lib/index.ts |
| 32 | +/*impl*/ |
| 33 | +export interface Pointable { |
| 34 | + getX(): number; |
| 35 | + getY(): number; |
| 36 | +} |
| 37 | +export const val = 42; |
| 38 | +// @Filename: /projects/container/lib/bar.ts |
| 39 | +import { Pointable } from "./index"; |
| 40 | +class Point implements Pointable { |
| 41 | + getX(): number { |
| 42 | + return 0; |
| 43 | + } |
| 44 | + getY(): number { |
| 45 | + return 0; |
| 46 | + } |
| 47 | +} |
| 48 | +// @Filename: /projects/container/exec/tsconfig.json |
| 49 | +{ |
| 50 | + "files": ["./index.ts"], |
| 51 | + "references": [ |
| 52 | + { "path": "../lib" }, |
| 53 | + ], |
| 54 | +} |
| 55 | +// @Filename: /projects/container/exec/index.ts |
| 56 | +import { Pointable } from "../lib"; |
| 57 | +class Point1 implements Pointable { |
| 58 | + getX(): number { |
| 59 | + return 0; |
| 60 | + } |
| 61 | + getY(): number { |
| 62 | + return 0; |
| 63 | + } |
| 64 | +} |
| 65 | +// @Filename: /projects/container/compositeExec/tsconfig.json |
| 66 | +{ |
| 67 | + "compilerOptions": { |
| 68 | + "composite": true, |
| 69 | + }, |
| 70 | + "files": ["./index.ts"], |
| 71 | + "references": [ |
| 72 | + { "path": "../lib" }, |
| 73 | + ], |
| 74 | +} |
| 75 | +// @Filename: /projects/container/compositeExec/index.ts |
| 76 | +import { Pointable } from "../lib"; |
| 77 | +class Point2 implements Pointable { |
| 78 | + getX(): number { |
| 79 | + return 0; |
| 80 | + } |
| 81 | + getY(): number { |
| 82 | + return 0; |
| 83 | + } |
| 84 | +} |
| 85 | +// @Filename: /projects/container/tsconfig.json |
| 86 | +{ |
| 87 | + "files": [], |
| 88 | + "include": [], |
| 89 | + "references": [ |
| 90 | + { "path": "./exec" }, |
| 91 | + { "path": "./compositeExec" }, |
| 92 | + ], |
| 93 | +} |
| 94 | +// @Filename: /projects/container/tsconfig.json |
| 95 | +{ |
| 96 | + "files": [], |
| 97 | + "include": [], |
| 98 | + "references": [ |
| 99 | + { "path": "./exec" }, |
| 100 | + { "path": "./compositeExec" }, |
| 101 | + ], |
| 102 | +} |
| 103 | +// @Filename: /projects/container/tsconfig.json |
| 104 | +{ |
| 105 | + "files": [], |
| 106 | + "include": [], |
| 107 | + "references": [ |
| 108 | + { "path": "./exec" }, |
| 109 | + { "path": "./compositeExec" }, |
| 110 | + ], |
| 111 | +} |
| 112 | +` |
| 113 | + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) |
| 114 | + defer done() |
| 115 | + f.GoToMarker(t, "impl") |
| 116 | + // Open temp file and verify all projects alive |
| 117 | + f.GoToMarker(t, "temp") |
| 118 | + |
| 119 | + // Ref projects are loaded after as part of this command |
| 120 | + f.VerifyBaselineCodeLens(t, &lsutil.UserPreferences{ |
| 121 | + CodeLens: lsutil.CodeLensUserPreferences{ |
| 122 | + ReferencesCodeLensEnabled: true, |
| 123 | + ReferencesCodeLensShowOnAllFunctions: true, |
| 124 | + |
| 125 | + ImplementationsCodeLensEnabled: true, |
| 126 | + ImplementationsCodeLensShowOnInterfaceMethods: true, |
| 127 | + ImplementationsCodeLensShowOnAllClassMethods: true, |
| 128 | + }, |
| 129 | + }) |
| 130 | + |
| 131 | + // Open temp file and verify all projects alive |
| 132 | + f.CloseFileOfMarker(t, "temp") |
| 133 | + f.GoToMarker(t, "temp") |
| 134 | + |
| 135 | + // Close all files and open temp file, only inferred project should be alive |
| 136 | + f.CloseFileOfMarker(t, "impl") |
| 137 | + f.CloseFileOfMarker(t, "temp") |
| 138 | + f.GoToMarker(t, "temp") |
| 139 | +} |
| 140 | + |
| 141 | +func TestCodeLensOnFunctionAcrossProjects1(t *testing.T) { |
| 142 | + t.Parallel() |
| 143 | + defer testutil.RecoverAndFail(t, "Panic on fourslash test") |
| 144 | + const content = ` |
| 145 | +// @filename: ./a/tsconfig.json |
| 146 | +{ |
| 147 | + "compilerOptions": { |
| 148 | + "composite": true, |
| 149 | + "declaration": true, |
| 150 | + "declarationMaps": true, |
| 151 | + "outDir": "./dist", |
| 152 | + "rootDir": "src" |
| 153 | + }, |
| 154 | + "include": ["./src"] |
| 155 | +} |
| 156 | +
|
| 157 | +// @filename: ./a/src/foo.ts |
| 158 | +export function aaa() {} |
| 159 | +aaa(); |
| 160 | +
|
| 161 | +// @filename: ./b/tsconfig.json |
| 162 | +{ |
| 163 | + "compilerOptions": { |
| 164 | + "composite": true, |
| 165 | + "declaration": true, |
| 166 | + "declarationMaps": true, |
| 167 | + "outDir": "./dist", |
| 168 | + "rootDir": "src" |
| 169 | + }, |
| 170 | + "references": [{ "path": "../a" }], |
| 171 | + "include": ["./src"] |
| 172 | +} |
| 173 | +
|
| 174 | +// @filename: ./b/src/bar.ts |
| 175 | +import * as foo from '../../a/dist/foo.js'; |
| 176 | +foo.aaa(); |
| 177 | +` |
| 178 | + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) |
| 179 | + defer done() |
| 180 | + |
| 181 | + f.VerifyBaselineCodeLens(t, &lsutil.UserPreferences{ |
| 182 | + CodeLens: lsutil.CodeLensUserPreferences{ |
| 183 | + ReferencesCodeLensEnabled: true, |
| 184 | + }, |
| 185 | + }) |
| 186 | +} |
0 commit comments