Repository navigation
feat: a rename, a code action or workspace/applyEdit asks to confirm the changes whose change annotation needs confirmation - #2400
Open
lagergren wants to merge 1 commit into
Conversation
…the changes whose change annotation needs confirmation (redhat-developer#2246) A text edit with an annotationId is read as an AnnotatedTextEdit, which LSP4J would read as a TextEdit without it. The changes whose annotation needs confirmation are shown by label in a dialog, each checked: Apply applies the checked labels and the other changes, and Cancel applies nothing. The edit of workspace/will*Files, applied during a VFS event, leaves them out. LSP4IJ announces changeAnnotationSupport (groupsOnLabel) and honorsChangeAnnotations for rename and code actions.
|
Warning Review limit reachedThis review ran on the open-source allowance, not this organization's plan, because the pull request author doesn't have an assigned seat. Waiting won't change this — ask an organization admin to assign them a seat, or add seats in Billing if every seat is already assigned, then retry. Next included review available in 31 minutes. View limit details
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #2400 +/- ##
==========================================
+ Coverage 60.01% 60.06% +0.05%
==========================================
Files 860 863 +3
Lines 37725 37930 +205
Branches 5923 7866 +1943
==========================================
+ Hits 22641 22783 +142
- Misses 11980 12035 +55
- Partials 3104 3112 +8 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2246.
Since LSP 3.16, a workspace edit can annotate its changes (ChangeAnnotation): a text edit (
AnnotatedTextEdit) or a file operation refers to an annotation by itsannotationId, and an annotation withneedsConfirmationasks the client to let the user confirm those changes first. rust-analyzer annotates a change outside the workspace this way, such as a rename that would edit a dependency's sources, but only for a client that announceschangeAnnotationSupport. LSP4IJ didn't, and it dropped the annotation ID of a text edit when it read one, so such changes were applied without asking.What changes
Reading the annotation ID: LSP4J reads the text edits of a
TextDocumentEditasTextEdits, which lose theannotationId. The newAnnotatedTextEditTypeAdapterFactory, among LSP4IJ's Gson adapters, reads an edit with one as anAnnotatedTextEdit, and writes it with it. ASnippetTextEditand a file operation already keep theirs.ChangeAnnotationsfinds the changes whose annotation needs confirmation, groups them by label (groupsOnLabel), and returns the edit without the changes of the labels that the user doesn't check.The dialog,
ChangeAnnotationsDialog, shows:Apply applies the checked labels and every change that doesn't need confirmation. Cancel applies nothing.
Where it's asked:
workspace/applyEdit: the label of the request is the dialog's title. Cancel answersapplied: falsewith a failure reason, and unchecked labels still answerapplied: true, as in VS Code.Edits that need no confirmation go the way they went before, on the same threads.
File operations: the edit of
workspace/willCreateFiles,willRenameFilesorwillDeleteFilesis applied during the VFS event, where the user can't be asked. Its changes that need confirmation are left out, and a warning is logged. VS Code asks there, but IntelliJ gives no point before the file operation where a dialog could open; tell me if you'd rather apply them.Fallback:
ChangeAnnotations.confirmcalled in a write action leaves out the changes to confirm instead of opening a dialog.Capabilities: LSP4IJ now announces
workspace.workspaceEdit.changeAnnotationSupport(groupsOnLabel: true), andhonorsChangeAnnotationsfor rename and code actions.Tests: the mock language server now writes an
AnnotatedTextEditwith its annotation ID, as a language server sends it.Docs: a Change annotations section in
docs/LSPSupport.md.Behaviour changes
workspace/applyEditasks to confirm it, by label, and leaves out the unchecked labels; Cancel applies nothingwillCreateFiles/willRenameFiles/willDeleteFilesedit leaves out its changes that need confirmationchangeAnnotationSupport(groupsOnLabel) andhonorsChangeAnnotationsfor rename and code actions, so rust-analyzer now annotatesTests
ChangeAnnotationsTest, 7 tests:AnnotatedTextEditand written back with it, which LSP4J alone doesn't do;changesmap;RenameChangeAnnotationsTest: a rename which edits the current file and, with an annotation that needs confirmation,lib.rs: confirmed, unchecked, cancelled, and without an annotation to confirm, which doesn't ask.ChangeAnnotationsCodeActionTest: a code action with its edit, and a resolved one: confirmed, unchecked and cancelled.ChangeAnnotationsWorkspaceEditTest:workspace/applyEditconfirmed, with the dialog titled by the request's label; unchecked, answeringapplied: true; and cancelled, answeringapplied: falsewith the reason;willRenameFilesedit applied without the change to confirm, and without a dialog.