refactor(language-service): convert references_spec to new testing package (#40966)

refactor(language-service): convert references_spec to new testing package

PR Close #40966
This commit is contained in:
Andrew Scott 2021-02-08 15:23:41 -08:00 committed by atscott
parent 000ec6be3c
commit dcee784b4f
5 changed files with 523 additions and 436 deletions

View File

@ -392,6 +392,11 @@ export class ReferencesAndRenameBuilder {
...shimDocumentSpan,
fileName: templateUrl,
textSpan: toTextSpan(span),
// Specifically clear other text span values because we do not have enough knowledge to
// convert these to spans in the template.
contextSpan: undefined,
originalContextSpan: undefined,
originalTextSpan: undefined,
};
}
}

File diff suppressed because it is too large Load Diff

View File

@ -88,4 +88,16 @@ export class OpenBuffer {
getTypeDefinitionAtPosition() {
return this.ngLS.getTypeDefinitionAtPosition(this.scriptInfo.fileName, this._cursor);
}
getReferencesAtPosition() {
return this.ngLS.getReferencesAtPosition(this.scriptInfo.fileName, this._cursor);
}
fineRenameLocations() {
return this.ngLS.findRenameLocations(this.scriptInfo.fileName, this._cursor);
}
getRenameInfo() {
return this.ngLS.getRenameInfo(this.scriptInfo.fileName, this._cursor);
}
}

View File

@ -98,9 +98,14 @@ export class Project {
openFile(projectFileName: string): OpenBuffer {
if (!this.buffers.has(projectFileName)) {
const fileName = absoluteFrom(`/${this.name}/${projectFileName}`);
let scriptInfo = this.tsProject.getScriptInfo(fileName);
this.projectService.openClientFile(fileName);
// Mark the project as dirty because the act of opening a file may result in the version
// changing since TypeScript will `switchToScriptVersionCache` when a file is opened.
// Note that this emulates what we have to do in the server/extension as well.
this.tsProject.markAsDirty();
const scriptInfo = this.tsProject.getScriptInfo(fileName);
scriptInfo = this.tsProject.getScriptInfo(fileName);
if (scriptInfo === undefined) {
throw new Error(
`Unable to open ScriptInfo for ${projectFileName} in project ${this.tsConfigPath}`);

View File

@ -45,6 +45,11 @@ export function assertFileNames(refs: Array<{fileName: string}>, expectedFileNam
expect(new Set(actualFileNames)).toEqual(new Set(expectedFileNames));
}
export function assertTextSpans(items: Array<{textSpan: string}>, expectedTextSpans: string[]) {
const actualSpans = items.map(item => item.textSpan);
expect(new Set(actualSpans)).toEqual(new Set(expectedTextSpans));
}
/**
* Returns whether the given `ts.Diagnostic` is of a type only produced by the Angular compiler (as
* opposed to being an upstream TypeScript diagnostic).