Skip to content

Commit ddac387

Browse files
authored
Deprecate CommandNames in favor of protocol.CommandTypes, direct import for better bundler output (#52208)
1 parent 5b18979 commit ddac387

23 files changed

+447
-443
lines changed

src/harness/client.ts

Lines changed: 40 additions & 41 deletions
Large diffs are not rendered by default.

src/server/editorServices.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ import {
3636
ProjectFilesWithTSDiagnostics,
3737
ProjectKind,
3838
ProjectOptions,
39-
protocol,
4039
ScriptInfo,
4140
ScriptInfoVersion,
4241
ServerHost,
@@ -179,6 +178,7 @@ import {
179178
WatchType,
180179
WildcardDirectoryWatcher,
181180
} from "./_namespaces/ts";
181+
import * as protocol from "./protocol";
182182

183183
export const maxProgramSizeForNonTsFiles = 20 * 1024 * 1024;
184184
/** @internal */

src/server/project.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
ProjectOptions,
1515
ProjectReferenceProjectLoadKind,
1616
ProjectService,
17-
protocol,
1817
ScriptInfo,
1918
ServerHost,
2019
Session,
@@ -148,6 +147,7 @@ import {
148147
WatchOptions,
149148
WatchType,
150149
} from "./_namespaces/ts";
150+
import * as protocol from "./protocol";
151151

152152
export enum ProjectKind {
153153
Inferred,

src/server/scriptInfo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
NormalizedPath,
1212
Project,
1313
ProjectKind,
14-
protocol,
1514
ScriptVersionCache,
1615
ServerHost,
1716
} from "./_namespaces/ts.server";
@@ -52,6 +51,7 @@ import {
5251
TextSpan,
5352
unorderedRemoveItem,
5453
} from "./_namespaces/ts";
54+
import * as protocol from "./protocol";
5555

5656
export interface ScriptInfoVersion {
5757
svc: number;

src/server/scriptVersionCache.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import {
1111
} from "./_namespaces/ts";
1212
import {
1313
emptyArray,
14-
protocol,
1514
} from "./_namespaces/ts.server";
15+
import * as protocol from "./protocol";
1616

1717
const lineCollectionCapacity = 4;
1818

src/server/session.ts

Lines changed: 176 additions & 174 deletions
Large diffs are not rendered by default.

src/testRunner/unittests/tsserver/compileOnSave.ts

Lines changed: 47 additions & 47 deletions
Large diffs are not rendered by default.

src/testRunner/unittests/tsserver/declarationFileMaps.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ describe("unittests:: tsserver:: with declaration file maps:: project references
194194
it("goToDefinition -- target does not exist", () => {
195195
const session = makeSampleProjects();
196196
session.executeCommandSeq<ts.server.protocol.DefinitionRequest>({
197-
command: ts.server.CommandNames.Definition,
197+
command: ts.server.protocol.CommandTypes.Definition,
198198
arguments: protocolFileLocationFromSubstring(userTs, "fnB()")
199199
});
200200
verifySingleInferredProject(session);
@@ -204,7 +204,7 @@ describe("unittests:: tsserver:: with declaration file maps:: project references
204204
it("navigateTo", () => {
205205
const session = makeSampleProjects();
206206
session.executeCommandSeq<ts.server.protocol.NavtoRequest>({
207-
command: ts.server.CommandNames.Navto,
207+
command: ts.server.protocol.CommandTypes.Navto,
208208
arguments: { file: userTs.path, searchValue: "fn" }
209209
});
210210
verifySingleInferredProject(session);
@@ -214,7 +214,7 @@ describe("unittests:: tsserver:: with declaration file maps:: project references
214214
it("navigateToAll -- when neither file nor project is specified", () => {
215215
const session = makeSampleProjects(/*addUserTsConfig*/ true, /*keepAllFiles*/ true);
216216
session.executeCommandSeq<ts.server.protocol.NavtoRequest>({
217-
command: ts.server.CommandNames.Navto,
217+
command: ts.server.protocol.CommandTypes.Navto,
218218
arguments: { file: undefined, searchValue: "fn" }
219219
});
220220
baselineTsserverLogs("declarationFileMaps", "navigateToAll neither file not project is specified", session);
@@ -223,7 +223,7 @@ describe("unittests:: tsserver:: with declaration file maps:: project references
223223
it("navigateToAll -- when file is not specified but project is", () => {
224224
const session = makeSampleProjects(/*addUserTsConfig*/ true, /*keepAllFiles*/ true);
225225
session.executeCommandSeq<ts.server.protocol.NavtoRequest>({
226-
command: ts.server.CommandNames.Navto,
226+
command: ts.server.protocol.CommandTypes.Navto,
227227
arguments: { projectFileName: bTsconfig.path, file: undefined, searchValue: "fn" }
228228
});
229229
baselineTsserverLogs("declarationFileMaps", "navigateToAll file is not specified but project is", session);

src/testRunner/unittests/tsserver/events/projectUpdatedInBackground.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe("unittests:: tsserver:: events:: ProjectsUpdatedInBackground", () => {
2929
function createVerifyInitialOpen(session: TestSession, verifyProjectsUpdatedInBackgroundEventHandler: (events: ts.server.ProjectsUpdatedInBackgroundEvent[]) => void) {
3030
return (file: File) => {
3131
session.executeCommandSeq({
32-
command: ts.server.CommandNames.Open,
32+
command: ts.server.protocol.CommandTypes.Open,
3333
arguments: {
3434
file: file.path
3535
}
@@ -237,7 +237,7 @@ describe("unittests:: tsserver:: events:: ProjectsUpdatedInBackground", () => {
237237

238238
function updateContentOfOpenFile(file: File, newContent: string) {
239239
session.executeCommandSeq<ts.server.protocol.ChangeRequest>({
240-
command: ts.server.CommandNames.Change,
240+
command: ts.server.protocol.CommandTypes.Change,
241241
arguments: {
242242
file: file.path,
243243
insertString: newContent,

src/testRunner/unittests/tsserver/getEditsForFileRename.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ describe("unittests:: tsserver:: getEditsForFileRename", () => {
8282
openFilesForSession([aUserTs, bUserTs], session);
8383

8484
session.executeCommandSeq<ts.server.protocol.GetEditsForFileRenameRequest>({
85-
command: ts.server.CommandNames.GetEditsForFileRename,
85+
command: ts.server.protocol.CommandTypes.GetEditsForFileRename,
8686
arguments: {
8787
oldFilePath: aOldTs.path,
8888
newFilePath: "/a/new.ts",
@@ -101,7 +101,7 @@ describe("unittests:: tsserver:: getEditsForFileRename", () => {
101101
openFilesForSession([aTs, cTs], session);
102102

103103
session.executeCommandSeq<ts.server.protocol.GetEditsForFileRenameRequest>({
104-
command: ts.server.CommandNames.GetEditsForFileRename,
104+
command: ts.server.protocol.CommandTypes.GetEditsForFileRename,
105105
arguments: {
106106
oldFilePath: "/b.ts",
107107
newFilePath: cTs.path,

src/testRunner/unittests/tsserver/helpers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ export class TestServerCancellationToken implements ts.server.ServerCancellation
739739
export function openFilesForSession(files: readonly (string | File | { readonly file: File | string, readonly projectRootPath: string, content?: string })[], session: TestSession): void {
740740
for (const file of files) {
741741
session.executeCommandSeq<ts.server.protocol.OpenRequest>({
742-
command: ts.server.CommandNames.Open,
742+
command: ts.server.protocol.CommandTypes.Open,
743743
arguments: ts.isString(file) ?
744744
{ file } :
745745
"projectRootPath" in file ? // eslint-disable-line local/no-in-operator
@@ -755,7 +755,7 @@ export function openFilesForSession(files: readonly (string | File | { readonly
755755
export function closeFilesForSession(files: readonly File[], session: TestSession): void {
756756
for (const file of files) {
757757
session.executeCommandSeq<ts.server.protocol.CloseRequest>({
758-
command: ts.server.CommandNames.Close,
758+
command: ts.server.protocol.CommandTypes.Close,
759759
arguments: { file: file.path }
760760
});
761761
}

src/testRunner/unittests/tsserver/inferredProjects.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ describe("unittests:: tsserver:: Inferred projects", () => {
170170
session.executeCommand({
171171
seq: 1,
172172
type: "request",
173-
command: ts.server.CommandNames.CompilerOptionsForInferredProjects,
173+
command: ts.server.protocol.CommandTypes.CompilerOptionsForInferredProjects,
174174
arguments: {
175175
options: {
176176
allowJs: true,
@@ -181,7 +181,7 @@ describe("unittests:: tsserver:: Inferred projects", () => {
181181
session.executeCommand({
182182
seq: 2,
183183
type: "request",
184-
command: ts.server.CommandNames.CompilerOptionsForInferredProjects,
184+
command: ts.server.protocol.CommandTypes.CompilerOptionsForInferredProjects,
185185
arguments: {
186186
options: {
187187
allowJs: true,
@@ -193,7 +193,7 @@ describe("unittests:: tsserver:: Inferred projects", () => {
193193
session.executeCommand({
194194
seq: 3,
195195
type: "request",
196-
command: ts.server.CommandNames.Open,
196+
command: ts.server.protocol.CommandTypes.Open,
197197
arguments: {
198198
file: file1.path,
199199
fileContent: file1.content,
@@ -204,7 +204,7 @@ describe("unittests:: tsserver:: Inferred projects", () => {
204204
session.executeCommand({
205205
seq: 4,
206206
type: "request",
207-
command: ts.server.CommandNames.Open,
207+
command: ts.server.protocol.CommandTypes.Open,
208208
arguments: {
209209
file: file2.path,
210210
fileContent: file2.content,
@@ -215,7 +215,7 @@ describe("unittests:: tsserver:: Inferred projects", () => {
215215
session.executeCommand({
216216
seq: 5,
217217
type: "request",
218-
command: ts.server.CommandNames.Open,
218+
command: ts.server.protocol.CommandTypes.Open,
219219
arguments: {
220220
file: file3.path,
221221
fileContent: file3.content,
@@ -226,7 +226,7 @@ describe("unittests:: tsserver:: Inferred projects", () => {
226226
session.executeCommand({
227227
seq: 6,
228228
type: "request",
229-
command: ts.server.CommandNames.Open,
229+
command: ts.server.protocol.CommandTypes.Open,
230230
arguments: {
231231
file: file4.path,
232232
fileContent: file4.content,

src/testRunner/unittests/tsserver/navTo.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ describe("unittests:: tsserver:: navigate-to for javascript project", () => {
2727

2828
// Try to find some interface type defined in lib.d.ts
2929
session.executeCommandSeq<ts.server.protocol.NavtoRequest>({
30-
command: ts.server.CommandNames.Navto,
30+
command: ts.server.protocol.CommandTypes.Navto,
3131
arguments: { searchValue: "Document", file: file1.path, projectFileName: configFile.path }
3232
}).response as ts.server.protocol.NavtoItem[];
3333

3434
session.executeCommandSeq<ts.server.protocol.NavtoRequest>({
35-
command: ts.server.CommandNames.Navto,
35+
command: ts.server.protocol.CommandTypes.Navto,
3636
arguments: { searchValue: "foo", file: file1.path, projectFileName: configFile.path }
3737
}).response as ts.server.protocol.NavtoItem[];
3838
baselineTsserverLogs("navTo", "should not include type symbols", session);
@@ -72,7 +72,7 @@ export const ghijkl = a.abcdef;`
7272
openFilesForSession([file1, file2], session);
7373

7474
session.executeCommandSeq<ts.server.protocol.NavtoRequest>({
75-
command: ts.server.CommandNames.Navto,
75+
command: ts.server.protocol.CommandTypes.Navto,
7676
arguments: { searchValue: "abcdef", file: file1.path }
7777
});
7878

@@ -120,7 +120,7 @@ export const ghijkl = a.abcdef;`
120120
openFilesForSession([file1], session);
121121

122122
session.executeCommandSeq<ts.server.protocol.NavtoRequest>({
123-
command: ts.server.CommandNames.Navto,
123+
command: ts.server.protocol.CommandTypes.Navto,
124124
arguments: { searchValue: "abcdef" }
125125
});
126126
baselineTsserverLogs("navTo", "should de-duplicate symbols when searching all projects", session);
@@ -141,7 +141,7 @@ export const ghijkl = a.abcdef;`
141141

142142
// Try to find some interface type defined in lib.d.ts
143143
session.executeCommandSeq<ts.server.protocol.NavtoRequest>({
144-
command: ts.server.CommandNames.Navto,
144+
command: ts.server.protocol.CommandTypes.Navto,
145145
arguments: { searchValue: "foo", file: file1.path, projectFileName: configFile.path }
146146
});
147147
baselineTsserverLogs("navTo", "should work with Deprecated", session);

src/testRunner/unittests/tsserver/occurences.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@ describe("unittests:: tsserver:: occurrence highlight on string", () => {
2121
const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) });
2222
openFilesForSession([file1], session);
2323
session.executeCommandSeq<ts.server.protocol.FileLocationRequest>({
24-
command: ts.server.CommandNames.Occurrences,
24+
command: ts.server.protocol.CommandTypes.Occurrences,
2525
arguments: { file: file1.path, line: 1, offset: 11 }
2626
});
2727

2828
session.executeCommandSeq<ts.server.protocol.FileLocationRequest>({
29-
command: ts.server.CommandNames.Occurrences,
29+
command: ts.server.protocol.CommandTypes.Occurrences,
3030
arguments: { file: file1.path, line: 3, offset: 13 }
3131
});
3232

3333
session.executeCommandSeq<ts.server.protocol.FileLocationRequest>({
34-
command: ts.server.CommandNames.Occurrences,
34+
command: ts.server.protocol.CommandTypes.Occurrences,
3535
arguments: { file: file1.path, line: 4, offset: 14 }
3636
});
3737
baselineTsserverLogs("occurences", "should be marked if only on string values", session);

src/testRunner/unittests/tsserver/projectErrors.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ describe("unittests:: tsserver:: Project Errors", () => {
6262
const projectFileName = "/a/b/test.csproj";
6363
const compilerOptionsRequest: ts.server.protocol.CompilerOptionsDiagnosticsRequest = {
6464
type: "request",
65-
command: ts.server.CommandNames.CompilerOptionsDiagnosticsFull,
65+
command: ts.server.protocol.CommandTypes.CompilerOptionsDiagnosticsFull,
6666
seq: 2,
6767
arguments: { projectFileName }
6868
};
@@ -117,7 +117,7 @@ describe("unittests:: tsserver:: Project Errors", () => {
117117
const project = configuredProjectAt(projectService, 0);
118118
const compilerOptionsRequest: ts.server.protocol.CompilerOptionsDiagnosticsRequest = {
119119
type: "request",
120-
command: ts.server.CommandNames.CompilerOptionsDiagnosticsFull,
120+
command: ts.server.protocol.CommandTypes.CompilerOptionsDiagnosticsFull,
121121
seq: 2,
122122
arguments: { projectFileName: project.getProjectName() }
123123
};
@@ -262,7 +262,7 @@ describe("unittests:: tsserver:: Project Errors are reported as appropriate", ()
262262
const fileContent = `/// <reference path="${refPathNotFound1}" />
263263
/// <reference path="${refPathNotFound2}" />`;
264264
session.executeCommandSeq<ts.server.protocol.OpenRequest>({
265-
command: ts.server.CommandNames.Open,
265+
command: ts.server.protocol.CommandTypes.Open,
266266
arguments: {
267267
file: untitledFile,
268268
fileContent,
@@ -305,7 +305,7 @@ describe("unittests:: tsserver:: Project Errors are reported as appropriate", ()
305305
const session = createSession(host, { canUseEvents: true, logger: createLoggerWithInMemoryLogs(host) });
306306

307307
session.executeCommandSeq<ts.server.protocol.OpenRequest>({
308-
command: ts.server.CommandNames.Open,
308+
command: ts.server.protocol.CommandTypes.Open,
309309
arguments: { file: app.path, }
310310
});
311311
verifyGetErrRequest({ session, host, files: [app] });
@@ -325,7 +325,7 @@ describe("unittests:: tsserver:: Project Errors are reported as appropriate", ()
325325
const host = createServerHost([file, libFile]);
326326
const session = createSession(host, { canUseEvents: true, logger: createLoggerWithInMemoryLogs(host) });
327327
session.executeCommandSeq<ts.server.protocol.GeterrRequest>({
328-
command: ts.server.CommandNames.Geterr,
328+
command: ts.server.protocol.CommandTypes.Geterr,
329329
arguments: {
330330
delay: 0,
331331
files: [file.path]
@@ -624,21 +624,21 @@ describe("unittests:: tsserver:: Project Errors dont include overwrite emit erro
624624

625625
const diags = session.executeCommand({
626626
type: "request",
627-
command: ts.server.CommandNames.CompilerOptionsDiagnosticsFull,
627+
command: ts.server.protocol.CommandTypes.CompilerOptionsDiagnosticsFull,
628628
seq: 2,
629629
arguments: { projectFileName: projectName }
630630
} as ts.server.protocol.CompilerOptionsDiagnosticsRequest).response as readonly ts.server.protocol.DiagnosticWithLinePosition[];
631631
assert.isTrue(diags.length === 0);
632632

633633
session.executeCommand({
634634
type: "request",
635-
command: ts.server.CommandNames.CompilerOptionsForInferredProjects,
635+
command: ts.server.protocol.CommandTypes.CompilerOptionsForInferredProjects,
636636
seq: 3,
637637
arguments: { options: { module: ts.ModuleKind.CommonJS } }
638638
} as ts.server.protocol.SetCompilerOptionsForInferredProjectsRequest);
639639
const diagsAfterUpdate = session.executeCommand({
640640
type: "request",
641-
command: ts.server.CommandNames.CompilerOptionsDiagnosticsFull,
641+
command: ts.server.protocol.CommandTypes.CompilerOptionsDiagnosticsFull,
642642
seq: 4,
643643
arguments: { projectFileName: projectName }
644644
} as ts.server.protocol.CompilerOptionsDiagnosticsRequest).response as readonly ts.server.protocol.DiagnosticWithLinePosition[];
@@ -665,15 +665,15 @@ describe("unittests:: tsserver:: Project Errors dont include overwrite emit erro
665665

666666
const diags = session.executeCommand({
667667
type: "request",
668-
command: ts.server.CommandNames.CompilerOptionsDiagnosticsFull,
668+
command: ts.server.protocol.CommandTypes.CompilerOptionsDiagnosticsFull,
669669
seq: 2,
670670
arguments: { projectFileName }
671671
} as ts.server.protocol.CompilerOptionsDiagnosticsRequest).response as readonly ts.server.protocol.DiagnosticWithLinePosition[];
672672
assert.isTrue(diags.length === 0);
673673

674674
session.executeCommand({
675675
type: "request",
676-
command: ts.server.CommandNames.OpenExternalProject,
676+
command: ts.server.protocol.CommandTypes.OpenExternalProject,
677677
seq: 3,
678678
arguments: {
679679
projectFileName,
@@ -683,7 +683,7 @@ describe("unittests:: tsserver:: Project Errors dont include overwrite emit erro
683683
} as ts.server.protocol.OpenExternalProjectRequest);
684684
const diagsAfterUpdate = session.executeCommand({
685685
type: "request",
686-
command: ts.server.CommandNames.CompilerOptionsDiagnosticsFull,
686+
command: ts.server.protocol.CommandTypes.CompilerOptionsDiagnosticsFull,
687687
seq: 4,
688688
arguments: { projectFileName }
689689
} as ts.server.protocol.CompilerOptionsDiagnosticsRequest).response as readonly ts.server.protocol.DiagnosticWithLinePosition[];
@@ -723,7 +723,7 @@ describe("unittests:: tsserver:: Project Errors reports Options Diagnostic locat
723723

724724
const diags = session.executeCommand({
725725
type: "request",
726-
command: ts.server.CommandNames.SemanticDiagnosticsSync,
726+
command: ts.server.protocol.CommandTypes.SemanticDiagnosticsSync,
727727
seq: 2,
728728
arguments: { file: configFile.path, projectFileName: projectName, includeLinePosition: true }
729729
} as ts.server.protocol.SemanticDiagnosticsSyncRequest).response as readonly ts.server.protocol.DiagnosticWithLinePosition[];
@@ -734,7 +734,7 @@ describe("unittests:: tsserver:: Project Errors reports Options Diagnostic locat
734734

735735
const diagsAfterEdit = session.executeCommand({
736736
type: "request",
737-
command: ts.server.CommandNames.SemanticDiagnosticsSync,
737+
command: ts.server.protocol.CommandTypes.SemanticDiagnosticsSync,
738738
seq: 2,
739739
arguments: { file: configFile.path, projectFileName: projectName, includeLinePosition: true }
740740
} as ts.server.protocol.SemanticDiagnosticsSyncRequest).response as readonly ts.server.protocol.DiagnosticWithLinePosition[];

0 commit comments

Comments
 (0)