From 5841110b2d65accde4ddd41228cacc17ee0fe6fa Mon Sep 17 00:00:00 2001 From: Orta Therox Date: Mon, 22 Jun 2020 15:33:19 -0400 Subject: [PATCH] Handle feedback from #39119 --- src/compiler/types.ts | 5 -- src/harness/fourslashImpl.ts | 56 +++++++++---------- ...{classifierVscode.ts => classifier2020.ts} | 3 +- src/services/services.ts | 4 +- src/services/tsconfig.json | 2 +- src/services/types.ts | 5 ++ 6 files changed, 37 insertions(+), 38 deletions(-) rename src/services/{classifierVscode.ts => classifier2020.ts} (96%) diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 557845466cf2e..05ad94c7599f1 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -7766,11 +7766,6 @@ namespace ts { newLength: number; } - export const enum SemanticClassificationFormat { - Original = "original", - TwentyTwenty = "2020" - } - /* @internal */ export interface DiagnosticCollection { // Adds a diagnostic to this diagnostic collection. diff --git a/src/harness/fourslashImpl.ts b/src/harness/fourslashImpl.ts index 54f7405a88873..7603dfb58602a 100644 --- a/src/harness/fourslashImpl.ts +++ b/src/harness/fourslashImpl.ts @@ -2451,37 +2451,37 @@ namespace FourSlash { private classificationToIdentifier(classification: number){ const tokenTypes: string[] = []; - tokenTypes[ts.classifier.vscode.TokenType.class] = "class"; - tokenTypes[ts.classifier.vscode.TokenType.enum] = "enum"; - tokenTypes[ts.classifier.vscode.TokenType.interface] = "interface"; - tokenTypes[ts.classifier.vscode.TokenType.namespace] = "namespace"; - tokenTypes[ts.classifier.vscode.TokenType.typeParameter] = "typeParameter"; - tokenTypes[ts.classifier.vscode.TokenType.type] = "type"; - tokenTypes[ts.classifier.vscode.TokenType.parameter] = "parameter"; - tokenTypes[ts.classifier.vscode.TokenType.variable] = "variable"; - tokenTypes[ts.classifier.vscode.TokenType.enumMember] = "enumMember"; - tokenTypes[ts.classifier.vscode.TokenType.property] = "property"; - tokenTypes[ts.classifier.vscode.TokenType.function] = "function"; - tokenTypes[ts.classifier.vscode.TokenType.member] = "member"; + 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"; const tokenModifiers: string[] = []; - tokenModifiers[ts.classifier.vscode.TokenModifier.async] = "async"; - tokenModifiers[ts.classifier.vscode.TokenModifier.declaration] = "declaration"; - tokenModifiers[ts.classifier.vscode.TokenModifier.readonly] = "readonly"; - tokenModifiers[ts.classifier.vscode.TokenModifier.static] = "static"; - tokenModifiers[ts.classifier.vscode.TokenModifier.local] = "local"; - tokenModifiers[ts.classifier.vscode.TokenModifier.defaultLibrary] = "defaultLibrary"; + 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"; function getTokenTypeFromClassification(tsClassification: number): number | undefined { - if (tsClassification > ts.classifier.vscode.TokenEncodingConsts.modifierMask) { - return (tsClassification >> ts.classifier.vscode.TokenEncodingConsts.typeOffset) - 1; + if (tsClassification > ts.classifier.modern.TokenEncodingConsts.modifierMask) { + return (tsClassification >> ts.classifier.modern.TokenEncodingConsts.typeOffset) - 1; } return undefined; } function getTokenModifierFromClassification(tsClassification: number) { - return tsClassification & ts.classifier.vscode.TokenEncodingConsts.modifierMask; + return tsClassification & ts.classifier.modern.TokenEncodingConsts.modifierMask; } const typeIdx = getTokenTypeFromClassification(classification) || 0; @@ -2566,15 +2566,13 @@ namespace FourSlash { }); replacement.push(");"); - // throw new Error("You need to change the source code of fourslash test to use replaceWithSemanticClassifications"); - - - const fs = require("fs"); - const testfilePath = this.originalInputFileName.slice(1); - const testfile = fs.readFileSync(testfilePath, "utf8"); - const newfile = testfile.replace("verify.replaceWithSemanticClassifications(\"2020\")", replacement.join("\n")); - fs.writeFileSync(testfilePath, newfile); + throw new Error("You need to change the source code of fourslash test to use replaceWithSemanticClassifications"); + // const fs = require("fs"); + // const testfilePath = this.originalInputFileName.slice(1); + // const testfile = fs.readFileSync(testfilePath, "utf8"); + // const newfile = testfile.replace("verify.replaceWithSemanticClassifications(\"2020\")", replacement.join("\n")); + // fs.writeFileSync(testfilePath, newfile); } diff --git a/src/services/classifierVscode.ts b/src/services/classifier2020.ts similarity index 96% rename from src/services/classifierVscode.ts rename to src/services/classifier2020.ts index 2d3a382cc9574..f8f02c13b2bcb 100644 --- a/src/services/classifierVscode.ts +++ b/src/services/classifier2020.ts @@ -1,4 +1,5 @@ -namespace ts.classifier.vscode { +/** @internal */ +namespace ts.classifier.modern { /** @internal */ export enum TokenEncodingConsts { diff --git a/src/services/services.ts b/src/services/services.ts index 04502be4b4fbf..f4b300059aea9 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1809,7 +1809,7 @@ namespace ts { return ts.getSemanticClassifications(program.getTypeChecker(), cancellationToken, getValidSourceFile(fileName), program.getClassifiableNames(), span); } else { - return classifier.vscode.getSemanticClassifications(program, cancellationToken, getValidSourceFile(fileName), span); + return classifier.modern.getSemanticClassifications(program, cancellationToken, getValidSourceFile(fileName), span); } } @@ -1825,7 +1825,7 @@ namespace ts { return ts.getEncodedSemanticClassifications(program.getTypeChecker(), cancellationToken, getValidSourceFile(fileName), program.getClassifiableNames(), span); } else { - return classifier.vscode.getEncodedSemanticClassifications(program, cancellationToken, getValidSourceFile(fileName), span); + return classifier.modern.getEncodedSemanticClassifications(program, cancellationToken, getValidSourceFile(fileName), span); } } diff --git a/src/services/tsconfig.json b/src/services/tsconfig.json index fb62e2a953e81..8e660d9f2854e 100644 --- a/src/services/tsconfig.json +++ b/src/services/tsconfig.json @@ -12,7 +12,7 @@ "types.ts", "utilities.ts", "classifier.ts", - "classifierVscode.ts", + "classifier2020.ts", "stringCompletions.ts", "completions.ts", "documentHighlights.ts", diff --git a/src/services/types.ts b/src/services/types.ts index 3fbaa2ea0d1ad..401b0ac202830 100644 --- a/src/services/types.ts +++ b/src/services/types.ts @@ -313,6 +313,11 @@ namespace ts { export type WithMetadata = T & { metadata?: unknown; }; + export const enum SemanticClassificationFormat { + Original = "original", + TwentyTwenty = "2020" + } + // // Public services of a language service instance associated // with a language service host instance