Skip to content

Commit

Permalink
Reafactor after comments
Browse files Browse the repository at this point in the history
  • Loading branch information
orta committed Jun 23, 2020
1 parent 13d7b9b commit 87bbcdc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/harness/fourslashImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2564,7 +2564,7 @@ namespace FourSlash {
const identifier = this.classificationToIdentifier(a.classificationType as number);
const text = this.activeFile.content.slice(a.textSpan.start, a.textSpan.start + a.textSpan.length);
replacement.push(` c2.semanticToken("${identifier}", "${text}"), `);
});
};
replacement.push(");");

throw new Error("You need to change the source code of fourslash test to use replaceWithSemanticClassifications");
Expand Down
15 changes: 7 additions & 8 deletions src/services/classifier2020.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@ namespace ts.classifier.modern {

/** @internal */
export const enum TokenEncodingConsts {

typeOffset = 8,
modifierMask = (1 << typeOffset) - 1
}

/** @internal */
export const enum TokenType {
class, enum, interface, namespace, typeParameter, type, parameter, variable, enumMember, property, function, member, _
class, enum, interface, namespace, typeParameter, type, parameter, variable, enumMember, property, function, member
}

/** @internal */
export const enum TokenModifier {
declaration, static, async, readonly, defaultLibrary, local, _
declaration, static, async, readonly, defaultLibrary, local
}

/** This is mainly used internally for testing */
Expand All @@ -26,10 +25,10 @@ namespace ts.classifier.modern {
const dense = classifications.spans;
const result: ClassifiedSpan[] = [];
for (let i = 0; i < dense.length; i += 3) {
result.push({
textSpan: createTextSpan(dense[i], dense[i + 1]),
classificationType: dense[i + 2]
});
result.push({
textSpan: createTextSpan(dense[i], dense[i + 1]),
classificationType: dense[i + 2]
});
}

return result;
Expand All @@ -46,7 +45,7 @@ namespace ts.classifier.modern {
const resultTokens: number[] = [];

const collector = (node: Node, typeIdx: number, modifierSet: number) => {
resultTokens.push(node.getStart(), node.getWidth(), ((typeIdx + 1) << TokenEncodingConsts.typeOffset) + modifierSet);
resultTokens.push(node.getStart(sourceFile), node.getWidth(sourceFile), ((typeIdx + 1) << TokenEncodingConsts.typeOffset) + modifierSet);
};

if (program && sourceFile) {
Expand Down
6 changes: 3 additions & 3 deletions src/services/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1802,11 +1802,11 @@ namespace ts {
synchronizeHostData();

const responseFormat = format || SemanticClassificationFormat.Original;
if (responseFormat === SemanticClassificationFormat.Original) {
return ts.getSemanticClassifications(program.getTypeChecker(), cancellationToken, getValidSourceFile(fileName), program.getClassifiableNames(), span);
if (responseFormat === SemanticClassificationFormat.TwentyTwenty) {
return classifier.modern.getSemanticClassifications(program, cancellationToken, getValidSourceFile(fileName), span);
}
else {
return classifier.modern.getSemanticClassifications(program, cancellationToken, getValidSourceFile(fileName), span);
return ts.getSemanticClassifications(program.getTypeChecker(), cancellationToken, getValidSourceFile(fileName), program.getClassifiableNames(), span);
}
}

Expand Down

0 comments on commit 87bbcdc

Please sign in to comment.