mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-17 11:24:29 -05:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user