Skip to content
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

Inlay hint #2018

Merged
merged 68 commits into from
Aug 20, 2022
Merged

Inlay hint #2018

merged 68 commits into from
Aug 20, 2022

Conversation

predragnikolic
Copy link
Member

@predragnikolic predragnikolic commented Aug 12, 2022

This PR implements the inlay hints spec.

It will show inlay hints in the view.
It exposes a setting to show/hide inlay hints - "show_inlay_hints": boolean.

[UPDATED]: The toggle functionality will be left out from this PR:
It exposes a keybinding to toggle that setting:

    {
        "command": "lsp_toggle_inlay_hints",
        "keys": [
            "UNBOUND"
        ],
        "context": [
            {
                "key": "lsp.session_with_capability",
                "operator": "equal",
                "operand": "inlayHintProvider"
            }
        ]
    }

It exposes a command palette command to toggle that setting: LSP: Toggle Inlay Hints

Here is an example:

Screenshot 2022-08-12 at 14 46 27

Kapture 2022-08-12 at 14 44 13

This can be tried with this LSP-volar PR.

closes #1746

predrag-codetribe and others added 15 commits August 11, 2022 14:45
Co-authored-by: jwortmann <jwortmann@outlook.com>
…ugh a keybinding or the command palette with LSP: Toggle Inlay Hints
to re-fetch the newest inlay hints to avoid showing stale inlay hints.
In order to follow the spec more precisly
/**
 * ...
 *
 * *Note* that edits are expected to change the document so that the inlay
 * hint (or its nearest variant) is now part of the document and the inlay
 * hint itself is **now obsolete**.
 *
 * ...
 */
textEdits?: TextEdit[];

Phantoms have an id but we cannot rely on that field because it is none at the time of creating the Phantom.
It is creted only when the phantom_set is created.

Instead attach a custom lsp_uuid field on the phantom
@predragnikolic
Copy link
Member Author

@predragnikolic

This comment was marked as outdated.

sublime-package.json Outdated Show resolved Hide resolved
@Penguin98kStudio
Copy link

Is it possible to add some settings to let the user select the different font options for inlayhint

I believe that I didn't implement correctly handling of label.commands, so I will remove them.

Mosly because I am itrating of label_parts and triggering commands for each label_part,

but I think I shul run only one command from the clicked label part.
or the one who do not have text edits but support resolving(this is still not perfect but a better behavior)
@predragnikolic
Copy link
Member Author

@Penguin98kStudio ST "font_face" setting will be respected.
d833b4c

@predragnikolic predragnikolic marked this pull request as draft August 13, 2022 22:13
plugin/session_view.py Outdated Show resolved Hide resolved
plugin/inlay_hint.py Outdated Show resolved Hide resolved
LSP.sublime-settings Outdated Show resolved Hide resolved
plugin/core/types.py Outdated Show resolved Hide resolved
sublime-package.json Outdated Show resolved Hide resolved
sublime-package.json Outdated Show resolved Hide resolved
@rwols rwols merged commit 314ec85 into main Aug 20, 2022
@rwols rwols deleted the inlay-hint branch August 20, 2022 14:46
@predragnikolic
Copy link
Member Author

🙌

@jwortmann
Copy link
Member

I wonder if inlay hints should use an increased debounce time. Currently they are forced to use the FEATURES_TIMEOUT defined as 300 ms for the debounce time after text changed.

debounced(lambda: self.purge_changes_async(view), FEATURES_TIMEOUT,

VSCode uses 1250 ms, see microsoft/vscode#133730

@predragnikolic
Copy link
Member Author

@jwortmann yep, I can see that being an issue.

@rchl
Copy link
Member

rchl commented Aug 23, 2022

The only argument against doing that right now might be the fact that ST UX is kinda broken with those and shorter timeout helps with fixing ST issues faster while typing. For example the phantom doesn't shift to the right when typing right in front of it.

@jwortmann
Copy link
Member

jwortmann commented Aug 23, 2022

Another thing I see in the code is that an ongoing request is not canceled when another request is to be made and the response for the previous one hasn't arrived yet. This also means that the result will be drawn unconditionally, despite that the response arrives after more changes in the buffer were made.

For semantic tokens I added a line to cancel a pending request whenever a new request is in preparation:

if self.semantic_tokens.pending_response:
self.session.cancel_request(self.semantic_tokens.pending_response)

I'm not sure what the expected average/maximum times for inlay hint responses is, but it might be an improvement to also cancel the ongoing request if new changes were made. In fact, according to the linked issue apparently VSCode does it this way.

But compared to my implementation of the request canceling for semantic tokens, I think for inlay hints it would be better to move the part shown in the two lines above into on_text_changed_async under if purge: (and not within the debounced part, which is the case for semantic tokens):

if purge:
debounced(lambda: self.purge_changes_async(view), FEATURES_TIMEOUT,
lambda: view.is_valid() and change_count == view.change_count(), async_thread=True)

Because at that time we already know that a new request will be made very soon and that the pending results are already outdated and drawing them might make the cursor jump arround annoyingly, so that the resonse should better be ignored instead.

rchl added a commit that referenced this pull request Aug 25, 2022
* main:
  Implement inlay hints (#2018)
  Improve strategy for semantic highlighting requests
  Fix parameter name mismatch reported by Pyright (#2021)
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.

Look into textDocument/inlayHints
6 participants