LSP icon indicating copy to clipboard operation
LSP copied to clipboard

Code action (annotation) not updated after document change

Open rchl opened this issue 4 years ago • 4 comments

Describe the bug Clicking the code action annotation triggers document modification but the annotation does not get refreshed, still showing the old "suggestion" that does not do anything when clicking. The cursor has to be moved to update it.

To Reproduce Steps to reproduce the behavior:

  1. Install LSP-rust-analyzer
  2. Go to https://github.com/rust-analyzer/rust-analyzer/blob/5b663f1b07233442a3b0b58db453504dcc51ddc9/lib/arena/src/map.rs#L23-L23
  3. Click the annotation to convert line comment to block comment

Expected behavior The code action annotation should automatically update after document is changed.

Screenshots

https://user-images.githubusercontent.com/153197/122014134-29488c00-cdbf-11eb-9242-af065af07605.mov

Environment (please complete the following information):

  • OS: macOS
  • LSP version: 1.5.0

rchl avatar Jun 15 '21 07:06 rchl

It's a code action actually. Changing bug description to reflect that.

:: --> rust-analyzer textDocument/codeAction(72): {'context': {'diagnostics': []}, 'range': {'end': {'character': 25, 'line': 22}, 'start': {'character': 25, 'line': 22}}, 'textDocument': {'uri': 'file:///.../rust-analyzer/lib/arena/src/map.rs'}}
:: <<< rust-analyzer 71: None
:: <<< rust-analyzer 72: [{'data': {'id': 'line_to_block:RefactorRewrite:0', 'codeActionParams': {'context': {'diagnostics': []}, 'range': {'end': {'character': 25, 'line': 22}, 'start': {'character': 25, 'line': 22}}, 'textDocument': {'uri': 'file:///.../rust-analyzer/lib/arena/src/map.rs'}}}, 'title': 'Replace line comments with a single block comment', 'kind': 'refactor.rewrite'}]

rchl avatar Jun 15 '21 07:06 rchl

There is also a small issue with the annotation collapsing if hovered shortly after the document is modified. Possibly because internally we re-create it.

rchl avatar Jun 15 '21 07:06 rchl

cannot reproduce because LSP no longer displays the 'Replace line comments with a single block comment' in the annotations.

Screencast from 2023-08-18 00-00-18.webm

predragnikolic avatar Aug 17 '23 22:08 predragnikolic

I had to do a bit of a hack to reproduce but it still reproduces:

diff --git a/plugin/documents.py b/plugin/documents.py
index 243a443..3331045 100644
--- a/plugin/documents.py
+++ b/plugin/documents.py
@@ -636,10 +636,11 @@ class DocumentSyncListener(sublime_plugin.ViewEventListener, AbstractViewListene
             return
         diagnostics_by_config, covering = self.diagnostics_intersecting_async(self._stored_selection[0])
         actions_manager \
-            .request_for_region_async(self.view, covering, diagnostics_by_config, manual=False) \
+            .request_for_region_async(self.view, covering, diagnostics_by_config, manual=True) \
             .then(self._on_code_actions)
 
     def _on_code_actions(self, responses: List[CodeActionsByConfigName]) -> None:
+        responses = [(name, [actions[0]]) for name, actions in responses]
         self._actions_by_config = responses
         action_count = 0
         first_action_title = ''

rchl avatar Aug 20 '23 21:08 rchl