Skip to content

Commit f6240cb

Browse files
author
Andy Hanson
committed
Make CommandTypes a const enum and use allCommandTypes for unit test
1 parent c6e69dd commit f6240cb

File tree

2 files changed

+75
-5
lines changed

2 files changed

+75
-5
lines changed

Diff for: src/harness/unittests/session.ts

+73-4
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,81 @@ namespace ts.server {
172172
});
173173

174174
describe("onMessage", () => {
175+
const allCommandNames: CommandNames[] = [
176+
CommandNames.Brace,
177+
CommandNames.BraceFull,
178+
CommandNames.BraceCompletion,
179+
CommandNames.Change,
180+
CommandNames.Close,
181+
CommandNames.Completions,
182+
CommandNames.CompletionsFull,
183+
CommandNames.CompletionDetails,
184+
CommandNames.CompileOnSaveAffectedFileList,
185+
CommandNames.Configure,
186+
CommandNames.Definition,
187+
CommandNames.DefinitionFull,
188+
CommandNames.Implementation,
189+
CommandNames.ImplementationFull,
190+
CommandNames.Exit,
191+
CommandNames.Format,
192+
CommandNames.Formatonkey,
193+
CommandNames.FormatFull,
194+
CommandNames.FormatonkeyFull,
195+
CommandNames.FormatRangeFull,
196+
CommandNames.Geterr,
197+
CommandNames.GeterrForProject,
198+
CommandNames.SemanticDiagnosticsSync,
199+
CommandNames.SyntacticDiagnosticsSync,
200+
CommandNames.NavBar,
201+
CommandNames.NavBarFull,
202+
CommandNames.Navto,
203+
CommandNames.NavtoFull,
204+
CommandNames.NavTree,
205+
CommandNames.NavTreeFull,
206+
CommandNames.Occurrences,
207+
CommandNames.DocumentHighlights,
208+
CommandNames.DocumentHighlightsFull,
209+
CommandNames.Open,
210+
CommandNames.Quickinfo,
211+
CommandNames.QuickinfoFull,
212+
CommandNames.References,
213+
CommandNames.ReferencesFull,
214+
CommandNames.Reload,
215+
CommandNames.Rename,
216+
CommandNames.RenameInfoFull,
217+
CommandNames.RenameLocationsFull,
218+
CommandNames.Saveto,
219+
CommandNames.SignatureHelp,
220+
CommandNames.SignatureHelpFull,
221+
CommandNames.TypeDefinition,
222+
CommandNames.ProjectInfo,
223+
CommandNames.ReloadProjects,
224+
CommandNames.Unknown,
225+
CommandNames.OpenExternalProject,
226+
CommandNames.CloseExternalProject,
227+
CommandNames.SynchronizeProjectList,
228+
CommandNames.ApplyChangedToOpenFiles,
229+
CommandNames.EncodedSemanticClassificationsFull,
230+
CommandNames.Cleanup,
231+
CommandNames.OutliningSpans,
232+
CommandNames.TodoComments,
233+
CommandNames.Indentation,
234+
CommandNames.DocCommentTemplate,
235+
CommandNames.CompilerOptionsDiagnosticsFull,
236+
CommandNames.NameOrDottedNameSpan,
237+
CommandNames.BreakpointStatement,
238+
CommandNames.CompilerOptionsForInferredProjects,
239+
CommandNames.GetCodeFixes,
240+
CommandNames.GetCodeFixesFull,
241+
CommandNames.GetSupportedCodeFixes,
242+
CommandNames.GetApplicableRefactors,
243+
CommandNames.GetRefactorCodeActions,
244+
CommandNames.GetRefactorCodeActionsFull,
245+
];
246+
175247
it("should not throw when commands are executed with invalid arguments", () => {
176248
let i = 0;
177-
for (const name in CommandNames) {
178-
if (!Object.prototype.hasOwnProperty.call(CommandNames, name)) {
179-
continue;
180-
}
249+
for (const name of allCommandNames) {
181250
const req: protocol.Request = {
182251
command: name,
183252
seq: i,

Diff for: src/server/protocol.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
* Declaration module describing the TypeScript Server protocol
33
*/
44
namespace ts.server.protocol {
5-
export enum CommandTypes {
5+
// NOTE: If updating this, be sure to also update `allCommandNames` in `harness/unittests/session.ts`.
6+
export const enum CommandTypes {
67
Brace = "brace",
78
/* @internal */
89
BraceFull = "brace-full",

0 commit comments

Comments
 (0)