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

Request code actions at the cursor/selection when the selection is modified #1085

Closed
rwols opened this issue Jun 2, 2020 · 4 comments
Closed

Comments

@rwols
Copy link
Member

rwols commented Jun 2, 2020

The rust-analyzer language server makes use of VSCode's behavior to request "diagnostic-less" code actions at the cursor whenever it changes. A user reported this on discord. We should mirror the behavior. This has already been observed and discussed here.

Because code-actions returned from this type of request do not belong to any diagnostics, we may have to adjust the internal design of the code a little for this feature. For example, we should invalidate those type of code actions whenever the buffer is modified. Most likely we can re-use the logic present in highlights.py or color.py.

Also, the user cannot "see" these code actions unless they turned on the gutter bulb.

@rchl
Copy link
Member

rchl commented Jun 2, 2020

I can do it after finishing CAOS (soon, I think). I'd want to avoid conflicting changes for now :)

@rchl
Copy link
Member

rchl commented Jun 9, 2020

I wonder if it's again because of custom handling in the extension that makes this server trigger code actions on selection change. It doesn't look like VSCode triggers code actions on selection change for other servers (tried eslint).

Here is some relevant code but it doesn't give me a clear answer: https://github.com/rust-analyzer/rust-analyzer/blob/4029628f15c612182ad9da1c652078f9df62f5cf/editors/code/src/client.ts#L69-L71

If that middleware is called on every selection change then that would explain the behavior but then do we really want to do the same for every server?

And then there is also this comment in that code:

// In our case we expect to get code edits only from diagnostics

which doesn't really seem to be the case.

EDIT: Actually that seems right. It receives edit-less code actions and creates "commands" from them.

@rchl
Copy link
Member

rchl commented Jun 9, 2020

Also, it builds somewhat custom code actions in that code so, since we don't do that, those code actions wouldn't work for us anyway.

action.command = {
                            command: "rust-analyzer.resolveCodeAction",
                            title: item.title,
                            arguments: [resolveParams],
                        };

So this behavior might be wanted anyway but rust-analyzer will still not function properly.

And we might want to consider performance impact of triggering code actions on all cursor movements (even when typing).

rchl added a commit that referenced this issue Jun 9, 2020
- When requesting code actions using keyboard action, take whole selection
  range into account rather than just selection end point.
- Move code action requesting code into CodeActionsManager class to have
  one common endpoint. "request_code_actions" is left outside because
  it's imported by tests (but technically could also move it inside).
- (WIP) Trigger code actions on selection changes. This uses new ST4
  annotations feature to show the number of available code actions. It's
  better than bulb as bulb can't be clicked. The underline of the link
  looks a bit wrong in the annotation (seems like an ST bug). Also, it's
  not clear if we really want this feature. Maybe if we optimize it to
  not trigger for *all* selection changes (so also when typing).
- I guess we could support all selections for this feature instead of
  only the first one.

Resolves #1085
rchl added a commit that referenced this issue Jun 10, 2020
- When requesting code actions using keyboard action, take whole selection
  range into account rather than just selection end point.
- Move code action requesting code into CodeActionsManager class to have
  one common endpoint. "get_matching_kinds" is left outside because
  it's imported by tests (but technically could also move it inside).
- (WIP) Trigger code actions on selection changes. This uses new ST4
  annotations feature to show the number of available code actions. It's
  better than bulb as bulb can't be clicked. The underline of the link
  looks a bit wrong in the annotation (seems like an ST bug). Also, it's
  not clear if we really want this feature. Maybe if we optimize it to
  not trigger for *all* selection changes (so also when typing).
- I guess we could support all selections for this feature instead of
  only the first one.

Resolves #1085
rchl added a commit that referenced this issue Jun 12, 2020
- When requesting code actions using keyboard action, take whole selection
  range into account rather than just selection end point.
- Move code action requesting code into CodeActionsManager class to have
  one common endpoint. "get_matching_kinds" is left outside because
  it's imported by tests (but technically could also move it inside).
- (WIP) Trigger code actions on selection changes. This uses new ST4
  annotations feature to show the number of available code actions. It's
  better than bulb as bulb can't be clicked. The underline of the link
  looks a bit wrong in the annotation (seems like an ST bug). Also, it's
  not clear if we really want this feature. Maybe if we optimize it to
  not trigger for *all* selection changes (so also when typing).
- I guess we could support all selections for this feature instead of
  only the first one.

Resolves #1085
@rwols
Copy link
Member Author

rwols commented Jun 18, 2020

Implemented by #1109

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants