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
3 changes: 1 addition & 2 deletions src/services/findAllReferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ namespace ts.FindAllReferences {
}
}

export function findReferencedEntries(program: Program, cancellationToken: CancellationToken, sourceFiles: ReadonlyArray<SourceFile>, sourceFile: SourceFile, position: number, options?: Options): ReferenceEntry[] | undefined {
const node = getTouchingPropertyName(sourceFile, position);
export function findReferencedEntries(program: Program, cancellationToken: CancellationToken, sourceFiles: ReadonlyArray<SourceFile>, node: Node, position: number, options: Options | undefined): ReferenceEntry[] | undefined {
return map(flattenEntries(Core.getReferencedSymbolsForNode(position, node, program, sourceFiles, cancellationToken, options)), toReferenceEntry);
}

Expand Down
20 changes: 15 additions & 5 deletions src/services/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1697,23 +1697,33 @@ namespace ts {
}

function findRenameLocations(fileName: string, position: number, findInStrings: boolean, findInComments: boolean): RenameLocation[] | undefined {
const refs = getReferences(fileName, position, { findInStrings, findInComments, isForRename: true });
return refs && refs.map(({ fileName, textSpan }): RenameLocation => ({ fileName, textSpan }));
synchronizeHostData();
const sourceFile = getValidSourceFile(fileName);
const node = getTouchingPropertyName(sourceFile, position);
if (isIdentifier(node) && isJsxOpeningElement(node.parent) || isJsxClosingElement(node.parent)) {
const { openingElement, closingElement } = node.parent.parent;
return [openingElement, closingElement].map((node): RenameLocation => ({ fileName: sourceFile.fileName, textSpan: createTextSpanFromNode(node.tagName, sourceFile) }));
}
else {
const refs = getReferences(node, position, { findInStrings, findInComments, isForRename: true });
return refs && refs.map(({ fileName, textSpan }): RenameLocation => ({ fileName, textSpan }));
}
}

function getReferencesAtPosition(fileName: string, position: number): ReferenceEntry[] | undefined {
return getReferences(fileName, position)!;
synchronizeHostData();
return getReferences(getTouchingPropertyName(getValidSourceFile(fileName), position), position);
}

function getReferences(fileName: string, position: number, options?: FindAllReferences.Options): ReferenceEntry[] | undefined {
function getReferences(node: Node, position: number, options?: FindAllReferences.Options): ReferenceEntry[] | undefined {
synchronizeHostData();

// Exclude default library when renaming as commonly user don't want to change that file.
const sourceFiles = options && options.isForRename
? program.getSourceFiles().filter(sourceFile => !program.isSourceFileDefaultLibrary(sourceFile))
: program.getSourceFiles();

return FindAllReferences.findReferencedEntries(program, cancellationToken, sourceFiles, getValidSourceFile(fileName), position, options);
return FindAllReferences.findReferencedEntries(program, cancellationToken, sourceFiles, node, position, options);
}

function findReferences(fileName: string, position: number): ReferencedSymbol[] | undefined {
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/api/tsserverlibrary.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11112,7 +11112,7 @@ declare namespace ts.FindAllReferences {
}
function findReferencedSymbols(program: Program, cancellationToken: CancellationToken, sourceFiles: ReadonlyArray<SourceFile>, sourceFile: SourceFile, position: number): ReferencedSymbol[] | undefined;
function getImplementationsAtPosition(program: Program, cancellationToken: CancellationToken, sourceFiles: ReadonlyArray<SourceFile>, sourceFile: SourceFile, position: number): ImplementationLocation[] | undefined;
function findReferencedEntries(program: Program, cancellationToken: CancellationToken, sourceFiles: ReadonlyArray<SourceFile>, sourceFile: SourceFile, position: number, options?: Options): ReferenceEntry[] | undefined;
function findReferencedEntries(program: Program, cancellationToken: CancellationToken, sourceFiles: ReadonlyArray<SourceFile>, node: Node, position: number, options: Options | undefined): ReferenceEntry[] | undefined;
function getReferenceEntriesForNode(position: number, node: Node, program: Program, sourceFiles: ReadonlyArray<SourceFile>, cancellationToken: CancellationToken, options?: Options, sourceFilesSet?: ReadonlyMap<true>): Entry[] | undefined;
function toHighlightSpan(entry: Entry): {
fileName: string;
Expand Down
24 changes: 10 additions & 14 deletions tests/cases/fourslash/tsxRename4.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
/// <reference path='fourslash.ts' />

//@Filename: file.tsx
//// declare module JSX {
//// interface Element { }
//// interface IntrinsicElements {
//// }
//// interface ElementAttributesProperty { props }
//// }
//// class [|MyClass|] {
//// props: {
//// name?: string;
//// size?: number;
//// }
////declare module JSX {
//// interface Element {}
//// interface IntrinsicElements {}
////}
////class [|MyClass|] {}
////
////
//// var x = <[|MyClass|] name='hello'></[|MyClass|]>;
////<[|MyClass|]></[|MyClass|]>;
////<[|MyClass|]/>;

verify.rangesAreRenameLocations();
const [r0, r1, r2, r3] = test.ranges();
verify.renameLocations([r0, r3], [r0, r1, r2, r3]);
verify.renameLocations([r1, r2], [r1, r2]);