From f6240cb6f91fb202c8c0b8fc21d965fd83ea62b7 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Mon, 22 May 2017 11:17:12 -0700 Subject: [PATCH] Make CommandTypes a const enum and use `allCommandTypes` for unit test --- src/harness/unittests/session.ts | 77 ++++++++++++++++++++++++++++++-- src/server/protocol.ts | 3 +- 2 files changed, 75 insertions(+), 5 deletions(-) diff --git a/src/harness/unittests/session.ts b/src/harness/unittests/session.ts index 74d1f5d064084..db33d87f087d1 100644 --- a/src/harness/unittests/session.ts +++ b/src/harness/unittests/session.ts @@ -172,12 +172,81 @@ namespace ts.server { }); describe("onMessage", () => { + const allCommandNames: CommandNames[] = [ + CommandNames.Brace, + CommandNames.BraceFull, + CommandNames.BraceCompletion, + CommandNames.Change, + CommandNames.Close, + CommandNames.Completions, + CommandNames.CompletionsFull, + CommandNames.CompletionDetails, + CommandNames.CompileOnSaveAffectedFileList, + CommandNames.Configure, + CommandNames.Definition, + CommandNames.DefinitionFull, + CommandNames.Implementation, + CommandNames.ImplementationFull, + CommandNames.Exit, + CommandNames.Format, + CommandNames.Formatonkey, + CommandNames.FormatFull, + CommandNames.FormatonkeyFull, + CommandNames.FormatRangeFull, + CommandNames.Geterr, + CommandNames.GeterrForProject, + CommandNames.SemanticDiagnosticsSync, + CommandNames.SyntacticDiagnosticsSync, + CommandNames.NavBar, + CommandNames.NavBarFull, + CommandNames.Navto, + CommandNames.NavtoFull, + CommandNames.NavTree, + CommandNames.NavTreeFull, + CommandNames.Occurrences, + CommandNames.DocumentHighlights, + CommandNames.DocumentHighlightsFull, + CommandNames.Open, + CommandNames.Quickinfo, + CommandNames.QuickinfoFull, + CommandNames.References, + CommandNames.ReferencesFull, + CommandNames.Reload, + CommandNames.Rename, + CommandNames.RenameInfoFull, + CommandNames.RenameLocationsFull, + CommandNames.Saveto, + CommandNames.SignatureHelp, + CommandNames.SignatureHelpFull, + CommandNames.TypeDefinition, + CommandNames.ProjectInfo, + CommandNames.ReloadProjects, + CommandNames.Unknown, + CommandNames.OpenExternalProject, + CommandNames.CloseExternalProject, + CommandNames.SynchronizeProjectList, + CommandNames.ApplyChangedToOpenFiles, + CommandNames.EncodedSemanticClassificationsFull, + CommandNames.Cleanup, + CommandNames.OutliningSpans, + CommandNames.TodoComments, + CommandNames.Indentation, + CommandNames.DocCommentTemplate, + CommandNames.CompilerOptionsDiagnosticsFull, + CommandNames.NameOrDottedNameSpan, + CommandNames.BreakpointStatement, + CommandNames.CompilerOptionsForInferredProjects, + CommandNames.GetCodeFixes, + CommandNames.GetCodeFixesFull, + CommandNames.GetSupportedCodeFixes, + CommandNames.GetApplicableRefactors, + CommandNames.GetRefactorCodeActions, + CommandNames.GetRefactorCodeActionsFull, + ]; + it("should not throw when commands are executed with invalid arguments", () => { let i = 0; - for (const name in CommandNames) { - if (!Object.prototype.hasOwnProperty.call(CommandNames, name)) { - continue; - } + for (const name of allCommandNames) { const req: protocol.Request = { command: name, seq: i, diff --git a/src/server/protocol.ts b/src/server/protocol.ts index 8a75311c5d13b..4e474edd0c441 100644 --- a/src/server/protocol.ts +++ b/src/server/protocol.ts @@ -2,7 +2,8 @@ * Declaration module describing the TypeScript Server protocol */ namespace ts.server.protocol { - export enum CommandTypes { + // NOTE: If updating this, be sure to also update `allCommandNames` in `harness/unittests/session.ts`. + export const enum CommandTypes { Brace = "brace", /* @internal */ BraceFull = "brace-full",