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

[Sublime Text] Rename acts as a simple search-and-replace in some circumstances #661

Open
sylbru opened this issue Nov 18, 2021 · 8 comments

Comments

@sylbru
Copy link

sylbru commented Nov 18, 2021

Using the language server with Sublime Text 4, the "LSP: Rename" action is acting as a simple search-and-replace.

Expected Behavior

Consider the following file:

module Main exposing (..)

import Html

main =
    Html.text myString

myString : String
myString =
    "blah"

somethingElse : String
somethingElse =
    "text including myString"

Executing the Rename action on myString should perform exactly three replacements: the myString type annotation, myString definition, and the reference to it in main. It should in no circumstances change the contents of a string.

Current Behavior

The Rename action performs the three replacements mentioned above, as well as a fourth one, replacing the word myString in the string defined as somethingElse.

Possible Solution

It seems like the Rename action performs a search-and-replace looking for the function name in the file(s) as a whole word. If I remove the spaces in somethingElse, everything works as expected.

Steps to Reproduce (for bugs)

  1. Create a new project with the file above as Main.elm
  2. Place the cursor on the myString function definition
  3. Execute the LSP code action Rename, specifying another name like myRenamedString
  4. If it works as expected (not touching the string), try removing the space in the somethingElse string between "including" and "myString", and putting it back again. It behaves like this when I reopen the project: 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.

Context

I experienced a bug because of this, as I had a URL string like "?action=doSearch" that was being changed when renaming a function called doSearch.

Your Environment

  • Version used: 2.3.0 via sublimelsp/LSP-elm 1.1.12
  • Editor used: Sublime Text 4, build 4121
  • Environment name and version (e.g. node.js 5.4):
  • Operating System and version: Linux Mint 20.2
@sylbru
Copy link
Author

sylbru commented Nov 18, 2021

I’m unable to reproduce this in VSCode. :/

@razzeee
Copy link
Member

razzeee commented Dec 3, 2021

Did you raise this with the sublime client team?

@sylbru
Copy link
Author

sylbru commented Dec 4, 2021

I didn’t bother raising the issue on the LSP-elm plugin because it looks like a simple wrapper around the language server, but maybe I should, and maybe also on the general Sublime LSP plugin if that’s what you mean.

@sylbru
Copy link
Author

sylbru commented Dec 4, 2021

Do you think it’s more likely to come from the LSP plugin or the LSP-elm plugin? (if you have any idea about that!)

@razzeee
Copy link
Member

razzeee commented Dec 4, 2021

From your wording it did sound, like it would be the general plugin.
Still, I would think that rename is one of the first things to implement.

@sylbru
Copy link
Author

sylbru commented Dec 6, 2021

After enabling the debug logs, I was able to see that the language server is returning 4 edits instead of 3, so it does tell the client to change "myString" inside that literal string on the last line.

Here is the relevant log output, please tell me if I can provide additional relevant information. (Line numbers don’t match exactly because I removed some empty lines in the source file for this bug report)

:: --> 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'}]}}
::  -> LSP-elm textDocument/didChange: {'textDocument': {'version': 26, 'uri': 'file:///data/Fichiers/Code/testbuglspelm/src/Main.elm'}, 'contentChanges': [{'range': {'start': {'line': 16, 'character': 20}, 'end': {'line': 16, 'character': 28}}, 'text': 'myaiueString', 'rangeLength': 8}, {'range': {'start': {'line': 10, 'character': 0}, 'end': {'line': 10, 'character': 8}}, 'text': 'myaiueString', 'rangeLength': 8}, {'range': {'start': {'line': 9, 'character': 0}, 'end': {'line': 9, 'character': 8}}, 'text': 'myaiueString', 'rangeLength': 8}, {'range': {'start': {'line': 6, 'character': 14}, 'end': {'line': 6, 'character': 22}}, 'text': 'myaiueString', 'rangeLength': 8}]}

@razzeee
Copy link
Member

razzeee commented Dec 25, 2021

This isn't happening in vscode, so it has to be something thats different in the client in my opinion

image

@sylbru
Copy link
Author

sylbru commented Apr 8, 2022

I’m not encountering this in my day-to-day use, but I tried it again just to see if it was still happening.

So it’s pretty consistent, when I initially open the project it’s working as expected, then I remove the space in the string between "including" and "myString", I save the file, and then I put the space back, and I save again. Now the Rename action changes the string. And I can even find the "text including myString" string in references for the myString variable, so clearly there was an issue with the parsing of the file somewhere. Is there a way to see the AST somehow?

image

Sorry I know this bug is annoying and hard to test especially since it’s not happening in VSCode. As I said I’m not encountering this in my day-to-day use, but I’d be happy to help in any way if I can. Please tell me if there’s any more information I can gather (like logging the contents of the file that were sent to the language server, logging the parsed AST…).


Here’s the demonstration of the bug happening. When the log panel closes, it means I’m saving the file (after removing the space, and after putting the space back; it looks like saving twice matters in order to reproduce the bug…)

elm-lsp-rename-bug

@sylbru sylbru changed the title Rename acts as a simple search-and-replace in some circumstances [Sublime Text] Rename acts as a simple search-and-replace in some circumstances Apr 8, 2022
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

No branches or pull requests

2 participants