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

Rename acts as a simple search-and-replace in some circumstances #1912

Closed
sylbru opened this issue Dec 4, 2021 · 6 comments
Closed

Rename acts as a simple search-and-replace in some circumstances #1912

sylbru opened this issue Dec 4, 2021 · 6 comments
Labels
language server issue Issues related to language servers communicating with this plugin

Comments

@sylbru
Copy link

sylbru commented Dec 4, 2021

Describe the bug
Note: This issue was reported in the Elm language server repo, before I tried it in VS Code where things are working as expected. So it looks like the problem is coming from another layer.

Using LSP-elm, is some circumstances (detailed below), it seems like LSP: Rename acts as a simple search-and-replace on whole words, changing the name of a function even inside a literal string.

To Reproduce
Steps to reproduce the behavior:

  1. Create a new Elm project with elm init (npm install -g elm if needed)
  2. Create src/Main.elm with the following:
module Main exposing (..)

import Html

main =
    Html.text myString

myString : String
myString =
    "blah"

somethingElse : String
somethingElse =
    "text including myString"
  1. Place the cursor on the myString function definition
  2. Execute the LSP: Rename command, specifying another name like myRenamedString
  3. If it works as expected (not touching the string), try this:
    1. Remove the space in the somethingElse string between "including" and "myString"
    2. Save the file
    3. Put the space back between "including" and "myString".
    4. Execute the LSP: Rename command, specifying another name like myRenamedString

The observed behaviour is that "text including myString" gets changed to "text including myRenamedString".

When I’m just opening the project, I always have to do the additional steps described in 5. above. Even though the source is exactly the same, the bug does not happen before I touch this string and put it back as it was.

This behaviour seems somewhat erratic, but quite predictible when I open the project and execute these steps exactly, before doing anything else.

Expected behavior
LSP: Rename should never change a literal string, at the very least.

Environment:

  • OS: Linux Mint 20.2
  • Sublime Text version: 4121
  • LSP version: 1.14.0
  • Language servers used: Elm (sublimelsp/LSP-elm 1.1.12)
@rchl
Copy link
Member

rchl commented Dec 4, 2021

Definitively looks like an elm server issue.

Reproduced in VSCode also:

Screen.Recording.2021-12-04.at.18.27.47.mov

The LSP client just sends the position of the symbol to the server and receives back edits to apply so it's hard to get anything wrong here on the client side.

@rchl rchl closed this as completed Dec 4, 2021
@rchl rchl added the language server issue Issues related to language servers communicating with this plugin label Dec 4, 2021
@sylbru
Copy link
Author

sylbru commented Dec 6, 2021

I’m confused: you are saying you reproduced the issue under VS Code, while your screen recording clearly doesn’t show you did…

I imagine the LSP client shouldn’t do anything "clever" and just apply edits received from the server. But on the language server side, I’m told it does work properly under VS Code so it must be a bug on the LSP plugin side.

Can you tell me if there is a way to see what the language server is sending to the client?

@rchl
Copy link
Member

rchl commented Dec 6, 2021

Ops. Sorry, I've got confused since I don't know the language. :)

Actually I can't reproduce it in ST either.

@rchl rchl removed the language server issue Issues related to language servers communicating with this plugin label Dec 6, 2021
@rchl
Copy link
Member

rchl commented Dec 6, 2021

Can you tell me if there is a way to see what the language server is sending to the client?

Enable log_server option - https://lsp.sublimetext.io/troubleshooting/#self-help-instructions

@sylbru
Copy link
Author

sylbru commented Dec 6, 2021

Thanks! That’ll help me see what’s going on. Yeah it’s pretty weird, at least it’s consistent on my setup.

@rchl rchl reopened this Dec 6, 2021
@sylbru
Copy link
Author

sylbru commented Dec 6, 2021

So I reproduced the issue with the debug logs enabled, and it’s pretty clear that the language server is returning 4 edits instead of 3. I’ll close this and add that tag back :)

EDIT: Oh I can’t add the tag actually.

:: --> LSP-elm textDocument/rename(116): {'textDocument': {'uri': 'file:///data/Fichiers/Code/testbuglspelm/src/Main.elm'}, 'position': {'line': 9, 'character': 0}, 'newName': 'myaiueString', 'workDoneToken': 'wd116'}
LSP-elm: Renaming was requested
:: <-  LSP-elm window/logMessage: {'message': 'Renaming was requested', 'type': 3}
:: <<< LSP-elm 116: {'documentChanges': [{'textDocument': {'version': None, 'uri': 'file:///data/Fichiers/Code/testbuglspelm/src/Main.elm'}, 'edits': [{'range': {'start': {'line': 9, 'character': 0}, 'end': {'line': 9, 'character': 8}}, 'newText': 'myaiueString'}, {'range': {'start': {'line': 10, 'character': 0}, 'end': {'line': 10, 'character': 8}}, 'newText': 'myaiueString'}, {'range': {'start': {'line': 6, 'character': 14}, 'end': {'line': 6, 'character': 22}}, 'newText': 'myaiueString'}, {'range': {'start': {'line': 16, 'character': 20}, 'end': {'line': 16, 'character': 28}}, 'newText': 'myaiueString'}]}], 'changes': {'file:///data/Fichiers/Code/testbuglspelm/src/Main.elm': [{'range': {'start': {'line': 9, 'character': 0}, 'end': {'line': 9, 'character': 8}}, 'newText': 'myaiueString'}, {'range': {'start': {'line': 10, 'character': 0}, 'end': {'line': 10, 'character': 8}}, 'newText': 'myaiueString'}, {'range': {'start': {'line': 6, 'character': 14}, 'end': {'line': 6, 'character': 22}}, 'newText': 'myaiueString'}, {'range': {'start': {'line': 16, 'character': 20}, 'end': {'line': 16, 'character': 28}}, 'newText': 'myaiueString'}]}}

@sylbru sylbru closed this as completed Dec 6, 2021
@rwols rwols added the language server issue Issues related to language servers communicating with this plugin label Dec 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
language server issue Issues related to language servers communicating with this plugin
Projects
None yet
Development

No branches or pull requests

3 participants