Skip to content

Commit

Permalink
Use 2020 everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
orta committed Jul 6, 2020
1 parent 1c84d41 commit 6ba0d3f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 26 deletions.
42 changes: 21 additions & 21 deletions src/harness/fourslashImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2451,37 +2451,37 @@ namespace FourSlash {
private classificationToIdentifier(classification: number){

const tokenTypes: string[] = [];
tokenTypes[ts.classifier.modern.TokenType.class] = "class";
tokenTypes[ts.classifier.modern.TokenType.enum] = "enum";
tokenTypes[ts.classifier.modern.TokenType.interface] = "interface";
tokenTypes[ts.classifier.modern.TokenType.namespace] = "namespace";
tokenTypes[ts.classifier.modern.TokenType.typeParameter] = "typeParameter";
tokenTypes[ts.classifier.modern.TokenType.type] = "type";
tokenTypes[ts.classifier.modern.TokenType.parameter] = "parameter";
tokenTypes[ts.classifier.modern.TokenType.variable] = "variable";
tokenTypes[ts.classifier.modern.TokenType.enumMember] = "enumMember";
tokenTypes[ts.classifier.modern.TokenType.property] = "property";
tokenTypes[ts.classifier.modern.TokenType.function] = "function";
tokenTypes[ts.classifier.modern.TokenType.member] = "member";
tokenTypes[ts.classifier.v2020.TokenType.class] = "class";
tokenTypes[ts.classifier.v2020.TokenType.enum] = "enum";
tokenTypes[ts.classifier.v2020.TokenType.interface] = "interface";
tokenTypes[ts.classifier.v2020.TokenType.namespace] = "namespace";
tokenTypes[ts.classifier.v2020.TokenType.typeParameter] = "typeParameter";
tokenTypes[ts.classifier.v2020.TokenType.type] = "type";
tokenTypes[ts.classifier.v2020.TokenType.parameter] = "parameter";
tokenTypes[ts.classifier.v2020.TokenType.variable] = "variable";
tokenTypes[ts.classifier.v2020.TokenType.enumMember] = "enumMember";
tokenTypes[ts.classifier.v2020.TokenType.property] = "property";
tokenTypes[ts.classifier.v2020.TokenType.function] = "function";
tokenTypes[ts.classifier.v2020.TokenType.member] = "member";

const tokenModifiers: string[] = [];
tokenModifiers[ts.classifier.modern.TokenModifier.async] = "async";
tokenModifiers[ts.classifier.modern.TokenModifier.declaration] = "declaration";
tokenModifiers[ts.classifier.modern.TokenModifier.readonly] = "readonly";
tokenModifiers[ts.classifier.modern.TokenModifier.static] = "static";
tokenModifiers[ts.classifier.modern.TokenModifier.local] = "local";
tokenModifiers[ts.classifier.modern.TokenModifier.defaultLibrary] = "defaultLibrary";
tokenModifiers[ts.classifier.v2020.TokenModifier.async] = "async";
tokenModifiers[ts.classifier.v2020.TokenModifier.declaration] = "declaration";
tokenModifiers[ts.classifier.v2020.TokenModifier.readonly] = "readonly";
tokenModifiers[ts.classifier.v2020.TokenModifier.static] = "static";
tokenModifiers[ts.classifier.v2020.TokenModifier.local] = "local";
tokenModifiers[ts.classifier.v2020.TokenModifier.defaultLibrary] = "defaultLibrary";


function getTokenTypeFromClassification(tsClassification: number): number | undefined {
if (tsClassification > ts.classifier.modern.TokenEncodingConsts.modifierMask) {
return (tsClassification >> ts.classifier.modern.TokenEncodingConsts.typeOffset) - 1;
if (tsClassification > ts.classifier.v2020.TokenEncodingConsts.modifierMask) {
return (tsClassification >> ts.classifier.v2020.TokenEncodingConsts.typeOffset) - 1;
}
return undefined;
}

function getTokenModifierFromClassification(tsClassification: number) {
return tsClassification & ts.classifier.modern.TokenEncodingConsts.modifierMask;
return tsClassification & ts.classifier.v2020.TokenEncodingConsts.modifierMask;
}

const typeIdx = getTokenTypeFromClassification(classification) || 0;
Expand Down
14 changes: 12 additions & 2 deletions src/harness/fourslashInterfaceImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -752,12 +752,20 @@ namespace FourSlashInterface {
}
}

interface Classification {
classificationType: ts.ClassificationTypeNames | string;
interface OlderClassification {
classificationType: ts.ClassificationTypeNames;
text: string;
textSpan?: FourSlash.TextSpan;
}

// The VS Code LSP
interface ModernClassification {
classificationType: string;
text?: string;
textSpan?: FourSlash.TextSpan;
}

type Classification = OlderClassification | ModernClassification;

export function classification(format: ts.SemanticClassificationFormat) {

Expand All @@ -774,6 +782,8 @@ namespace FourSlashInterface {
};
}

// Defaults to the previous semantic classifier factory functions

function comment(text: string, position?: number): Classification {
return getClassification(ts.ClassificationTypeNames.comment, text, position);
}
Expand Down
2 changes: 1 addition & 1 deletion src/services/classifier2020.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** @internal */
namespace ts.classifier.modern {
namespace ts.classifier.v2020 {

/** @internal */
export const enum TokenEncodingConsts {
Expand Down
4 changes: 2 additions & 2 deletions src/services/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1806,7 +1806,7 @@ namespace ts {

const responseFormat = format || SemanticClassificationFormat.Original;
if (responseFormat === SemanticClassificationFormat.TwentyTwenty) {
return classifier.modern.getSemanticClassifications(program, cancellationToken, getValidSourceFile(fileName), span);
return classifier.v2020.getSemanticClassifications(program, cancellationToken, getValidSourceFile(fileName), span);
}
else {
return ts.getSemanticClassifications(program.getTypeChecker(), cancellationToken, getValidSourceFile(fileName), program.getClassifiableNames(), span);
Expand All @@ -1825,7 +1825,7 @@ namespace ts {
return ts.getEncodedSemanticClassifications(program.getTypeChecker(), cancellationToken, getValidSourceFile(fileName), program.getClassifiableNames(), span);
}
else {
return classifier.modern.getEncodedSemanticClassifications(program, cancellationToken, getValidSourceFile(fileName), span);
return classifier.v2020.getEncodedSemanticClassifications(program, cancellationToken, getValidSourceFile(fileName), span);
}
}

Expand Down

0 comments on commit 6ba0d3f

Please sign in to comment.