Gopls on the command line

241 views
Skip to first unread message

Stephen Illingworth

unread,
Feb 16, 2026, 10:06:18 AMFeb 16
to golang-nuts
I want to run the gopls analsysers on all the files in my project. I was hoping something like the following would work:

    gopls check ./...

But unfortunately, "gopls check" only works with filenames and the ./... is for packages.
I really want to only check the files in each package in turn.

I've created the following bash script to do what I need:

https://gist.github.com/JetSetIlly/0cb4fb553df41e7dfba134ec4fb78cc7

    Usage: GOPLS_CHECK <PATH> [QUIET]

It works by finding all packages in the specified path and running an instance of "gopls check" for the files in each package. The number of "gopls check" running in parallel at any one time is limited to the number of CPU cores.

By default, the script will print out the names of the packages it is checking. This can be suppressed with the optional QUIET argument. When QUIET is set then only the output from gopls itself is printed.

Besides gopls, all commands should be available on any system with bash installed (xargs, dirname, etc.)



A simpler way of doing this would be to pass every file in the entire project to "gopls check" in one gulp. This didn't work well for me, seemingly because of the presence of build tags in some of my packages. The method described above works better for my purposes.

I'm posting because I thought that it might be useful to other people. I'm also curious if there are existing solutions. I was surprised at not being able to find an existing way to run the gopls analysers in this fashion.



Michael Oguidan

unread,
Feb 19, 2026, 10:00:51 AMFeb 19
to golang-nuts
thank you very much, very useful

Xie Yuchen

unread,
Mar 5, 2026, 2:32:36 AM (7 days ago) Mar 5
to golang-nuts
Hi Stephen, may I know your context of gopls check usage? Gopls is mostly used by editor so the editor passes the filenames for every opened file.

The command right now works, but a wildcard feature is helpful in your case.

Stephen Illingworth

unread,
Mar 5, 2026, 3:07:24 AM (7 days ago) Mar 5
to golang-nuts
Yes, gopls is mostly used by the editor. However, gopls does some good static checks that are not performed by "go vet" or "go fix". I Iike to perform static linter checks on the command line as part of my development process.

Running gopls on the command line works well with individual files but not well with packages. You can't just specify the path to a package, you have to list all the files in the package. My script is just a way of automating that.

It walks the source tree and calls "gopls check" with *.go wildcard for each package.

The best solution would be for "gopls check" to accept the ./... package specifier, like other go tools do. If gopls was enhanced in that way I would have no need for the script.

Stephen Illingworth

unread,
Mar 5, 2026, 3:08:13 AM (7 days ago) Mar 5
to golang-nuts
The other solution would be for "go vet" to perform the same static checks as gopls.

Jason Robert Rauch

unread,
Mar 5, 2026, 10:48:56 AM (7 days ago) Mar 5
to Xie Yuchen, golang-nuts
How long will it take to finish I kinda told the site I wouldn't use it after a finally worded email.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/golang-nuts/8b3629f0-3a4a-4e93-8fb4-573bce4cd5f0n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages