Support testing document highlights with "filesToSearch" (#21640)

* Support testing document highlights with "filesToSearch"

* Fix lint
This commit is contained in:
Andy 2018-02-05 14:02:50 -08:00 committed by GitHub
parent d584f4d97b
commit 48c0af5d43
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 13 deletions

View File

@ -2819,7 +2819,7 @@ Actual: ${stringify(fullActual)}`);
}
}
private getDocumentHighlightsAtCurrentPosition(fileNamesToSearch: string[]) {
private getDocumentHighlightsAtCurrentPosition(fileNamesToSearch: ReadonlyArray<string>) {
const filesToSearch = fileNamesToSearch.map(name => ts.combinePaths(this.basePath, name));
return this.languageService.getDocumentHighlights(this.activeFile.fileName, this.currentCaretPosition, filesToSearch);
}
@ -2843,9 +2843,8 @@ Actual: ${stringify(fullActual)}`);
this.rangesByText().forEach(ranges => this.verifyRangesAreDocumentHighlights(ranges));
}
public verifyDocumentHighlightsOf(startRange: Range, ranges: Range[]) {
ts.Debug.assert(ts.contains(ranges, startRange));
const fileNames = unique(ranges, range => range.fileName);
public verifyDocumentHighlightsOf(startRange: Range, ranges: Range[], options: FourSlashInterface.VerifyDocumentHighlightsOptions | undefined) {
const fileNames = options && options.filesToSearch || unique(ranges, range => range.fileName);
this.goToRangeStart(startRange);
this.verifyDocumentHighlights(ranges, fileNames);
}
@ -2868,7 +2867,7 @@ Actual: ${stringify(fullActual)}`);
}
}
private verifyDocumentHighlights(expectedRanges: Range[], fileNames: string[] = [this.activeFile.fileName]) {
private verifyDocumentHighlights(expectedRanges: Range[], fileNames: ReadonlyArray<string> = [this.activeFile.fileName]) {
const documentHighlights = this.getDocumentHighlightsAtCurrentPosition(fileNames) || [];
for (const dh of documentHighlights) {
@ -2880,10 +2879,7 @@ Actual: ${stringify(fullActual)}`);
for (const fileName of fileNames) {
const expectedRangesInFile = expectedRanges.filter(r => r.fileName === fileName);
const highlights = ts.find(documentHighlights, dh => dh.fileName === fileName);
if (!highlights) {
this.raiseError(`verifyDocumentHighlights failed - found no highlights in ${fileName}`);
}
const spansInFile = highlights.highlightSpans.sort((s1, s2) => s1.textSpan.start - s2.textSpan.start);
const spansInFile = highlights ? highlights.highlightSpans.sort((s1, s2) => s1.textSpan.start - s2.textSpan.start) : [];
if (expectedRangesInFile.length !== spansInFile.length) {
this.raiseError(`verifyDocumentHighlights failed - In ${fileName}, expected ${expectedRangesInFile.length} highlights, got ${spansInFile.length}`);
@ -4272,8 +4268,8 @@ namespace FourSlashInterface {
this.state.verifyRangesWithSameTextAreDocumentHighlights();
}
public documentHighlightsOf(startRange: FourSlash.Range, ranges: FourSlash.Range[]) {
this.state.verifyDocumentHighlightsOf(startRange, ranges);
public documentHighlightsOf(startRange: FourSlash.Range, ranges: FourSlash.Range[], options?: VerifyDocumentHighlightsOptions) {
this.state.verifyDocumentHighlightsOf(startRange, ranges, options);
}
public noDocumentHighlights(startRange: FourSlash.Range) {
@ -4622,6 +4618,10 @@ namespace FourSlashInterface {
insertText?: string;
}
export interface VerifyDocumentHighlightsOptions {
filesToSearch?: ReadonlyArray<string>;
}
export interface NewContentOptions {
// Exactly one of these should be defined.
newFileContent?: string;

View File

@ -1582,7 +1582,7 @@ namespace ts {
function getDocumentHighlights(fileName: string, position: number, filesToSearch: string[]): DocumentHighlights[] {
synchronizeHostData();
const sourceFilesToSearch = map(filesToSearch, f => program.getSourceFile(f));
const sourceFilesToSearch = map(filesToSearch, f => Debug.assertDefined(program.getSourceFile(f)));
const sourceFile = getValidSourceFile(fileName);
return DocumentHighlights.getDocumentHighlights(program, cancellationToken, sourceFile, position, sourceFilesToSearch);
}

View File

@ -310,7 +310,9 @@ declare namespace FourSlashInterface {
occurrencesAtPositionCount(expectedCount: number): void;
rangesAreDocumentHighlights(ranges?: Range[]): void;
rangesWithSameTextAreDocumentHighlights(): void;
documentHighlightsOf(startRange: Range, ranges: Range[]): void;
documentHighlightsOf(startRange: Range, ranges: Range[], options?: {
filesToSearch?: ReadonlyArray<string>;
}): void;
completionEntryDetailIs(entryName: string, text: string, documentation?: string, kind?: string, tags?: ts.JSDocTagInfo[]): void;
/**
* This method *requires* a contiguous, complete, and ordered stream of classifications for a file.