Skip to content

Commit f94818d

Browse files
author
Andy Hanson
committed
Also convert ClassificationTypeNames and CommandTypes/CommandNames
1 parent b162097 commit f94818d

File tree

5 files changed

+167
-259
lines changed

5 files changed

+167
-259
lines changed

src/harness/fourslash.ts

+55-50
Original file line numberDiff line numberDiff line change
@@ -2174,7 +2174,7 @@ namespace FourSlash {
21742174
}
21752175

21762176
ts.zipWith(expected, actual, (expectedClassification, actualClassification) => {
2177-
const expectedType: string = (<any>ts.ClassificationTypeNames)[expectedClassification.classificationType];
2177+
const expectedType = expectedClassification.classificationType;
21782178
if (expectedType !== actualClassification.classificationType) {
21792179
this.raiseError("verifyClassifications failed - expected classifications type to be " +
21802180
expectedType + ", but was " +
@@ -3876,7 +3876,7 @@ namespace FourSlashInterface {
38763876
/**
38773877
* This method *requires* an ordered stream of classifications for a file, and spans are highly recommended.
38783878
*/
3879-
public semanticClassificationsAre(...classifications: { classificationType: string; text: string; textSpan?: FourSlash.TextSpan }[]) {
3879+
public semanticClassificationsAre(...classifications: Classification[]) {
38803880
this.state.verifySemanticClassifications(classifications);
38813881
}
38823882

@@ -4071,102 +4071,107 @@ namespace FourSlashInterface {
40714071
}
40724072
}
40734073

4074+
interface Classification {
4075+
classificationType: ts.ClassificationTypeNames;
4076+
text: string;
4077+
textSpan?: FourSlash.TextSpan;
4078+
}
40744079
export namespace Classification {
4075-
export function comment(text: string, position?: number): { classificationType: string; text: string; textSpan?: FourSlash.TextSpan } {
4076-
return getClassification("comment", text, position);
4080+
export function comment(text: string, position?: number): Classification {
4081+
return getClassification(ts.ClassificationTypeNames.comment, text, position);
40774082
}
40784083

4079-
export function identifier(text: string, position?: number): { classificationType: string; text: string; textSpan?: FourSlash.TextSpan } {
4080-
return getClassification("identifier", text, position);
4084+
export function identifier(text: string, position?: number): Classification {
4085+
return getClassification(ts.ClassificationTypeNames.identifier, text, position);
40814086
}
40824087

4083-
export function keyword(text: string, position?: number): { classificationType: string; text: string; textSpan?: FourSlash.TextSpan } {
4084-
return getClassification("keyword", text, position);
4088+
export function keyword(text: string, position?: number): Classification {
4089+
return getClassification(ts.ClassificationTypeNames.keyword, text, position);
40854090
}
40864091

4087-
export function numericLiteral(text: string, position?: number): { classificationType: string; text: string; textSpan?: FourSlash.TextSpan } {
4088-
return getClassification("numericLiteral", text, position);
4092+
export function numericLiteral(text: string, position?: number): Classification {
4093+
return getClassification(ts.ClassificationTypeNames.numericLiteral, text, position);
40894094
}
40904095

4091-
export function operator(text: string, position?: number): { classificationType: string; text: string; textSpan?: FourSlash.TextSpan } {
4092-
return getClassification("operator", text, position);
4096+
export function operator(text: string, position?: number): Classification {
4097+
return getClassification(ts.ClassificationTypeNames.operator, text, position);
40934098
}
40944099

4095-
export function stringLiteral(text: string, position?: number): { classificationType: string; text: string; textSpan?: FourSlash.TextSpan } {
4096-
return getClassification("stringLiteral", text, position);
4100+
export function stringLiteral(text: string, position?: number): Classification {
4101+
return getClassification(ts.ClassificationTypeNames.stringLiteral, text, position);
40974102
}
40984103

4099-
export function whiteSpace(text: string, position?: number): { classificationType: string; text: string; textSpan?: FourSlash.TextSpan } {
4100-
return getClassification("whiteSpace", text, position);
4104+
export function whiteSpace(text: string, position?: number): Classification {
4105+
return getClassification(ts.ClassificationTypeNames.whiteSpace, text, position);
41014106
}
41024107

4103-
export function text(text: string, position?: number): { classificationType: string; text: string; textSpan?: FourSlash.TextSpan } {
4104-
return getClassification("text", text, position);
4108+
export function text(text: string, position?: number): Classification {
4109+
return getClassification(ts.ClassificationTypeNames.text, text, position);
41054110
}
41064111

4107-
export function punctuation(text: string, position?: number): { classificationType: string; text: string; textSpan?: FourSlash.TextSpan } {
4108-
return getClassification("punctuation", text, position);
4112+
export function punctuation(text: string, position?: number): Classification {
4113+
return getClassification(ts.ClassificationTypeNames.punctuation, text, position);
41094114
}
41104115

4111-
export function docCommentTagName(text: string, position?: number): { classificationType: string; text: string; textSpan?: FourSlash.TextSpan } {
4112-
return getClassification("docCommentTagName", text, position);
4116+
export function docCommentTagName(text: string, position?: number): Classification {
4117+
return getClassification(ts.ClassificationTypeNames.docCommentTagName, text, position);
41134118
}
41144119

4115-
export function className(text: string, position?: number): { classificationType: string; text: string; textSpan?: FourSlash.TextSpan } {
4116-
return getClassification("className", text, position);
4120+
export function className(text: string, position?: number): Classification {
4121+
return getClassification(ts.ClassificationTypeNames.className, text, position);
41174122
}
41184123

4119-
export function enumName(text: string, position?: number): { classificationType: string; text: string; textSpan?: FourSlash.TextSpan } {
4120-
return getClassification("enumName", text, position);
4124+
export function enumName(text: string, position?: number): Classification {
4125+
return getClassification(ts.ClassificationTypeNames.enumName, text, position);
41214126
}
41224127

4123-
export function interfaceName(text: string, position?: number): { classificationType: string; text: string; textSpan?: FourSlash.TextSpan } {
4124-
return getClassification("interfaceName", text, position);
4128+
export function interfaceName(text: string, position?: number): Classification {
4129+
return getClassification(ts.ClassificationTypeNames.interfaceName, text, position);
41254130
}
41264131

4127-
export function moduleName(text: string, position?: number): { classificationType: string; text: string; textSpan?: FourSlash.TextSpan } {
4128-
return getClassification("moduleName", text, position);
4132+
export function moduleName(text: string, position?: number): Classification {
4133+
return getClassification(ts.ClassificationTypeNames.moduleName, text, position);
41294134
}
41304135

4131-
export function typeParameterName(text: string, position?: number): { classificationType: string; text: string; textSpan?: FourSlash.TextSpan } {
4132-
return getClassification("typeParameterName", text, position);
4136+
export function typeParameterName(text: string, position?: number): Classification {
4137+
return getClassification(ts.ClassificationTypeNames.typeParameterName, text, position);
41334138
}
41344139

4135-
export function parameterName(text: string, position?: number): { classificationType: string; text: string; textSpan?: FourSlash.TextSpan } {
4136-
return getClassification("parameterName", text, position);
4140+
export function parameterName(text: string, position?: number): Classification {
4141+
return getClassification(ts.ClassificationTypeNames.parameterName, text, position);
41374142
}
41384143

4139-
export function typeAliasName(text: string, position?: number): { classificationType: string; text: string; textSpan?: FourSlash.TextSpan } {
4140-
return getClassification("typeAliasName", text, position);
4144+
export function typeAliasName(text: string, position?: number): Classification {
4145+
return getClassification(ts.ClassificationTypeNames.typeAliasName, text, position);
41414146
}
41424147

4143-
export function jsxOpenTagName(text: string, position?: number): { classificationType: string; text: string; textSpan?: FourSlash.TextSpan } {
4144-
return getClassification("jsxOpenTagName", text, position);
4148+
export function jsxOpenTagName(text: string, position?: number): Classification {
4149+
return getClassification(ts.ClassificationTypeNames.jsxOpenTagName, text, position);
41454150
}
41464151

4147-
export function jsxCloseTagName(text: string, position?: number): { classificationType: string; text: string; textSpan?: FourSlash.TextSpan } {
4148-
return getClassification("jsxCloseTagName", text, position);
4152+
export function jsxCloseTagName(text: string, position?: number): Classification {
4153+
return getClassification(ts.ClassificationTypeNames.jsxCloseTagName, text, position);
41494154
}
41504155

4151-
export function jsxSelfClosingTagName(text: string, position?: number): { classificationType: string; text: string; textSpan?: FourSlash.TextSpan } {
4152-
return getClassification("jsxSelfClosingTagName", text, position);
4156+
export function jsxSelfClosingTagName(text: string, position?: number): Classification {
4157+
return getClassification(ts.ClassificationTypeNames.jsxSelfClosingTagName, text, position);
41534158
}
41544159

4155-
export function jsxAttribute(text: string, position?: number): { classificationType: string; text: string; textSpan?: FourSlash.TextSpan } {
4156-
return getClassification("jsxAttribute", text, position);
4160+
export function jsxAttribute(text: string, position?: number): Classification {
4161+
return getClassification(ts.ClassificationTypeNames.jsxAttribute, text, position);
41574162
}
41584163

4159-
export function jsxText(text: string, position?: number): { classificationType: string; text: string; textSpan?: FourSlash.TextSpan } {
4160-
return getClassification("jsxText", text, position);
4164+
export function jsxText(text: string, position?: number): Classification {
4165+
return getClassification(ts.ClassificationTypeNames.jsxText, text, position);
41614166
}
41624167

4163-
export function jsxAttributeStringLiteralValue(text: string, position?: number): { classificationType: string; text: string; textSpan?: FourSlash.TextSpan } {
4164-
return getClassification("jsxAttributeStringLiteralValue", text, position);
4168+
export function jsxAttributeStringLiteralValue(text: string, position?: number): Classification {
4169+
return getClassification(ts.ClassificationTypeNames.jsxAttributeStringLiteralValue, text, position);
41654170
}
41664171

4167-
function getClassification(type: string, text: string, position?: number) {
4172+
function getClassification(classificationType: ts.ClassificationTypeNames, text: string, position?: number): Classification {
41684173
return {
4169-
classificationType: type,
4174+
classificationType,
41704175
text: text,
41714176
textSpan: position === undefined ? undefined : { start: position, end: position + text.length }
41724177
};

src/server/protocol.ts

+72-72
Original file line numberDiff line numberDiff line change
@@ -2,103 +2,103 @@
22
* Declaration module describing the TypeScript Server protocol
33
*/
44
namespace ts.server.protocol {
5-
export namespace CommandTypes {
6-
export type Brace = "brace";
5+
export enum CommandTypes {
6+
Brace = "brace",
77
/* @internal */
8-
export type BraceFull = "brace-full";
9-
export type BraceCompletion = "braceCompletion";
10-
export type Change = "change";
11-
export type Close = "close";
12-
export type Completions = "completions";
8+
BraceFull = "brace-full",
9+
BraceCompletion = "braceCompletion",
10+
Change = "change",
11+
Close = "close",
12+
Completions = "completions",
1313
/* @internal */
14-
export type CompletionsFull = "completions-full";
15-
export type CompletionDetails = "completionEntryDetails";
16-
export type CompileOnSaveAffectedFileList = "compileOnSaveAffectedFileList";
17-
export type CompileOnSaveEmitFile = "compileOnSaveEmitFile";
18-
export type Configure = "configure";
19-
export type Definition = "definition";
14+
CompletionsFull = "completions-full",
15+
CompletionDetails = "completionEntryDetails",
16+
CompileOnSaveAffectedFileList = "compileOnSaveAffectedFileList",
17+
CompileOnSaveEmitFile = "compileOnSaveEmitFile",
18+
Configure = "configure",
19+
Definition = "definition",
2020
/* @internal */
21-
export type DefinitionFull = "definition-full";
22-
export type Implementation = "implementation";
21+
DefinitionFull = "definition-full",
22+
Implementation = "implementation",
2323
/* @internal */
24-
export type ImplementationFull = "implementation-full";
25-
export type Exit = "exit";
26-
export type Format = "format";
27-
export type Formatonkey = "formatonkey";
24+
ImplementationFull = "implementation-full",
25+
Exit = "exit",
26+
Format = "format",
27+
Formatonkey = "formatonkey",
2828
/* @internal */
29-
export type FormatFull = "format-full";
29+
FormatFull = "format-full",
3030
/* @internal */
31-
export type FormatonkeyFull = "formatonkey-full";
31+
FormatonkeyFull = "formatonkey-full",
3232
/* @internal */
33-
export type FormatRangeFull = "formatRange-full";
34-
export type Geterr = "geterr";
35-
export type GeterrForProject = "geterrForProject";
36-
export type SemanticDiagnosticsSync = "semanticDiagnosticsSync";
37-
export type SyntacticDiagnosticsSync = "syntacticDiagnosticsSync";
38-
export type NavBar = "navbar";
33+
FormatRangeFull = "formatRange-full",
34+
Geterr = "geterr",
35+
GeterrForProject = "geterrForProject",
36+
SemanticDiagnosticsSync = "semanticDiagnosticsSync",
37+
SyntacticDiagnosticsSync = "syntacticDiagnosticsSync",
38+
NavBar = "navbar",
3939
/* @internal */
40-
export type NavBarFull = "navbar-full";
41-
export type Navto = "navto";
40+
NavBarFull = "navbar-full",
41+
Navto = "navto",
4242
/* @internal */
43-
export type NavtoFull = "navto-full";
44-
export type NavTree = "navtree";
45-
export type NavTreeFull = "navtree-full";
46-
export type Occurrences = "occurrences";
47-
export type DocumentHighlights = "documentHighlights";
43+
NavtoFull = "navto-full",
44+
NavTree = "navtree",
45+
NavTreeFull = "navtree-full",
46+
Occurrences = "occurrences",
47+
DocumentHighlights = "documentHighlights",
4848
/* @internal */
49-
export type DocumentHighlightsFull = "documentHighlights-full";
50-
export type Open = "open";
51-
export type Quickinfo = "quickinfo";
49+
DocumentHighlightsFull = "documentHighlights-full",
50+
Open = "open",
51+
Quickinfo = "quickinfo",
5252
/* @internal */
53-
export type QuickinfoFull = "quickinfo-full";
54-
export type References = "references";
53+
QuickinfoFull = "quickinfo-full",
54+
References = "references",
5555
/* @internal */
56-
export type ReferencesFull = "references-full";
57-
export type Reload = "reload";
58-
export type Rename = "rename";
56+
ReferencesFull = "references-full",
57+
Reload = "reload",
58+
Rename = "rename",
5959
/* @internal */
60-
export type RenameInfoFull = "rename-full";
60+
RenameInfoFull = "rename-full",
6161
/* @internal */
62-
export type RenameLocationsFull = "renameLocations-full";
63-
export type Saveto = "saveto";
64-
export type SignatureHelp = "signatureHelp";
62+
RenameLocationsFull = "renameLocations-full",
63+
Saveto = "saveto",
64+
SignatureHelp = "signatureHelp",
6565
/* @internal */
66-
export type SignatureHelpFull = "signatureHelp-full";
67-
export type TypeDefinition = "typeDefinition";
68-
export type ProjectInfo = "projectInfo";
69-
export type ReloadProjects = "reloadProjects";
70-
export type Unknown = "unknown";
71-
export type OpenExternalProject = "openExternalProject";
72-
export type OpenExternalProjects = "openExternalProjects";
73-
export type CloseExternalProject = "closeExternalProject";
66+
SignatureHelpFull = "signatureHelp-full",
67+
TypeDefinition = "typeDefinition",
68+
ProjectInfo = "projectInfo",
69+
ReloadProjects = "reloadProjects",
70+
Unknown = "unknown",
71+
OpenExternalProject = "openExternalProject",
72+
OpenExternalProjects = "openExternalProjects",
73+
CloseExternalProject = "closeExternalProject",
7474
/* @internal */
75-
export type SynchronizeProjectList = "synchronizeProjectList";
75+
SynchronizeProjectList = "synchronizeProjectList",
7676
/* @internal */
77-
export type ApplyChangedToOpenFiles = "applyChangedToOpenFiles";
77+
ApplyChangedToOpenFiles = "applyChangedToOpenFiles",
7878
/* @internal */
79-
export type EncodedSemanticClassificationsFull = "encodedSemanticClassifications-full";
79+
EncodedSemanticClassificationsFull = "encodedSemanticClassifications-full",
8080
/* @internal */
81-
export type Cleanup = "cleanup";
81+
Cleanup = "cleanup",
8282
/* @internal */
83-
export type OutliningSpans = "outliningSpans";
84-
export type TodoComments = "todoComments";
85-
export type Indentation = "indentation";
86-
export type DocCommentTemplate = "docCommentTemplate";
83+
OutliningSpans = "outliningSpans",
84+
TodoComments = "todoComments",
85+
Indentation = "indentation",
86+
DocCommentTemplate = "docCommentTemplate",
8787
/* @internal */
88-
export type CompilerOptionsDiagnosticsFull = "compilerOptionsDiagnostics-full";
88+
CompilerOptionsDiagnosticsFull = "compilerOptionsDiagnostics-full",
8989
/* @internal */
90-
export type NameOrDottedNameSpan = "nameOrDottedNameSpan";
90+
NameOrDottedNameSpan = "nameOrDottedNameSpan",
9191
/* @internal */
92-
export type BreakpointStatement = "breakpointStatement";
93-
export type CompilerOptionsForInferredProjects = "compilerOptionsForInferredProjects";
94-
export type GetCodeFixes = "getCodeFixes";
92+
BreakpointStatement = "breakpointStatement",
93+
CompilerOptionsForInferredProjects = "compilerOptionsForInferredProjects",
94+
GetCodeFixes = "getCodeFixes",
9595
/* @internal */
96-
export type GetCodeFixesFull = "getCodeFixes-full";
97-
export type GetSupportedCodeFixes = "getSupportedCodeFixes";
96+
GetCodeFixesFull = "getCodeFixes-full",
97+
GetSupportedCodeFixes = "getSupportedCodeFixes",
9898

99-
export type GetApplicableRefactors = "getApplicableRefactors";
100-
export type GetRefactorCodeActions = "getRefactorCodeActions";
101-
export type GetRefactorCodeActionsFull = "getRefactorCodeActions-full";
99+
GetApplicableRefactors = "getApplicableRefactors",
100+
GetRefactorCodeActions = "getRefactorCodeActions",
101+
GetRefactorCodeActionsFull = "getRefactorCodeActions-full",
102102
}
103103

104104
/**

0 commit comments

Comments
 (0)