Skip to content

Commit

Permalink
Handle feedback from microsoft#39119
Browse files Browse the repository at this point in the history
  • Loading branch information
orta committed Jun 29, 2020
1 parent 16a7b23 commit 5841110
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 38 deletions.
5 changes: 0 additions & 5 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
56 changes: 27 additions & 29 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.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;
Expand Down Expand Up @@ -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);
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
namespace ts.classifier.vscode {
/** @internal */
namespace ts.classifier.modern {

/** @internal */
export 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 @@ -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);
}
}

Expand All @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/services/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"types.ts",
"utilities.ts",
"classifier.ts",
"classifierVscode.ts",
"classifier2020.ts",
"stringCompletions.ts",
"completions.ts",
"documentHighlights.ts",
Expand Down
5 changes: 5 additions & 0 deletions src/services/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,11 @@ namespace ts {

export type WithMetadata<T> = 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
Expand Down

0 comments on commit 5841110

Please sign in to comment.