This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Rename references to function arguments within the same file
AbandonedPublic

Authored by kbobyrev on Feb 9 2021, 1:53 AM.

Details

Reviewers
hokein
Summary

This is a fix of the problem (rather than a patch - D96247) discussed in
https://github.com/clangd/clangd/issues/685.

Diff Detail

Event Timeline

kbobyrev created this revision.Feb 9 2021, 1:53 AM
kbobyrev requested review of this revision.Feb 9 2021, 1:53 AM
kbobyrev updated this revision to Diff 322321.Feb 9 2021, 2:37 AM

Implement constructors handling.

kbobyrev edited the summary of this revision. (Show Details)Feb 9 2021, 2:38 AM

This likely needs some further thought on conflict detection. Assume we have

void foo(int Argument^); // case 1
void foo(int OhWait); // case 2
void foo(int Argument); // case 3

void foo(int AnotherOne) {} // case 4

What should we do when renaming Argument? Just rename all of them? Only rename in places where the name matches the original one (case 3)? Bail out and report an error? Also, there is no easy way to check all of these cases within our existing conflict detection pipeline: IIUC we'd need to walk the whole AST again for that (like we do in this patch within the rename pipeline).

kbobyrev updated this revision to Diff 322382.Feb 9 2021, 7:08 AM

Rebase on top of D96247, check for conflicts in specialization bodies.

@sammccall this is the argument renaming diff I was talking about during the standup.

Ping! Do you think this is a reasonable idea? I think if we just check whether there aren't any references to the function outside of the main file we should be safe enough to rename args.

Herald added a project: Restricted Project. · View Herald TranscriptAug 6 2021, 12:37 AM

I think this is a great use case for pseudo parser actually (unfortunately requires some multi-file interactions). In theory we can just fetch all the references, pseudo-parse the files, and update all the declarations & definitions to have the same parameter name.

My 2 cents for limiting to single-file cases initially;
It sounds like a better option to make the functionality less surprising, but I think we'll still end up confusing the users, so I am not sure if it is worth.

kbobyrev abandoned this revision.May 19 2022, 5:52 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 19 2022, 5:52 AM