Zulip Chat Archive
Stream: general
Topic: VSCode extension for Lean code actions
Mario Carneiro (Aug 24 2023 at 01:57):
Have you considered upstreaming this to vscode-lean4?
Scott Morrison (Aug 24 2023 at 01:58):
auto-import and rename in vscode-lean4 would be awesome
Denis Gorbachev (Aug 24 2023 at 02:55):
Mario Carneiro said:
Have you considered upstreaming this to vscode-lean4?
Yes, I'd love to. Who is the right person to talk with regarding upstreaming?
Notification Bot (Aug 24 2023 at 02:58):
3 messages were moved here from #announce > VSCode extension for Lean code actions by Scott Morrison.
Scott Morrison (Aug 24 2023 at 02:59):
@Wojciech Nawrocki and @Gabriel Ebner have done most of the recent work on the extension.
I think you can just start making PRs. (Preferably separate PRs for separate actions, to ease review.)
Denis Gorbachev (Aug 24 2023 at 05:25):
I'll send a preliminary PR to discuss the merge :ok:
Floris van Doorn (Aug 24 2023 at 16:15):
Some feature requests that I think would be very nice:
- "clean up" code by looking at open namespaces / (scoped) notation and using that to shorten names / use the notation. Example:
Example using mathlib:
import Mathlib.Analysis.SpecialFunctions.Trigonometric.Basic
namespace Real
noncomputable def tau := 2 * Real.pi
/- using the command gives:
noncomputable def tau := 2 * π
-/
end Real
- Look at namespaces / scoped notations that could be opened to shorten parts of the code. Example:
import Mathlib.Analysis.SpecialFunctions.Trigonometric.Basic
noncomputable def tau := 2 * Real.pi
/- using the command gives:
open Real in
noncomputable def tau := 2 * π
-/
- Use variables declared in the file and reuse those variables assuming those variables have the same type / binder type and associated type-classes, potentially by renaming the variable. Example:
variable {α β : Type _} [Add β]
def foo {γ : Type _} [Add γ] (x : γ) : γ := x + x
/- using the command gives:
def foo (x : β) : β := x + x
-/
(note: this can get trickier if you use type-classes that have more than 1 argument, like docs#Module)
I would love to use a "move definition" command that uses all of the above features!
Filippo A. E. Nuccio (Aug 24 2023 at 16:44):
I very much agree with the first and the third, while the second might be a bit trickier, because sometimes one really needs only one declaration and it is not worth it opening the namespace to avoid ambiguity.
Denis Gorbachev (Aug 25 2023 at 03:42):
@Floris van Doorn @Filippo A. E. Nuccio Thank you for suggestions - I've added new issues to the repo
Scott Morrison (Aug 25 2023 at 05:23):
We should not merge typescript code that is parsing Lean source to the vscode extension. This won't be maintainable; parsing needs to be done Lean natively.
Julian Berman (Aug 25 2023 at 08:02):
Is the plan really to merge new code actions to the VSCode extension? Rather than Std or somewhere else?
Denis Gorbachev (Aug 25 2023 at 08:04):
New command released: "Set argument style"
Before:
(α : Type u)
After:
{α : Type u}
Notes:
- The command supports four argument styles: explicit, implicit strong, implicit weak, typeclass (
()
,{}
,⦃⦄
,[]
).
Extension links:
Denis Gorbachev (Aug 25 2023 at 08:09):
Agreed, it's better to execute the code actions on the server, in the LSP file worker.
Sebastian Ullrich (Aug 25 2023 at 08:09):
Julian Berman said:
Is the plan really to merge new code actions to the VSCode extension? Rather than Std or somewhere else?
If they are implemented in Lean, they should of course go into a Lean package, yes
Eric Wieser (Aug 25 2023 at 08:10):
Denis Gorbachev said:
New command released: "Set argument style"
does this also change all the callers?
Mario Carneiro (Aug 25 2023 at 08:11):
These don't actually seem to be code actions though in the technical sense, these are extension commands
Denis Gorbachev (Aug 25 2023 at 08:12):
Julian Berman said:
Is the plan really to merge new code actions to the VSCode extension? Rather than Std or somewhere else?
Ideally, the extension should provide a frontend for the code actions, which should be executed on the server.
Whether to merge to core extension or not - see https://github.com/leanprover/vscode-lean4/issues/316
Denis Gorbachev (Aug 25 2023 at 08:15):
Eric Wieser said:
Denis Gorbachev said:
New command released: "Set argument style"
does this also change all the callers?
No, sorry - it simply changes the argument in the definition.
I agree this is suboptimal.
Who's interested in forming a Code Actions Working Group? Together, we could implement the proper code actions that handle all edge cases & work natively within the LSP server.
Mario Carneiro (Aug 25 2023 at 08:15):
At least the rename action seems to be relatively easy to implement in the server
Mario Carneiro (Aug 25 2023 at 08:15):
TBH it is unclear why it doesn't already exist
Denis Gorbachev (Aug 25 2023 at 08:16):
Mario Carneiro said:
At least the rename action seems to be relatively easy to implement in the server
Yeah, that would be great!
Mario Carneiro (Aug 25 2023 at 08:16):
I think the procedure would be to make a PR to the appropriate repository (lean core, std, or vscode-lean4), they each have their own contribution process
Mario Carneiro (Aug 25 2023 at 08:17):
a rename action would go in core
Mario Carneiro (Aug 25 2023 at 08:17):
auto-import too
Mario Carneiro (Aug 25 2023 at 08:18):
most actual code actions would go in std
Denis Gorbachev (Aug 25 2023 at 08:18):
P.S. The "final boss" is the "Move definition" command. There are lots of nuances related to namespace
and open
that should be handled when moving the definition from one file to another. Discussed here: https://github.com/DenisGorbachev/vscode-lean4-code-actions/issues/10
Mario Carneiro (Aug 25 2023 at 08:18):
and more involved text manipulation or things that need dropdowns / additional info would be in the extension
Denis Gorbachev (Aug 25 2023 at 08:21):
Agree
Eric Wieser (Aug 25 2023 at 08:27):
Denis Gorbachev said:
P.S. The "final boss" is the "Move definition" command.
This doesn't seem very valuable to me. Code actions are most useful when tens of files need to be changed in sync. Cut-and-pasting a single definition doesn't really meet that threshold.
Mario Carneiro (Aug 25 2023 at 08:28):
if it can actually solve those "final boss" issues it could be valuable
Mario Carneiro (Aug 25 2023 at 08:28):
but I'm not sure it's worth the effort
Damiano Testa (Aug 25 2023 at 08:58):
Eric Wieser said:
Denis Gorbachev said:
New command released: "Set argument style"
does this also change all the callers?
With respect to this, I've been using Bracketeer that has a key combination cycling through (), [], {}
only. Even so, I find it incredibly useful, since I very rarely use strict implicits. So, if this code action improved on this, I would be very happy!
Denis Gorbachev (Aug 25 2023 at 09:07):
Eric Wieser said:
Denis Gorbachev said:
P.S. The "final boss" is the "Move definition" command.
This doesn't seem very valuable to me. Code actions are most useful when tens of files need to be changed in sync. Cut-and-pasting a single definition doesn't really meet that threshold.
What about moving the definition that is used in tens of other files? (we'll need to update the imports)
Denis Gorbachev (Aug 25 2023 at 09:10):
Damiano Testa said:
Eric Wieser said:
Denis Gorbachev said:
New command released: "Set argument style"
does this also change all the callers?
With respect to this, I've been using Bracketeer that has a key combination cycling through
(), [], {}
only. Even so, I find it incredibly useful, since I very rarely use strict implicits. So, if this code action improved on this, I would be very happy!
Ah snap, Bracketeer looks like a better solution! (it also has a "Remove brackets" action)
But you're right - it doesn't support weak implicit args.
Denis Gorbachev (Aug 25 2023 at 09:10):
(deleted)
Mario Carneiro (Aug 25 2023 at 12:12):
Mario Carneiro said:
At least the rename action seems to be relatively easy to implement in the server
TBH it is unclear why it doesn't already exist
I put up a rename implementation at lean4#2462
Denis Gorbachev (Aug 26 2023 at 01:42):
Thanks a lot Mario! I'll switch to your implementation as soon as it's merged
Floris van Doorn (Aug 26 2023 at 10:20):
Eric Wieser said:
This doesn't seem very valuable to me. Code actions are most useful when tens of files need to be changed in sync. Cut-and-pasting a single definition doesn't really meet that threshold.
Moving a lemma from a new file to an existing mathlib file is a huge pain IMO, since the lemma usually breaks after just copy-and-pasting: the target location has different namespaces open, different declared variable names, etc. In Lean 3 it was a big annoyance. Also, if you paste results to multiple different files, then in Lean 3 you'd have to recompile a large part of the library to see if there are any errors after copy-pasting, so I usually just sent it off to Github CI and hoped for the best.
Having a "copy-paste" function that doesn't create errors 99% of the time would be very nice.
Denis Gorbachev (Aug 28 2023 at 07:52):
New action: Update imports on file rename
Example:
If you rename Some/File.lean
to Another/Name.lean
, it will update import Some.File
to import Another.Name
in every file in the workspace.
Extension links:
Last updated: Dec 20 2023 at 11:08 UTC