-
Notifications
You must be signed in to change notification settings - Fork 449
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RFC: Code actions #1494
Comments
This is not accurate. Code actions are not usually not related to a diagnostic. There's a separate request to fetch code actions.
The infoview already has a function to insert text in the editor. We can and should probably upgrade that to
I think this is a good starting point, and will immediately address existing uses like I still think we need lazily evaluated actions though (later on). Actions like "expand macro" or "add type to let" apply to a lot of code, are too expensive to compute eagerly, and are not produced by the elaborator itself. |
With respect to existing suggestions like Expensive suggestions may be implemented as a 'suggestion of suggestions', e.g., whenever you run a |
I would expect |
It would be useful if asynchronous processing is possible, say via the |
By the way, I just took a quick look at how one of the better language servers implements code transformations: synthesis seems to be string-based https://github.com/rust-lang/rust-analyzer/pull/13005/files. Not sure if there is a chance of lost comments from the transformation. |
Typescript does AST modification: |
Ah, this is the kind of hacky adjustment I would like to avoid by reformatting the whole declaration instead of just the synthesized text: https://github.com/microsoft/TypeScript/blob/db9e0079/src/services/textChanges.ts#L1048-L1049 |
Hi I've collected some thoughts on how to proceed with making a good code completions / actions interface for Lean:
Scope
This RFC intends to cover an API for the protocol between Lean and an editor (initially vscode-lean4) for handling code actions. By code action, I mean the process of Lean presenting suggested semantic code changes to the user via the editor or infoview interface. Examples are (source):
_
holes with{! ... !}
-style holes as described by @david-christiansen here.conv at
or suggesting potential rewrite rules for a particular position.squeeze_simp [...]
.library_search
.by show_term { exact ... }
.by library_search
.Out of scope: code formatting, snippets.
Existing work and discussion
CodeActionProvider
in VSCode extension APISummary of existing discussion
{! !}
holes at least in terms of notation and calls for a retrospective. Leo says this is because it was underdevelopedmatch
. @gebner is less keen.Design proposal
Available mechanisms for implemention of code actions
I think there are cases where you want to use all of the above. I think the code actions give the best solution to the hinting/replacing style tactics such as
squeeze_simp
. The right way to implement these I think is to get the tactic to emit a code action diagnostic that is stored on the infotree. A similar approach can be used when holes are elaborated. In addition to the editor-specific code actions menu, these actions could also be presented in the infoview to make them more promenant.The difference between completions and code actions seems to be that code actions are present as solutions to diagnostics ('squigglies'), whereas completions appear as you type new code. These completions can make arbitrary text edits, so we can do things like get
match x with
to suggest a completion where it autofills all of the cases. I think the rule should be that if you are inserting a new command such as while typing a term or a tactic script, it should give completions, otherwise if it is replacing it should use code actions.Modifying the document.
Currently, tactics can also put a user-widget on the infotree. User-widgets are able to send a command to the editor requesting a text edit, but it is currently clunky and isn't syntax aware.
I think that the best approach here is for Lean to provide a function
diff : Syntax → Syntax → TextEdit
or something similar, where the first argument is the existing syntax (stored on the infotree) and the second argument is the new syntax, theTextEdit
object is then sent to the client editor. This is better than the Lean server editing the file directly because the resulting edit will not appear in the user's undo stack, and there may be some complications with buffers getting out of sync with the file on disk.In the case of code actions and code completions, I propose that the
TextEdit
is computed at elaboration time, rather than asynchronously. This is acceptable because code actions that might take a long time to compute (likesqueeze_simp
) will be explicitly invoked by the user.By storing these completions on the infotree at elaboration time, we don't have to decide here on an API for working with holes or deciding exactly which completions should be supported for a different PR. If we want any custom UI for working with holes, they can use the user-widget system.
Changes proposed:
InfoTree
object calledCodeActionInfo
. Interactive tactics such assqueeze_simp
will put one of these on the infotree.textDocument/codeAction
LSP request.CompletionInfo
for sendingTextEdit
objects.diff : Syntax → Syntax → TextEdit
function to generate LSP text edits from a syntax change.TextEdit
, this can then be used by the infoview ( calls from contextual suggestions and user-widgets) to control the editor.The text was updated successfully, but these errors were encountered: