Skip to content

How to respond to rename request if user cancelled (via a showMessageRequest)? #1104

Open

Description

@DanTup

I have this scenario:

  • User invokes rename
  • The location is valid, so prepareRename returns normally
  • User enters a name that is already in use (or some other name that would result in invalid code)
  • Server sends a showMessageRequest informing the user this will produce an error, with options to "Rename anyway" or "Cancel rename"
  • User clicks "Cancel rename"

In this case, if I respond to the original rename request with RequestCancelled, VS Code will show an information notification saying it was cancelled. If I return null, it will show an information notification showing "No result":

Screenshot 2020-10-14 at 16 24 11

So my next thought is to return a WorkspaceEdit that has no changes in it. However, it feels awkward and it's not clear whether this is the correct route.

The spec isn't really clear what a null response means here (nor is it generally clear when clients should/should not show notifications for some responses). This is just one example, but I can imagine many other types of requests could be cancelled by the user via a showMessageRequest, so I think it should be clear how servers should response to requests cancelled in this way (that the client doesn't know were cancelled, because it was server-logic) and how clients should handle that.

Activity

  1. dbaeumer commented on Oct 20, 2020

    @dbaeumer
    Member

    I think the right approach is to use RequestCancelled (or if we think it is necessary a new RequestUserCancelled) in the response. IMO it is up to the client library to wire this up to the right cancel semantic in the editor.

    So the question for me is how this is best signaled in VS Code itself. Johannes Rieken (@jrieken) currently I will convert this into an Error with the name set to Canceled as we do for semantic highlighting. What is your proposal to handle this. Should I convert it to an empty workspace edit?

  2. added
    info-needed
    on Oct 20, 2020
  3. jrieken commented on Oct 20, 2020

    @jrieken

    I think the problem begins with showing a "custom" message with options. You leaving the flow of rename. This is also a problem for scenarios like LiveShare. The cancel-error thing might work for VS Code, worth trying.

  4. DanTup commented on Oct 20, 2020

    @DanTup
    ContributorAuthor

    I think the problem begins with showing a "custom" message with options

    Are there any alternatives for this? I had this functionality in the non-LSP implementation and it was noticed as missing from LSP, so I added this. It doesn't seem like a weird case to want to prompt the user if the rename might introduce errors (though this request was more general - there could be many reasons why a server wants to cancel a request and may wish to communicate this to the user itself instead of making it seem like something has gone wrong at the protocol level).

    In this case, returning an empty WorkspaceEdit works fine (it's what I've done with for now), though it's just not clear if it's the "best" way.

    This is also a problem for scenarios like LiveShare

    Can you elaborate? As far as the client knows, there was a rename request and it either returns a rename edit or it returns an empty edit. I wouldn't expect that there was a user prompt somewhere in the middle that influenced that decision to change how the rename would work? It's not much different to a ContentModified response - which I think is already silently dropped by the client.

  5. DanTup commented on May 19, 2021

    @DanTup
    ContributorAuthor

    Another feature request came up that makes it attractive to prompt the user mid-rename, but it's not clear from the above if it's a bad idea):

    Dart-Code/Dart-Code#3354

    In this case we don't need to be able to cancel, but we might want to prompt the user (in this case, asking if they want to rename the file when they rename the class inside it).

  6. added and removed
    info-needed
    on Nov 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions