Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/harness/fourslash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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) {
Expand All @@ -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}`);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/services/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 3 additions & 1 deletion tests/cases/fourslash/fourslash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down