Bug 449332 - LSP Client Rename does not work for Go and gopls
Summary: LSP Client Rename does not work for Go and gopls
Status: RESOLVED FIXED
Alias: None
Product: kate
Classification: Applications
Component: general (show other bugs)
Version: 21.12.1
Platform: Arch Linux Linux
: NOR normal
Target Milestone: ---
Assignee: KWrite Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-01-29 16:42 UTC by Juris
Modified: 2022-02-03 18:33 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Juris 2022-01-29 16:42:36 UTC
SUMMARY

LSP Client rename symbol functionality is broken for Go and gopls.

STEPS TO REPRODUCE
1. Call LSP Client -> Rename for some symbol (for example function)
2. Enter new name


OBSERVED RESULT
Symbol was not renamed.

EXPECTED RESULT
Symbol should be renamed

SOFTWARE/OS VERSIONS
Windows: 
macOS: 
Linux/KDE Plasma: 
(available in About System)
KDE Plasma Version: 
KDE Frameworks Version: 
Qt Version: 

ADDITIONAL INFORMATION

Sample main.go file:

package main

func main() {
    myFunction()
}

// myFunction is just a dummy function
func myFunction() {
    return
}

Trace logs from gopls when calling rename action:

[Trace - 18:41:39.802 PM] Sending request 'textDocument/rename - (12)'.
Params: {
        "newName": "myFunctionNew",
        "position": {
            "character": 12,
            "line": 7
        },
        "textDocument": {
            "uri": "file:///tmp/goproj/main.go"
        }
    }


[Trace - 18:41:39.803 PM] Received response 'textDocument/rename - (12)' in 0ms.
Result: {"documentChanges":[{"textDocument":{"version":167,"uri":"file:///tmp/goproj/main.go"},"edits":[{"range":{"start":{"line":3,"character":4},"end":{"line":3,"character":14}},"newText":"myFunctionNew"},{"range":{"start":{"line":6,"character":3},"end":{"line":6,"character":13}},"newText":"myFunctionNew"},{"range":{"start":{"line":7,"character":5},"end":{"line":7,"character":15}},"newText":"myFunctionNew"}]}]}



Operating System: Arch Linux
KDE Plasma Version: 5.23.5
KDE Frameworks Version: 5.90.0
Qt Version: 5.15.2
Kernel Version: 5.16.2-arch1-1 (64-bit)
Graphics Platform: Wayland
Processors: 12 × AMD Ryzen 5 5600G with Radeon Graphics
Memory: 13,6 GiB of RAM
Graphics Processor: AMD RENOIR
Comment 1 Mark Nauwelaerts 2022-01-30 20:14:17 UTC
The response from the gopls server is not quite what it should be, see specifications on https://microsoft.github.io/language-server-protocol/specifications/specification-3-17/#workspaceEdit

In this case, it chooses to use the documentChanges property, but it should only do that if the client specifies suitable capabilities. In this case, the LSP plugin does not specify those, as it does not (yet) support that type of response.  We may extend that parsing somewhat on the client side, but as it stands it is a server-side protocol issue.
Comment 2 Juris 2022-01-31 07:37:29 UTC
(In reply to Mark Nauwelaerts from comment #1)
> The response from the gopls server is not quite what it should be, see
> specifications on
> https://microsoft.github.io/language-server-protocol/specifications/
> specification-3-17/#workspaceEdit
> 
> In this case, it chooses to use the documentChanges property, but it should
> only do that if the client specifies suitable capabilities. In this case,
> the LSP plugin does not specify those, as it does not (yet) support that
> type of response.  We may extend that parsing somewhat on the client side,
> but as it stands it is a server-side protocol issue.

Mark, thanks for explanation! I am not versed in LSP client/server protocol. What I hear is that there might be issue on gopls side. If that is correct the I suppose it makes sense to open issue on their issue tracker. Would you be willing to comment on issue since I might not have the best idea what is going on?

Thanks!
Comment 3 Juris 2022-01-31 07:46:13 UTC
(In reply to Juris from comment #2)
> (In reply to Mark Nauwelaerts from comment #1)
> > The response from the gopls server is not quite what it should be, see
> > specifications on
> > https://microsoft.github.io/language-server-protocol/specifications/
> > specification-3-17/#workspaceEdit
> > 
> > In this case, it chooses to use the documentChanges property, but it should
> > only do that if the client specifies suitable capabilities. In this case,
> > the LSP plugin does not specify those, as it does not (yet) support that
> > type of response.  We may extend that parsing somewhat on the client side,
> > but as it stands it is a server-side protocol issue.
> 
> Mark, thanks for explanation! I am not versed in LSP client/server protocol.
> What I hear is that there might be issue on gopls side. If that is correct
> the I suppose it makes sense to open issue on their issue tracker. Would you
> be willing to comment on issue since I might not have the best idea what is
> going on?
> 
> Thanks!

Mark,

I created issue on gopls project, please, feel free to add comments.

https://github.com/golang/go/issues/50922

 I will appreciate your input very much! Thank You!
Comment 4 Bug Janitor Service 2022-01-31 22:14:57 UTC
A possibly relevant merge request was started @ https://invent.kde.org/utilities/kate/-/merge_requests/580
Comment 5 Mark Nauwelaerts 2022-02-03 18:33:31 UTC
Git commit e1b89deaec075e9b155877ba5e549ed87baf1395 by Mark Nauwelaerts.
Committed on 31/01/2022 at 21:05.
Pushed by cullmann into branch 'master'.

lspclient: also support some alternative WorkspaceEdit replies
Related: bug 447640

M  +22   -9    addons/lspclient/lspclientpluginview.cpp

https://invent.kde.org/utilities/kate/commit/e1b89deaec075e9b155877ba5e549ed87baf1395