Zulip Chat Archive

Stream: std4

Topic: std4#231, and code actions


Scott Morrison (Aug 26 2023 at 05:45):

Some questions about code actions.

  • Is there a mechanism (whether generic or Lean specific) to run all code actions in a file? Or all code actions of a specified kind??
  • What if I wanted to run all code actions across many files (ideally able to do this from the command line / a script)?

Scott Morrison (Aug 26 2023 at 05:46):

(I'm thinking here that there are some things which are useful both as user prompts and library-wide edit tools, and hoping that one can just implement these as code actions.)

Mario Carneiro (Aug 26 2023 at 06:40):

No, not really. We would need another interface for that, a framework for plugging in to a "do all the things" edit API

Mario Carneiro (Aug 26 2023 at 06:41):

What would the front end of such an API be? Something like cargo --fix, or a custom command in vscode?

Mario Carneiro (Aug 26 2023 at 06:55):

The way I would describe cargo --fix in lean terms is that compilation can produce diagnostics (warnings and errors) that are change requests tagged as "machine-applicable", and then --fix collects all of these by running lean in a special mode where it outputs these diagnostics in JSON format and then follows up with a global file edit which applies all machine-applicable diagnostic change suggestions.

Scott Morrison (Aug 26 2023 at 07:44):

Oh, I was imagining instead some tool that collected all the change requests via the LSP (hence wondering if there might be something generic for all langauges).

Scott Morrison (Aug 26 2023 at 07:48):

But a quick google finds nothing, which is a pity.

Mario Carneiro (Aug 26 2023 at 08:09):

The LSP interface (which is reflected in the lean interface) is that the client asks about what code actions exist at a given location or selection, the server responds with a list of suggestions, then the client picks one and the server sends a text edit

Mario Carneiro (Aug 26 2023 at 08:10):

so if you wanted to use the LSP interface directly you would (1) have to ask at each character and (2) identify and filter out duplicate suggestions, which would be very inefficient

Mario Carneiro (Aug 26 2023 at 08:12):

It is probably possible to come up with a combined interface which is usable for both workflows though, so that the code actions can share code with the autofix


Last updated: Dec 20 2023 at 11:08 UTC