9fans / acme-lsp

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

automatic imports on formatting not working #62

Closed kmx1 closed 5 months ago

kmx1 commented 10 months ago

when using the latest gopls and latest acme-lsp the automatic importing of go modules breaks

this is probably caused by a change in the gopls protocol, i tried several older version too (about 0.12 - 0.14) but it sill was broken

golang.org/x/tools/gopls v0.14.0
go version go1.21.3 linux/amd64

i traced the error to the CompatibleCodeActions function in internal/lsp/utils.go and implemented a very very quick and dirty fix to remedy the issue. https://github.com/kmx1/acme-lsp/commit/dea92a6f057827d71db4cb7581a7768b6ba567ff the type switch never got into the case protocol.CodeActionOptions

although it should probably be fixed in the protocol package? if that is even the cause

but maybe this should be done by someone who has a more thorough understanding of the LSP protocol and gopls

i hope that helps and thank you for this project

farhaven commented 10 months ago

Adding my 2 cents here:

the way the code currently works seems to be OK on my work laptop (macos), but we're using a Go packages driver there, so maybe that has some impact on automatically importing packages.

On my personal (linux) machine for projects that just use gopls as-is, your diff fixed imports on Lfmt for me.

rsc commented 5 months ago

Fixed with roughly the same diff in v0.12.0. Note that acme-lsp has moved: go install 9fans.net/acme-lsp/cmd/acme-lsp@latest for the fix.