Zulip Chat Archive

Stream: lean4

Topic: Renaming decls using LSP


Johan Commelin (Nov 15 2023 at 04:54):

If I want to rename my lemma xyzzy_foo to xyzzy.bar in all of mathlib, it would be great if this can be done automatically. And maybe I have a list of decls that should be renamed, and I want to do this in batch mode.
How close are we to having such code transformation tools? @Mario Carneiro I think you've mentioned some thoughts on this several times... (-;

Mario Carneiro (Nov 15 2023 at 04:55):

that's lean4#2462

Johan Commelin (Nov 15 2023 at 05:00):

Thanks for the pointer! Did you make any progress on issues 1 and 2 in the review comment?

Damiano Testa (Nov 15 2023 at 06:40):

Johan, while waiting for the "correct" solution would you be interested in a command-line patch?

I think that the ilean files contain information of where each declaration is located in the code: I used that to surgically replace every theorem to lemma. I could look into finding all declaration names as well, if you wanted.

Johan Commelin (Nov 15 2023 at 07:30):

Hah, if that works, I would certainly be happy to have it!
I think it's great if we can have renaming PRs where the diff is generated by invoking such a command. Makes it much easier to review the PRs if you know that's how they're created.

Johan Commelin (Nov 15 2023 at 07:31):

And it makes it easier to split PRs into the manual and automatic parts.

Damiano Testa (Nov 15 2023 at 07:38):

Ok, I'll look into this: it should be easy, since it seems a slight adaptation of what I already had, but I will have to figure out how to deal with name-spacing.

Damiano Testa (Nov 15 2023 at 07:39):

(Also, this will certainly not take care of docs/comments: those names would have to be inspected by a different means than what I have in mind.)

Notification Bot (Nov 15 2023 at 07:39):

Damiano Testa has marked this topic as resolved.

Notification Bot (Nov 15 2023 at 07:39):

Damiano Testa has marked this topic as unresolved.

Damiano Testa (Nov 15 2023 at 07:39):

Sorry about the misclick! :upside_down:

Johan Commelin (Nov 15 2023 at 07:39):

Yeah docs/comments is a good point.

Damiano Testa (Nov 15 2023 at 22:11):

Johan, do you have a concrete case where you would like this replacement to happen?

I have a very preliminary version and it would be good to test it and fix some gross mistakes that it contains!

Right now, I already know that it will do the wrong thing if the declaration is used in dot-notation and if it is called with @.

Eric Wieser (Nov 15 2023 at 22:53):

I'm hoping that @David Thrane Christiansen's documentation plans will leave us with comments that are recognized by the LSP

Damiano Testa (Nov 15 2023 at 22:55):

I am testing the replacement Real.tan to Real.Tan.

Except for the namespacing issues, the only other problem in this case is that I use sed to capture patterns and there are lines where there are more than 9 captures... :face_palm:

Jireh Loreaux (Nov 15 2023 at 23:00):

Related: I just opened #8433 to figure out which declarations were renamed. It's very pedestrian; it only lists all declarations in changed files and computes the diff.

Johan Commelin (Nov 16 2023 at 07:05):

@Damiano Testa My question was inspired by #8406. A tool like this might make it easier to separate the "renaming" and the "golfing" parts of such PRs.

Damiano Testa (Nov 16 2023 at 07:31):

Ok, I'll test the change

isAlgebraic_algebraMap -> IsAlgebraic.algebraMap

and see how it performs.

Damiano Testa (Nov 16 2023 at 08:21):

You can see the progress here: #8437.

I may regret this, but I have made more than one rename while testing the tool.

Damiano Testa (Nov 16 2023 at 09:07):

This was easy and successful. In hindsight, the only change that had to be manually made for this PR is protecting one of the renamed theorems.

Damiano Testa (Nov 16 2023 at 09:08):

I tried to keep the git history clean and the changes only affect 15 lines, in case you want to take a look at how the renaming of the declaration works.

Andrew Yang (Dec 07 2023 at 16:59):

Is there a way to use this script?

Damiano Testa (Dec 07 2023 at 19:32):

I thought that Mario had a version of the renaming tool written in Lean that was merged soon after I used the bash-one. Otherwise, I can share a version of my string-based one, but likely tomorrow, since I'm no longer at my computer for today.

Marc Huisinga (Dec 07 2023 at 19:58):

You should be able to right click on an identifier and select "Rename symbol" now.


Last updated: Dec 20 2023 at 11:08 UTC