|
| 1 | +package lspservertests |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/microsoft/typescript-go/internal/bundled" |
| 7 | + "github.com/microsoft/typescript-go/internal/lsp/lsproto" |
| 8 | + "github.com/microsoft/typescript-go/internal/testutil/lsptestutil" |
| 9 | + "github.com/microsoft/typescript-go/internal/testutil/stringtestutil" |
| 10 | + "github.com/microsoft/typescript-go/internal/vfs/vfstest" |
| 11 | +) |
| 12 | + |
| 13 | +func TestRename(t *testing.T) { |
| 14 | + t.Parallel() |
| 15 | + |
| 16 | + if !bundled.Embedded { |
| 17 | + t.Skip("bundled files are not embedded") |
| 18 | + } |
| 19 | + |
| 20 | + testCases := []*lspServerTest{ |
| 21 | + { |
| 22 | + subScenario: "ancestor and project ref management", |
| 23 | + files: func() map[string]any { |
| 24 | + return map[string]any{ |
| 25 | + "/user/username/projects/temp/temp.ts": "let x = 10", |
| 26 | + "/user/username/projects/temp/tsconfig.json": "{}", |
| 27 | + "/user/username/projects/container/lib/tsconfig.json": stringtestutil.Dedent(` |
| 28 | + { |
| 29 | + "compilerOptions": { |
| 30 | + "composite": true, |
| 31 | + }, |
| 32 | + references: [], |
| 33 | + files: [ |
| 34 | + "index.ts", |
| 35 | + ], |
| 36 | + }`), |
| 37 | + "/user/username/projects/container/lib/index.ts": stringtestutil.Dedent(` |
| 38 | + export const myConst = 30;`), |
| 39 | + "/user/username/projects/container/exec/tsconfig.json": stringtestutil.Dedent(` |
| 40 | + { |
| 41 | + "files": ["./index.ts"], |
| 42 | + "references": [ |
| 43 | + { "path": "../lib" }, |
| 44 | + ], |
| 45 | + }`), |
| 46 | + "/user/username/projects/container/exec/index.ts": stringtestutil.Dedent(` |
| 47 | + import { myConst } from "../lib"; |
| 48 | + export function getMyConst() { |
| 49 | + return myConst; |
| 50 | + }`), |
| 51 | + "/user/username/projects/container/compositeExec/tsconfig.json": stringtestutil.Dedent(` |
| 52 | + { |
| 53 | + "compilerOptions": { |
| 54 | + "composite": true, |
| 55 | + }, |
| 56 | + "files": ["./index.ts"], |
| 57 | + "references": [ |
| 58 | + { "path": "../lib" }, |
| 59 | + ], |
| 60 | + }`), |
| 61 | + "/user/username/projects/container/compositeExec/index.ts": stringtestutil.Dedent(` |
| 62 | + import { myConst } from "../lib"; |
| 63 | + export function getMyConst() { |
| 64 | + return myConst; |
| 65 | + }`), |
| 66 | + "/user/username/projects/container/tsconfig.json": stringtestutil.Dedent(` |
| 67 | + { |
| 68 | + "files": [], |
| 69 | + "include": [], |
| 70 | + "references": [ |
| 71 | + { "path": "./exec" }, |
| 72 | + { "path": "./compositeExec" }, |
| 73 | + ], |
| 74 | + }`), |
| 75 | + } |
| 76 | + }, |
| 77 | + test: func(server *testServer) { |
| 78 | + file := "/user/username/projects/container/compositeExec/index.ts" |
| 79 | + temp := "/user/username/projects/temp/temp.ts" |
| 80 | + server.openFile(file, lsproto.LanguageKindTypeScript) |
| 81 | + // Open temp file and verify all projects alive |
| 82 | + server.openFile(temp, lsproto.LanguageKindTypeScript) |
| 83 | + |
| 84 | + // Ref projects are loaded after as part of this command |
| 85 | + server.baselineRename(file, lsptestutil.PositionToLineAndCharacter(file, server.content(file), "myConst", 0)) |
| 86 | + |
| 87 | + // Open temp file and verify all projects alive |
| 88 | + server.closeFile(temp) |
| 89 | + server.openFile(temp, lsproto.LanguageKindTypeScript) |
| 90 | + |
| 91 | + // Close all files and open temp file, only inferred project should be alive |
| 92 | + server.closeFile(file) |
| 93 | + server.closeFile(temp) |
| 94 | + server.openFile(temp, lsproto.LanguageKindTypeScript) |
| 95 | + }, |
| 96 | + }, |
| 97 | + { |
| 98 | + subScenario: "rename in common file renames all project", |
| 99 | + files: func() map[string]any { |
| 100 | + return map[string]any{ |
| 101 | + "/users/username/projects/a/a.ts": stringtestutil.Dedent(` |
| 102 | + import {C} from "./c/fc"; |
| 103 | + console.log(C) |
| 104 | + `), |
| 105 | + "/users/username/projects/a/tsconfig.json": "{}", |
| 106 | + "/users/username/projects/a/c": vfstest.Symlink("/users/username/projects/c"), |
| 107 | + "/users/username/projects/b/b.ts": stringtestutil.Dedent(` |
| 108 | + import {C} from "../c/fc"; |
| 109 | + console.log(C) |
| 110 | + `), |
| 111 | + "/users/username/projects/b/tsconfig.json": "{}", |
| 112 | + "/users/username/projects/b/c": vfstest.Symlink("/users/username/projects/c"), |
| 113 | + "/users/username/projects/c/fc.ts": stringtestutil.Dedent(` |
| 114 | + export const C = 42; |
| 115 | + `), |
| 116 | + } |
| 117 | + }, |
| 118 | + test: func(server *testServer) { |
| 119 | + aTs := "/users/username/projects/a/a.ts" |
| 120 | + bTs := "/users/username/projects/b/b.ts" |
| 121 | + aFc := "/users/username/projects/a/c/fc.ts" |
| 122 | + bFc := "/users/username/projects/b/c/fc.ts" |
| 123 | + server.openFile(aTs, lsproto.LanguageKindTypeScript) |
| 124 | + server.openFile(bTs, lsproto.LanguageKindTypeScript) |
| 125 | + cContent := server.content("/users/username/projects/c/fc.ts") |
| 126 | + server.openFileWithContent(aFc, cContent, lsproto.LanguageKindTypeScript) |
| 127 | + server.openFileWithContent(bFc, cContent, lsproto.LanguageKindTypeScript) |
| 128 | + server.baselineRename(aFc, lsptestutil.PositionToLineAndCharacter(aFc, cContent, "C", 0)) |
| 129 | + }, |
| 130 | + }, |
| 131 | + } |
| 132 | + |
| 133 | + for _, test := range testCases { |
| 134 | + test.run(t, "rename") |
| 135 | + } |
| 136 | +} |
0 commit comments