9fans / acme-lsp

Language Server Protocol tools for the acme text editor
MIT License
195 stars 25 forks source link

Organize Imports code action is not working for gopls >= v0.3.1 #31

Closed palmamartin closed 4 years ago

palmamartin commented 4 years ago

Since I upgraded to macOS Catalina on "Put" the import path will not be organised any more (added/removed). Only the compiler will complain and write to /LSP/Diagnostics:

 /Users/m/Documents/src/project/project.go:88:14-88:26: undeclared name: strings

I tried to run acme-lsp -v but I do not get any error message or logs displayed on "Put". Any suggestions?

My config looks a follows:

WorkspaceDirectories = [
    "/Users/m/Documents/src/project",
]
FormatOnPut = true
CodeActionsOnPut = ["source.organizeImports"]

[Servers]
    [Servers.gopls]
    Command = ["gopls", "serve", "-rpc.trace"]
    StderrFile = "gopls.stderr.log"
    LogFile = "gopls.log"

        # These settings gets passed to gopls
        [Servers.gopls.Options]
        hoverKind = "FullDocumentation"

[[FilenameHandlers]]
Pattern = '([/\\]go\.mod)|([/\\]go\.sum)|(\.go)$'
ServerKey = "gopls"
mpl commented 4 years ago

Are you sure it has to do with Catalina? I recently experienced similar problems (and others), but it was after I updated gopls and/or acme-lsp. I reverted to f9edabb552417d6775aa7006343db80a42f0b8ee for acme-lsp and 0.2.2 for gopls and everything was fine again. And I am on Catalina as well. Sorry @fhs , I didn't have time to investigate/report at the time, which is why I reverted straight away.

palmamartin commented 4 years ago

No I'm not sure. It only occurred to me after I upgrade to Catalina, but it can be that after the upgrade I updated/reinstalled acme-lsp to the latest version.

I just downgraded acme-lsp to v0.9.0 (https://github.com/fhs/acme-lsp/commit/f9edabb552417d6775aa7006343db80a42f0b8ee) and gopls to 0.2.2 and now it is working again.

fhs commented 4 years ago

Check if gopls works without acme-lsp by running:

gopls check project.go

There is also gopls imports sub-command.

palmamartin commented 4 years ago

With the latest gopls, without acme-lsp, gopls check and gopls imports work as expected.

$ gopls version
golang.org/x/tools/gopls v0.3.1
    golang.org/x/tools/gopls@v0.3.1 h1:yNTWrf4gc4Or0UecjOas5pzOa3BL0WDDyKDV4Wz5VaM=

With acme-lsp version v0.9.0 and gopls v0.3.1 the check part works but the import part does not.

fhs commented 4 years ago

I can reproduce the issue with gopls v0.3.1 and v0.3.2. Imports code action is not working because gopls changed the response format to versioned document edits. acme-lsp does not advertise to support versioned document edits, but gopls uses the new format anyway. These kinds of breakage are probably expected until gopls 1.0 is release.

Before (not versioned edit):

[Trace - 10:23:53.697 AM] Received response 'textDocument/codeAction - (2)' in 122ms.
Result: [{"title":"Organize Imports","kind":"source.organizeImports","edit":{"changes":{"file:///tmp/hello/hello.go":[{"range":{"start":{"line":8,"character":0},"end":{"line":8,"character":0}},"newText":"\t\"fmt\"\n"}]}}}]

After (versioned document edit):

[Trace - 10:13:42.788 AM] Received response 'textDocument/codeAction - (2)' in 15ms.
Result: [{"title":"Organize Imports","kind":"source.organizeImports","edit":{"documentChanges":[{"textDocument":{"version":0,"uri":"file:///tmp/hello/hello.go"},"edits":[{"range":{"start":{"line":8,"character":0},"end":{"line":8,"character":0}},"newText":"\t\"fmt\"\n"}]}]}}]