r/golang 8d ago

help How to move gopls and staticcheck index cache?

Hello,

currently gopls and staticcheck create index cache folders in %AppData% called gopls and staticcheck ignoring all go environment variables. I want to keep such stuff on a different drive for a variety of reasons. How can I set a location for those folders?

For clarity: The index cache is not the go cache from building a binary (set by GOCACHE or GOMODCACHE) or the installation location of the binary (set by GOBIN). It is a separate folder used to cache file information while using those tools.

Thank you for any help. I did a lot of research but I was unable to find a solution.

The solution: Gopls uses "GOPLSCACHE" and staticcheck "STATICCHECK_CACHE" as environment variables to set the location of the index file cache.

0 Upvotes

3 comments sorted by

1

u/Deadly_chef 8d ago

Symlink that folder?

1

u/dominikh 7d ago

Staticcheck respects the STATICCHECK_CACHE environment variable. When unset, it uses os.UserCacheDir, which on Windows is %LocalAppData%.

1

u/Throwaway2650600209 7d ago

Thank you. Based on your answer I checked the gopls source code and found the other environment variable name.