Skip to content

Commit 415b30f

Browse files
authored
Merge pull request #4 from orta/semantic_2_2
WIP - don't provide a breaking change
2 parents 473f651 + 219c64a commit 415b30f

File tree

4 files changed

+16
-8
lines changed

4 files changed

+16
-8
lines changed

src/harness/fourslashImpl.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2490,7 +2490,7 @@ namespace FourSlash {
24902490
return [tokenTypes[typeIdx], ...tokenModifiers.filter((_, i) => modSet & 1 << i)].join(".");
24912491
}
24922492

2493-
private verifyClassifications(expected: { classificationType: string | number, text?: string; textSpan?: TextSpan }[], actual: ts.ClassifiedSpan[], sourceFileText: string) {
2493+
private verifyClassifications(expected: { classificationType: string | number, text?: string; textSpan?: TextSpan }[], actual: (ts.ClassifiedSpan | ts.ClassifiedSpan2020)[] , sourceFileText: string) {
24942494
if (actual.length !== expected.length) {
24952495
this.raiseError("verifyClassifications failed - expected total classifications to be " + expected.length +
24962496
", but was " + actual.length +
@@ -2579,7 +2579,6 @@ namespace FourSlash {
25792579
public verifySemanticClassifications(format: ts.SemanticClassificationFormat, expected: { classificationType: string | number; text?: string }[]) {
25802580
const actual = this.languageService.getSemanticClassifications(this.activeFile.fileName,
25812581
ts.createTextSpan(0, this.activeFile.content.length), format);
2582-
25832582
this.verifyClassifications(expected, actual, this.activeFile.content);
25842583
}
25852584

src/services/classifier2020.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ namespace ts.classifier.v2020 {
1818
}
1919

2020
/** This is mainly used internally for testing */
21-
export function getSemanticClassifications(program: Program, cancellationToken: CancellationToken, sourceFile: SourceFile, span: TextSpan): ClassifiedSpan[] {
21+
export function getSemanticClassifications(program: Program, cancellationToken: CancellationToken, sourceFile: SourceFile, span: TextSpan): ClassifiedSpan2020[] {
2222
const classifications = getEncodedSemanticClassifications(program, cancellationToken, sourceFile, span);
2323

2424
Debug.assert(classifications.spans.length % 3 === 0);
2525
const dense = classifications.spans;
26-
const result: ClassifiedSpan[] = [];
26+
const result: ClassifiedSpan2020[] = [];
2727
for (let i = 0; i < dense.length; i += 3) {
2828
result.push({
2929
textSpan: createTextSpan(dense[i], dense[i + 1]),

src/services/services.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1797,7 +1797,8 @@ namespace ts {
17971797
return kind === ScriptKind.TS || kind === ScriptKind.TSX;
17981798
}
17991799

1800-
function getSemanticClassifications(fileName: string, span: TextSpan, format?: SemanticClassificationFormat): ClassifiedSpan[] {
1800+
function getSemanticClassifications(fileName: string, span: TextSpan): ClassifiedSpan[];
1801+
function getSemanticClassifications(fileName: string, span: TextSpan, format?: SemanticClassificationFormat): ClassifiedSpan[] | ClassifiedSpan2020[] {
18011802
if (!isTsOrTsxFile(fileName)) {
18021803
// do not run semantic classification on non-ts-or-tsx files
18031804
return [];

src/services/types.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -380,10 +380,13 @@ namespace ts {
380380
getCompilerOptionsDiagnostics(): Diagnostic[];
381381

382382
/** @deprecated Use getEncodedSyntacticClassifications instead. */
383-
getSyntacticClassifications(fileName: string, span: TextSpan, format?: SemanticClassificationFormat): ClassifiedSpan[];
383+
getSyntacticClassifications(fileName: string, span: TextSpan): ClassifiedSpan[];
384+
getSyntacticClassifications(fileName: string, span: TextSpan, format: SemanticClassificationFormat): ClassifiedSpan[] | ClassifiedSpan2020[];
384385

385386
/** @deprecated Use getEncodedSemanticClassifications instead. */
386-
getSemanticClassifications(fileName: string, span: TextSpan, format?: SemanticClassificationFormat): ClassifiedSpan[];
387+
getSemanticClassifications(fileName: string, span: TextSpan): ClassifiedSpan[];
388+
getSemanticClassifications(fileName: string, span: TextSpan, format: SemanticClassificationFormat): ClassifiedSpan[] | ClassifiedSpan2020[];
389+
387390
/** Encoded as triples of [start, length, ClassificationType]. */
388391
getEncodedSyntacticClassifications(fileName: string, span: TextSpan): Classifications;
389392

@@ -603,7 +606,12 @@ namespace ts {
603606

604607
export interface ClassifiedSpan {
605608
textSpan: TextSpan;
606-
classificationType: ClassificationTypeNames | number;
609+
classificationType: ClassificationTypeNames;
610+
}
611+
612+
export interface ClassifiedSpan2020 {
613+
textSpan: TextSpan;
614+
classificationType: number;
607615
}
608616

609617
/**

0 commit comments

Comments
 (0)