Skip to content

Commit

Permalink
Also convert ClassificationTypeNames and CommandTypes/CommandNames
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy Hanson committed May 22, 2017
1 parent b162097 commit f94818d
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 259 deletions.
105 changes: 55 additions & 50 deletions src/harness/fourslash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2174,7 +2174,7 @@ namespace FourSlash {
}

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

Expand Down Expand Up @@ -4071,102 +4071,107 @@ namespace FourSlashInterface {
}
}

interface Classification {
classificationType: ts.ClassificationTypeNames;
text: string;
textSpan?: FourSlash.TextSpan;
}
export namespace Classification {
export function comment(text: string, position?: number): { classificationType: string; text: string; textSpan?: FourSlash.TextSpan } {
return getClassification("comment", text, position);
export function comment(text: string, position?: number): Classification {
return getClassification(ts.ClassificationTypeNames.comment, text, position);
}

export function identifier(text: string, position?: number): { classificationType: string; text: string; textSpan?: FourSlash.TextSpan } {
return getClassification("identifier", text, position);
export function identifier(text: string, position?: number): Classification {
return getClassification(ts.ClassificationTypeNames.identifier, text, position);
}

export function keyword(text: string, position?: number): { classificationType: string; text: string; textSpan?: FourSlash.TextSpan } {
return getClassification("keyword", text, position);
export function keyword(text: string, position?: number): Classification {
return getClassification(ts.ClassificationTypeNames.keyword, text, position);
}

export function numericLiteral(text: string, position?: number): { classificationType: string; text: string; textSpan?: FourSlash.TextSpan } {
return getClassification("numericLiteral", text, position);
export function numericLiteral(text: string, position?: number): Classification {
return getClassification(ts.ClassificationTypeNames.numericLiteral, text, position);
}

export function operator(text: string, position?: number): { classificationType: string; text: string; textSpan?: FourSlash.TextSpan } {
return getClassification("operator", text, position);
export function operator(text: string, position?: number): Classification {
return getClassification(ts.ClassificationTypeNames.operator, text, position);
}

export function stringLiteral(text: string, position?: number): { classificationType: string; text: string; textSpan?: FourSlash.TextSpan } {
return getClassification("stringLiteral", text, position);
export function stringLiteral(text: string, position?: number): Classification {
return getClassification(ts.ClassificationTypeNames.stringLiteral, text, position);
}

export function whiteSpace(text: string, position?: number): { classificationType: string; text: string; textSpan?: FourSlash.TextSpan } {
return getClassification("whiteSpace", text, position);
export function whiteSpace(text: string, position?: number): Classification {
return getClassification(ts.ClassificationTypeNames.whiteSpace, text, position);
}

export function text(text: string, position?: number): { classificationType: string; text: string; textSpan?: FourSlash.TextSpan } {
return getClassification("text", text, position);
export function text(text: string, position?: number): Classification {
return getClassification(ts.ClassificationTypeNames.text, text, position);
}

export function punctuation(text: string, position?: number): { classificationType: string; text: string; textSpan?: FourSlash.TextSpan } {
return getClassification("punctuation", text, position);
export function punctuation(text: string, position?: number): Classification {
return getClassification(ts.ClassificationTypeNames.punctuation, text, position);
}

export function docCommentTagName(text: string, position?: number): { classificationType: string; text: string; textSpan?: FourSlash.TextSpan } {
return getClassification("docCommentTagName", text, position);
export function docCommentTagName(text: string, position?: number): Classification {
return getClassification(ts.ClassificationTypeNames.docCommentTagName, text, position);
}

export function className(text: string, position?: number): { classificationType: string; text: string; textSpan?: FourSlash.TextSpan } {
return getClassification("className", text, position);
export function className(text: string, position?: number): Classification {
return getClassification(ts.ClassificationTypeNames.className, text, position);
}

export function enumName(text: string, position?: number): { classificationType: string; text: string; textSpan?: FourSlash.TextSpan } {
return getClassification("enumName", text, position);
export function enumName(text: string, position?: number): Classification {
return getClassification(ts.ClassificationTypeNames.enumName, text, position);
}

export function interfaceName(text: string, position?: number): { classificationType: string; text: string; textSpan?: FourSlash.TextSpan } {
return getClassification("interfaceName", text, position);
export function interfaceName(text: string, position?: number): Classification {
return getClassification(ts.ClassificationTypeNames.interfaceName, text, position);
}

export function moduleName(text: string, position?: number): { classificationType: string; text: string; textSpan?: FourSlash.TextSpan } {
return getClassification("moduleName", text, position);
export function moduleName(text: string, position?: number): Classification {
return getClassification(ts.ClassificationTypeNames.moduleName, text, position);
}

export function typeParameterName(text: string, position?: number): { classificationType: string; text: string; textSpan?: FourSlash.TextSpan } {
return getClassification("typeParameterName", text, position);
export function typeParameterName(text: string, position?: number): Classification {
return getClassification(ts.ClassificationTypeNames.typeParameterName, text, position);
}

export function parameterName(text: string, position?: number): { classificationType: string; text: string; textSpan?: FourSlash.TextSpan } {
return getClassification("parameterName", text, position);
export function parameterName(text: string, position?: number): Classification {
return getClassification(ts.ClassificationTypeNames.parameterName, text, position);
}

export function typeAliasName(text: string, position?: number): { classificationType: string; text: string; textSpan?: FourSlash.TextSpan } {
return getClassification("typeAliasName", text, position);
export function typeAliasName(text: string, position?: number): Classification {
return getClassification(ts.ClassificationTypeNames.typeAliasName, text, position);
}

export function jsxOpenTagName(text: string, position?: number): { classificationType: string; text: string; textSpan?: FourSlash.TextSpan } {
return getClassification("jsxOpenTagName", text, position);
export function jsxOpenTagName(text: string, position?: number): Classification {
return getClassification(ts.ClassificationTypeNames.jsxOpenTagName, text, position);
}

export function jsxCloseTagName(text: string, position?: number): { classificationType: string; text: string; textSpan?: FourSlash.TextSpan } {
return getClassification("jsxCloseTagName", text, position);
export function jsxCloseTagName(text: string, position?: number): Classification {
return getClassification(ts.ClassificationTypeNames.jsxCloseTagName, text, position);
}

export function jsxSelfClosingTagName(text: string, position?: number): { classificationType: string; text: string; textSpan?: FourSlash.TextSpan } {
return getClassification("jsxSelfClosingTagName", text, position);
export function jsxSelfClosingTagName(text: string, position?: number): Classification {
return getClassification(ts.ClassificationTypeNames.jsxSelfClosingTagName, text, position);
}

export function jsxAttribute(text: string, position?: number): { classificationType: string; text: string; textSpan?: FourSlash.TextSpan } {
return getClassification("jsxAttribute", text, position);
export function jsxAttribute(text: string, position?: number): Classification {
return getClassification(ts.ClassificationTypeNames.jsxAttribute, text, position);
}

export function jsxText(text: string, position?: number): { classificationType: string; text: string; textSpan?: FourSlash.TextSpan } {
return getClassification("jsxText", text, position);
export function jsxText(text: string, position?: number): Classification {
return getClassification(ts.ClassificationTypeNames.jsxText, text, position);
}

export function jsxAttributeStringLiteralValue(text: string, position?: number): { classificationType: string; text: string; textSpan?: FourSlash.TextSpan } {
return getClassification("jsxAttributeStringLiteralValue", text, position);
export function jsxAttributeStringLiteralValue(text: string, position?: number): Classification {
return getClassification(ts.ClassificationTypeNames.jsxAttributeStringLiteralValue, text, position);
}

function getClassification(type: string, text: string, position?: number) {
function getClassification(classificationType: ts.ClassificationTypeNames, text: string, position?: number): Classification {
return {
classificationType: type,
classificationType,
text: text,
textSpan: position === undefined ? undefined : { start: position, end: position + text.length }
};
Expand Down
144 changes: 72 additions & 72 deletions src/server/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,103 +2,103 @@
* Declaration module describing the TypeScript Server protocol
*/
namespace ts.server.protocol {
export namespace CommandTypes {
export type Brace = "brace";
export enum CommandTypes {
Brace = "brace",
/* @internal */
export type BraceFull = "brace-full";
export type BraceCompletion = "braceCompletion";
export type Change = "change";
export type Close = "close";
export type Completions = "completions";
BraceFull = "brace-full",
BraceCompletion = "braceCompletion",
Change = "change",
Close = "close",
Completions = "completions",
/* @internal */
export type CompletionsFull = "completions-full";
export type CompletionDetails = "completionEntryDetails";
export type CompileOnSaveAffectedFileList = "compileOnSaveAffectedFileList";
export type CompileOnSaveEmitFile = "compileOnSaveEmitFile";
export type Configure = "configure";
export type Definition = "definition";
CompletionsFull = "completions-full",
CompletionDetails = "completionEntryDetails",
CompileOnSaveAffectedFileList = "compileOnSaveAffectedFileList",
CompileOnSaveEmitFile = "compileOnSaveEmitFile",
Configure = "configure",
Definition = "definition",
/* @internal */
export type DefinitionFull = "definition-full";
export type Implementation = "implementation";
DefinitionFull = "definition-full",
Implementation = "implementation",
/* @internal */
export type ImplementationFull = "implementation-full";
export type Exit = "exit";
export type Format = "format";
export type Formatonkey = "formatonkey";
ImplementationFull = "implementation-full",
Exit = "exit",
Format = "format",
Formatonkey = "formatonkey",
/* @internal */
export type FormatFull = "format-full";
FormatFull = "format-full",
/* @internal */
export type FormatonkeyFull = "formatonkey-full";
FormatonkeyFull = "formatonkey-full",
/* @internal */
export type FormatRangeFull = "formatRange-full";
export type Geterr = "geterr";
export type GeterrForProject = "geterrForProject";
export type SemanticDiagnosticsSync = "semanticDiagnosticsSync";
export type SyntacticDiagnosticsSync = "syntacticDiagnosticsSync";
export type NavBar = "navbar";
FormatRangeFull = "formatRange-full",
Geterr = "geterr",
GeterrForProject = "geterrForProject",
SemanticDiagnosticsSync = "semanticDiagnosticsSync",
SyntacticDiagnosticsSync = "syntacticDiagnosticsSync",
NavBar = "navbar",
/* @internal */
export type NavBarFull = "navbar-full";
export type Navto = "navto";
NavBarFull = "navbar-full",
Navto = "navto",
/* @internal */
export type NavtoFull = "navto-full";
export type NavTree = "navtree";
export type NavTreeFull = "navtree-full";
export type Occurrences = "occurrences";
export type DocumentHighlights = "documentHighlights";
NavtoFull = "navto-full",
NavTree = "navtree",
NavTreeFull = "navtree-full",
Occurrences = "occurrences",
DocumentHighlights = "documentHighlights",
/* @internal */
export type DocumentHighlightsFull = "documentHighlights-full";
export type Open = "open";
export type Quickinfo = "quickinfo";
DocumentHighlightsFull = "documentHighlights-full",
Open = "open",
Quickinfo = "quickinfo",
/* @internal */
export type QuickinfoFull = "quickinfo-full";
export type References = "references";
QuickinfoFull = "quickinfo-full",
References = "references",
/* @internal */
export type ReferencesFull = "references-full";
export type Reload = "reload";
export type Rename = "rename";
ReferencesFull = "references-full",
Reload = "reload",
Rename = "rename",
/* @internal */
export type RenameInfoFull = "rename-full";
RenameInfoFull = "rename-full",
/* @internal */
export type RenameLocationsFull = "renameLocations-full";
export type Saveto = "saveto";
export type SignatureHelp = "signatureHelp";
RenameLocationsFull = "renameLocations-full",
Saveto = "saveto",
SignatureHelp = "signatureHelp",
/* @internal */
export type SignatureHelpFull = "signatureHelp-full";
export type TypeDefinition = "typeDefinition";
export type ProjectInfo = "projectInfo";
export type ReloadProjects = "reloadProjects";
export type Unknown = "unknown";
export type OpenExternalProject = "openExternalProject";
export type OpenExternalProjects = "openExternalProjects";
export type CloseExternalProject = "closeExternalProject";
SignatureHelpFull = "signatureHelp-full",
TypeDefinition = "typeDefinition",
ProjectInfo = "projectInfo",
ReloadProjects = "reloadProjects",
Unknown = "unknown",
OpenExternalProject = "openExternalProject",
OpenExternalProjects = "openExternalProjects",
CloseExternalProject = "closeExternalProject",
/* @internal */
export type SynchronizeProjectList = "synchronizeProjectList";
SynchronizeProjectList = "synchronizeProjectList",
/* @internal */
export type ApplyChangedToOpenFiles = "applyChangedToOpenFiles";
ApplyChangedToOpenFiles = "applyChangedToOpenFiles",
/* @internal */
export type EncodedSemanticClassificationsFull = "encodedSemanticClassifications-full";
EncodedSemanticClassificationsFull = "encodedSemanticClassifications-full",
/* @internal */
export type Cleanup = "cleanup";
Cleanup = "cleanup",
/* @internal */
export type OutliningSpans = "outliningSpans";
export type TodoComments = "todoComments";
export type Indentation = "indentation";
export type DocCommentTemplate = "docCommentTemplate";
OutliningSpans = "outliningSpans",
TodoComments = "todoComments",
Indentation = "indentation",
DocCommentTemplate = "docCommentTemplate",
/* @internal */
export type CompilerOptionsDiagnosticsFull = "compilerOptionsDiagnostics-full";
CompilerOptionsDiagnosticsFull = "compilerOptionsDiagnostics-full",
/* @internal */
export type NameOrDottedNameSpan = "nameOrDottedNameSpan";
NameOrDottedNameSpan = "nameOrDottedNameSpan",
/* @internal */
export type BreakpointStatement = "breakpointStatement";
export type CompilerOptionsForInferredProjects = "compilerOptionsForInferredProjects";
export type GetCodeFixes = "getCodeFixes";
BreakpointStatement = "breakpointStatement",
CompilerOptionsForInferredProjects = "compilerOptionsForInferredProjects",
GetCodeFixes = "getCodeFixes",
/* @internal */
export type GetCodeFixesFull = "getCodeFixes-full";
export type GetSupportedCodeFixes = "getSupportedCodeFixes";
GetCodeFixesFull = "getCodeFixes-full",
GetSupportedCodeFixes = "getSupportedCodeFixes",

export type GetApplicableRefactors = "getApplicableRefactors";
export type GetRefactorCodeActions = "getRefactorCodeActions";
export type GetRefactorCodeActionsFull = "getRefactorCodeActions-full";
GetApplicableRefactors = "getApplicableRefactors",
GetRefactorCodeActions = "getRefactorCodeActions",
GetRefactorCodeActionsFull = "getRefactorCodeActions-full",
}

/**
Expand Down
Loading

0 comments on commit f94818d

Please sign in to comment.