Skip to content

Conversation

@jwortmann
Copy link
Member

@jwortmann jwortmann commented Nov 5, 2025

Continuing from #2666

I refactored and renamed CodeLensView and moved the handling from SessionView to SessinBuffer, so that it is not done in parallel with the same data in case there are cloned (split) views. I have kept the caching for the annotations/commands and re-enabled resolving for the visible viewport area after selection change, which was accidentally removed in #2666. Unfortunately if the server uses codeLens/resolve the code lenses don't work great together with the filtering of supported commands. But it should be fine at least for the current viewport area due to the implemented caching. If you scroll away, you might need to click into the viewport (to change the selection and trigger resolve) before code lenses show up. But I also made some improvements for the caching:

The previous implementation first converted the line and column based LSP Range to a sublime.Region

self.region = range_to_region(data['range'], view)

and then used that Region as the key to store code lenses grouped by region:
region.to_tuple(): list(groups)

Then when code lenses are updated after a buffer change, it used the new regions to check if it can re-use the previous annotations temporarily until the code lenses get updated with the real data from codeLens/resolve. But this would only work for the code lenses between the start of the file and the cursor postion (where user is currently typing), because the offset-based regions for the code lenses that come after the cursor position would change after typing or deleting some characters in the file. So in this PR I used the line and column based LSP ranges as keys for the code lens groups instead. If you type some characters on a line, the LSP ranges for the code lenses after that line are still the same, and therefore caching should work for all code lenses in the entire file, except for the exact line where the user is typing and as long as the user didn't type or deleted a linebreak.

This rewrite also significantly reduces the number of ST API calls for add_regions and for updating phantoms. Now only a single region key per session is used for the code lens annotations, instead of one key per code lens and session. I wonder whether there was a reason that it was implemented as one region key per code lens before?

LSP/plugin/code_lens.py

Lines 203 to 205 in 72e6516

for index, lens in enumerate(self._flat_iteration()):
self.view.add_regions(
self._region_key(lens.session_name, index), [lens.region], "", "", flags, [lens.small_html], accent)

Furthermore, if there were no code lenses in the view, and no code lenses need to be added after a buffer change, there is no unnecessary API call anymore to clear annotations and phantoms.

More fixes and changes:

  • fixes to cancel codeLens/resolve requests and not codeAction/resolve, which is a bug in the current implementation:
    if data.request.method == 'codeAction/resolve':
  • fixes code lenses not immediately being redrawn on user setting change (switch between phantom/annotation)
  • fixes Code Lenses duplicate on creating "Split View" #2355
  • the LspCodeLensCommand now uses the quick panel instead of a popup menu at the caret position to show options when there are multiple code lenses

Fixes #2497
Fixes #2355

@netlify
Copy link

netlify bot commented Nov 5, 2025

Deploy Preview for sublime-lsp ready!

Name Link
🔨 Latest commit bb6c89c
🔍 Latest deploy log https://app.netlify.com/projects/sublime-lsp/deploys/690bbb223eb4130008d20864
😎 Deploy Preview https://deploy-preview-2677--sublime-lsp.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@rchl

This comment was marked as outdated.

@rchl
Copy link
Member

rchl commented Nov 5, 2025

When split view is opened it does not show code lenses until selection changes. Not sure if it was like that before also...

Co-authored-by: Rafał Chłodnicki <rchl2k@gmail.com>
@netlify
Copy link

netlify bot commented Nov 5, 2025

Deploy Preview for sublime-lsp ready!

Name Link
🔨 Latest commit 2f6da91
🔍 Latest deploy log https://app.netlify.com/projects/sublime-lsp/deploys/690bcaeb44d1720008aba997
😎 Deploy Preview https://deploy-preview-2677--sublime-lsp.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@jwortmann
Copy link
Member Author

jwortmann commented Nov 5, 2025

When split view is opened it does not show code lenses until selection changes. Not sure if it was like that before also...

I will look into that tomorrow or over the weekend and do some more testing for edge cases.

Edit: fixed in e473dbf

@jwortmann jwortmann marked this pull request as ready for review November 6, 2025 19:56
@rchl
Copy link
Member

rchl commented Nov 9, 2025

We have to release new LSP version ASAP since there are things relying on it. Hope everyone is fine with that. :)

@rchl rchl mentioned this pull request Nov 9, 2025
@jwortmann jwortmann merged commit 56f7cd2 into sublimelsp:main Nov 9, 2025
8 checks passed
@jwortmann jwortmann deleted the code-lens branch November 9, 2025 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

... annotations popping up Code Lenses duplicate on creating "Split View"

2 participants