dominikh / go-mode.el

Emacs mode for the Go programming language
BSD 3-Clause "New" or "Revised" License
1.37k stars 209 forks source link

go mode does not work when open a single go file to edit #376

Closed shizhz closed 3 years ago

shizhz commented 3 years ago

Hi,

Is it possible to make go-mode work for a single go file or buffer which is outside any project? Currently I'll get the following error message:

LSP :: test.go not in project or it is blacklisted. Suspicious state from syntax checker golangci-lint: Flycheck checker golangci-lint returned 5, but its output contained no errors: level=error msg="Running error: context loading failed: no go files to analyze"

Try installing a more recent version of golangci-lint, and please open a bug report if the issue persists in the latest release. Thanks!

Thanks.

psanford commented 3 years ago

Those errors appear to be from lsp-mode and something that has hooked up golangci-lint to Flycheck.

Those are not part of the go-mode package. go-mode works fine on single files.

shizhz commented 3 years ago

Yes it's not an issue of go-mode, it's the limitation of LS which needs a workspace to work correctly. I've asked help from ls-mode community and the workaround could be:

The key is that you need to mock a workspace environment to make gopls happy. Hope this could help those who has the same problem as me.