Only report isDefinition when FAR is triggered on a definition (#48566)

* Don't report isDefinition unless the starting node is a declaration

* Drop isDefinition everywhere it isn't specifically needed

* Fix tsserver tests

* Update shim comment

* Update baselines

* Add tests for isDefinition

* Update doc comment

* Clear isDefinition from all references if the first one lacks it
This commit is contained in:
Andrew Casey
2022-04-05 17:04:18 -07:00
committed by GitHub
parent f7c457d207
commit 76e74370ab
271 changed files with 4136 additions and 4678 deletions

View File

@@ -1158,9 +1158,12 @@ namespace ts.server.protocol {
isWriteAccess: boolean;
/**
* True if reference is a definition, false otherwise.
* Present only if the search was triggered from a declaration.
* True indicates that the references refers to the same symbol
* (i.e. has the same meaning) as the declaration that began the
* search.
*/
isDefinition: boolean;
isDefinition?: boolean;
}
/**

View File

@@ -354,6 +354,7 @@ namespace ts.server {
logger.info(`Finding references to ${location.fileName} position ${location.pos} in project ${project.getProjectName()}`);
const projectOutputs = project.getLanguageService().findReferences(location.fileName, location.pos);
if (projectOutputs) {
const clearIsDefinition = projectOutputs[0].references[0].isDefinition === undefined;
for (const referencedSymbol of projectOutputs) {
const mappedDefinitionFile = getMappedLocation(project, documentSpanLocation(referencedSymbol.definition));
const definition: ReferencedSymbolDefinitionInfo = mappedDefinitionFile === undefined ?
@@ -374,6 +375,9 @@ namespace ts.server {
for (const ref of referencedSymbol.references) {
// If it's in a mapped file, that is added to the todo list by `getMappedLocation`.
if (!contains(symbolToAddTo.references, ref, documentSpansEqual) && !getMappedLocation(project, documentSpanLocation(ref))) {
if (clearIsDefinition) {
delete ref.isDefinition;
}
symbolToAddTo.references.push(ref);
}
}
@@ -3260,7 +3264,7 @@ namespace ts.server {
return text;
}
function referenceEntryToReferencesResponseItem(projectService: ProjectService, { fileName, textSpan, contextSpan, isWriteAccess, isDefinition }: ReferenceEntry): protocol.ReferencesResponseItem {
function referenceEntryToReferencesResponseItem(projectService: ProjectService, { fileName, textSpan, contextSpan, isWriteAccess, isDefinition }: ReferencedSymbolEntry): protocol.ReferencesResponseItem {
const scriptInfo = Debug.checkDefined(projectService.getScriptInfo(fileName));
const span = toProtocolTextSpanWithContext(textSpan, contextSpan, scriptInfo);
const lineSpan = scriptInfo.lineToTextSpan(span.start.line - 1);