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

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

Closed
palmamartin opened this issue Feb 10, 2020 · 5 comments
Closed
Labels
enhancement New feature or request

Comments

@palmamartin
Copy link

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
Copy link

mpl commented Feb 10, 2020

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 f9edabb 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
Copy link
Author

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 (f9edabb) and gopls to 0.2.2 and now it is working again.

@fhs
Copy link
Collaborator

fhs commented Feb 10, 2020

Check if gopls works without acme-lsp by running:

gopls check project.go

There is also gopls imports sub-command.

@palmamartin
Copy link
Author

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/[email protected] 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
Copy link
Collaborator

fhs commented Feb 16, 2020

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"}]}]}}]

@fhs fhs added bug Something isn't working enhancement New feature or request and removed bug Something isn't working labels Feb 16, 2020
@fhs fhs changed the title On "Put" no import path will be organised or added/removed Organize Imports code action is not working for gopls >= v0.3.1 Feb 16, 2020
@fhs fhs closed this as completed in c143b86 Feb 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants