Running staticcheck with eglot and gopls
Posted on 17th of March 2023 | 188 wordsAnother neat finding in Go’s language server. Basically, I wanted to
include some sort of way to run some static analyser with my language
server. I remember golanci-lint
was long the “de facto” tool for
this, but seems that staticcheck
has grown a
lot in popularity. So I wanted to integrate that with my gopls
.
Naturally, the first step was installing the tool itself. Fortunately, that can be done super easily with just:
$ go install honnef.co/go/tools/cmd/staticcheck@latest
Next I needed to enable this somehow with gopls
. Again fortunately,
all the possible settings for gopls
can be found
here.
Including the simple variable for staticcheck
. To pass in this
setting to eglot
, I need to configure variable
eglot-workspace-configuration
, which basically allows you to
configure LSP servers specifically for a given project and given LSP.
To pass in the setting to the gopls
, we need to pass in a plist
with the configurations we want:
(use-package eglot :custom (eglot-workspace-configuration '((:gopls . ((staticcheck . t)))))) ;; OR (setq-default eglot-workspace-configuration '((:gopls . ((staticcheck . t)))))
Naturally, you can pass any setting you desire that is available for the language server this way.