sublimelsp / LSP

Client implementation of the Language Server Protocol for Sublime Text
https://lsp.sublimetext.io/
MIT License
1.65k stars 182 forks source link

Code action (annotation) not updated after document change #1749

Open rchl opened 3 years ago

rchl commented 3 years ago

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):

rchl commented 3 years ago

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 commented 3 years ago

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.

predragnikolic commented 1 year ago

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

rchl commented 1 year ago

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 = ''