### Install nvim-lspconfig plugin Source: https://go.dev/gopls/editor/vim Clone the nvim-lspconfig repository to the specified Neovim plugin directory. ```bash dir="${HOME}/.local/share/nvim/site/pack/nvim-lspconfig/opt/nvim-lspconfig/" mkdir -p "$dir" cd "$dir" git clone 'https://github.com/neovim/nvim-lspconfig.git' . ``` -------------------------------- ### Install Specific Gopls Version Source: https://go.dev/gopls/advanced Use 'go install' to get a specific version of gopls, such as a prerelease version. Replace vX.Y.Z with the desired version tag. ```bash go install golang.org/x/tools/gopls@vX.Y.Z ``` -------------------------------- ### Build Gopls from Source Source: https://go.dev/gopls/contributing Build and install a local version of gopls after applying your changes. Ensure you are in the correct directory before running the command. ```bash cd /path/to/tools/gopls go install ``` -------------------------------- ### Example of strings.TrimLeft usage Source: https://go.dev/gopls/analyzers Demonstrates how strings.TrimLeft works with a cutset. To remove a prefix, use strings.TrimPrefix instead. ```go strings.TrimLeft("42133word", "1234") ``` -------------------------------- ### Go Assembly Definition Request Example Source: https://go.dev/gopls/features/assembly Demonstrates a Definition request on the 'sigpanic' symbol in a Go assembly file, showing the jump to its declaration. ```go JMP ·sigpanic(SB) ``` ```go //go:linkname sigpanic func sigpanic() { ``` -------------------------------- ### Start Gopls Daemon Manually with Unix Domain Socket Source: https://go.dev/gopls/daemon Manually start a gopls daemon process listening on a Unix domain socket. The socket path must be enclosed in quotes due to the semicolon separator. ```bash gopls -listen="unix;/tmp/gopls-daemon-socket" -logfile=auto -debug=:0 ``` -------------------------------- ### Install Latest Stable Gopls Source: https://go.dev/gopls/index.md Use this command to install the latest stable release of Gopls. Some editors may handle this automatically. ```bash go install golang.org/x/tools/gopls@latest ``` -------------------------------- ### Set Local Import Path for Formatting Source: https://go.dev/gopls/settings Configure the 'local' setting to group imports starting with a specific prefix after third-party packages. ```go local string ``` -------------------------------- ### Install Latest Gopls Version Source: https://go.dev/gopls/features/mcp Installs the latest version of gopls using the Go toolchain. Ensure gopls v0.20 or higher is installed. ```bash $ go install golang.org/x/tools/gopls@latest ``` -------------------------------- ### Start Gopls Debug Server Source: https://go.dev/gopls/contributing Start the built-in debug server for Gopls by passing the -debug flag with a specified address. If using :0, Gopls will log the assigned address to stderr. ```bash gopls serve -debug=localhost:6060 ``` -------------------------------- ### Start Gopls Daemon Manually with TCP Source: https://go.dev/gopls/daemon Manually start a gopls daemon process listening on a specific TCP port using the `-listen` flag. This allows editors to connect to this pre-existing daemon using the `-remote` flag. ```bash gopls -listen=:37374 -logfile=auto -debug=:0 ``` -------------------------------- ### Struct Field Alignment Examples Source: https://go.dev/gopls/analyzers Illustrates how struct field ordering affects memory usage and pointer scanning by the garbage collector. ```go struct { uint32; string } ``` ```go struct { string; *uint32 } ``` ```go struct { string; uint32 } ``` -------------------------------- ### Verify Gopls Version Source: https://go.dev/gopls/contributing Check the installed gopls version to confirm that your local build is active. The output should indicate a development version. ```bash $ gopls version golang.org/x/tools/gopls master golang.org/x/tools/gopls@(devel) ``` -------------------------------- ### Configure gopls Settings Locally in Eglot Source: https://go.dev/gopls/editor/emacs Configures gopls settings for a specific project using a `.dir-locals.el` file. This example enables staticcheck and sets a case-sensitive matcher. ```emacs-lisp ((nil (eglot-workspace-configuration . ((gopls . ((staticcheck . t) (matcher . "CaseSensitive"))))))) ``` -------------------------------- ### Handling Control Flow for Nil Pointer Checks Source: https://go.dev/gopls/analyzers This example illustrates a scenario where static analysis might incorrectly flag a safe dereference due to a lack of understanding of control flow exit functions like `os.Exit`. The workaround involves adding a `panic` to ensure the function exits. ```go func Log(msg string, level int) { fmt.Println(msg) if level == levelFatal { os.Exit(1) } } func Fatal(msg string) { Log(msg, levelFatal) } func fn(x *int) { if x == nil { Fatal("unexpected nil pointer") } fmt.Println(*x) } ``` ```go func Fatal(msg string) { Log(msg, levelFatal) panic("unreachable") } ``` -------------------------------- ### Run Gopls with Automatic Daemon Management Source: https://go.dev/gopls/daemon Use the `-remote=auto` flag to have gopls automatically start and connect to a shared daemon process if one is not already running. This is the simplest way to enable daemon mode. The shared process will shut down after one minute of inactivity. ```bash gopls -remote=auto -logfile=auto -debug=:0 -remote.debug=:0 -rpc.trace ``` -------------------------------- ### Initialize and Use Multi-Module Workspaces with go.work Source: https://go.dev/gopls/workspace Use this command sequence to initialize a go.work file and specify the modules to include in your workspace. This is useful for simultaneously developing multiple modules that depend on each other. ```bash cd $WORK go work init go work use tools/gopls mod ``` -------------------------------- ### Basic Neovim LSP Configuration for Gopls Source: https://go.dev/gopls/editor/vim Set up the native LSP client in Neovim to use gopls with default settings. ```lua local lspconfig = require("lspconfig") lspconfig.gopls.setup({}) ``` -------------------------------- ### Enable Experimental Postfix Completions Source: https://go.dev/gopls/settings Enable 'experimentalPostfixCompletions' to use artificial method snippets like 'someSlice.sort!'. ```go experimentalPostfixCompletions bool ``` -------------------------------- ### Install Latest Unstable Gopls Version Source: https://go.dev/gopls/advanced Update gopls to the latest unstable version by initializing a temporary module, adding master requirements, and then installing. This ensures compatibility between gopls and the Go toolchain. ```bash # Create an empty go.mod file, only for tracking requirements. cd $(mktemp -d) go mod init gopls-unstable # Use 'go get' to add requirements and to ensure they work together. go get -d golang.org/x/tools/gopls@master golang.org/x/tools@master go install golang.org/x/tools/gopls ``` -------------------------------- ### Enable gofumpt Formatting Source: https://go.dev/gopls/settings Set the 'gofumpt' option to true to enable gofumpt formatting. ```go gofumpt bool ``` -------------------------------- ### Initialize Go Work File for Std and Cmd Source: https://go.dev/gopls/advanced When working on the Go project, use 'go work init' within the GOROOT/src directory to manage simultaneous work on the 'std' and 'cmd' components. This requires the Go command to match the source version. ```bash cd $(go env GOROOT)/src go work init . cmd ``` -------------------------------- ### Configure LanguageClient-neovim for Gopls Source: https://go.dev/gopls/editor/vim Launch gopls when Go files are in use and configure gofmt to run on save. ```vimscript " Launch gopls when Go files are in use let g:LanguageClient_serverCommands = { \ "go": ['gopls'] \ } " Run gofmt on save autocmd BufWritePre *.go :call LanguageClient#textDocument_formatting_sync() ``` -------------------------------- ### Set Completion Budget Source: https://go.dev/gopls/settings Configure the 'completionBudget' for debugging latency goals in completion requests. Zero means unlimited. ```go completionBudget time.Duration ``` -------------------------------- ### Enable New Go File Header Source: https://go.dev/gopls/settings Enable 'newGoFileHeader' to automatically insert copyright comments and package declarations in new Go files. ```go newGoFileHeader bool ``` -------------------------------- ### Set Completion Matcher Algorithm Source: https://go.dev/gopls/settings Choose the 'matcher' algorithm for calculating completion candidates. Options include CaseInsensitive, CaseSensitive, and Fuzzy. ```go matcher enum ``` -------------------------------- ### Run Gopls MCP Server in Detached Mode Source: https://go.dev/gopls/features/mcp Starts the MCP server in detached mode as a standalone gopls instance communicating over stdin/stdout. ```bash gopls mcp ``` -------------------------------- ### Global LSP Settings with Specific Paths and Options Source: https://go.dev/gopls/editor/sublime Configure global LSP settings to specify the exact PATH for gopls and go executables. Includes options to enable debug logging and control completion behavior. ```json { "clients": { "gopls": { "enabled": true, "env": { "PATH": "/path/to/your/go/bin", } } }, "show_references_in_quick_panel": true, "log_debug": true, "inhibit_snippet_completions": true, "inhibit_word_completions": true, } ``` -------------------------------- ### Unused Write to Struct Field Example Source: https://go.dev/gopls/analyzers This snippet demonstrates an unused write to a struct field within a loop where the loop variable is a copy. ```go type T struct { x int } func f(input []T) { for i, v := range input { // v is a copy v.x = i // unused write to field x } } ``` -------------------------------- ### Simplify composite literals Source: https://go.dev/gopls/analyzers Simplifies array, slice, or map composite literals. For example, []T{T{}, T{}} becomes []T{{}, {}}. This is a simplification also applied by 'gofmt -s'. ```go []T{T{}, T{}} ``` ```go []T{{}, {}} ``` -------------------------------- ### Handle Duplicate Package Imports Source: https://go.dev/gopls/analyzers Demonstrates how Go allows importing the same package multiple times with different aliases. This is often a refactoring artifact and can be disabled if intentional. ```go import ( "fmt" fumpt "fmt" format "fmt" ) ``` -------------------------------- ### Report Fatal Calls from Non-Test Goroutines Source: https://go.dev/gopls/analyzers Detects calls to *testing.T.Fatal and similar methods from goroutines not started by the test itself. These functions must be called from the test goroutine. ```go func TestFoo(t *testing.T) { go func() { t.Fatal("oops") // error: (*T).Fatal called from non-test goroutine }() } ``` -------------------------------- ### Use bytes.Buffer.String or bytes.Buffer.Bytes Source: https://go.dev/gopls/analyzers Prefer using bytes.Buffer.String() or bytes.Buffer.Bytes() directly over type conversions like string(buf.Bytes()) or []byte(buf.String()). ```go string(buf.Bytes()) ``` ```go []byte(buf.String()) ``` -------------------------------- ### Unused Write to Struct Field with Non-Pointer Receiver Example Source: https://go.dev/gopls/analyzers This snippet illustrates an unused write to a struct field when using a non-pointer receiver, where the receiver is a copy. ```go type T struct { x int } func (t T) f() { // t is a copy t.x = i // unused write to field x } ``` -------------------------------- ### Configure gopls Settings Globally in Eglot Source: https://go.dev/gopls/editor/emacs Sets default workspace configurations for gopls globally in Emacs. This example enables staticcheck and sets a case-sensitive matcher. ```emacs-lisp (setq-default eglot-workspace-configuration '((:gopls . ((staticcheck . t) (matcher . "CaseSensitive"))))) ``` -------------------------------- ### Configure Emacs for Legacy Import Organization and Formatting Source: https://go.dev/gopls/features/transformation Set up Emacs with go-mode to use the 'goimports' tool for organizing imports and formatting files before saving. This is a legacy approach that predates full LSP integration for these tasks. ```emacs lisp (setq gofmt-command "goimports") (add-hook 'before-save-hook 'gofmt-before-save) ``` -------------------------------- ### Configure Standalone Build Tags Source: https://go.dev/gopls/settings Specify 'standaloneTags' for build constraints identifying individual Go source files that form an entire main package. ```go standaloneTags []string ``` -------------------------------- ### Omit Comparison with Boolean Constant (Go) Source: https://go.dev/gopls/analyzers Removes redundant comparisons of a boolean variable with `true` or `false` in conditional statements. For example, `if x == true` can be simplified to `if x`. ```go if x == true {} ``` ```go if x {} ``` -------------------------------- ### Configure coc.nvim for Gopls Source: https://go.dev/gopls/editor/vim Set up gopls as a language server in coc.nvim, including root patterns and filetypes. ```json "languageserver": { "go": { "command": "gopls", "rootPatterns": ["go.work", "go.mod", ".vim/", ".git/", ".hg/"], "filetypes": ["go"], "initializationOptions": { "usePlaceholders": true } } } ``` -------------------------------- ### Compile Error due to Unspecified Constant Type in Go Source: https://go.dev/gopls/analyzers This example demonstrates a compile error that occurs when constants in a group have differing implicit types, leading to a type mismatch during assignment. ```Go package pkg const ( EnumFirst uint8 = 1 EnumSecond = 2 ) func fn(useFirst bool) { x := EnumSecond if useFirst { x = EnumFirst } } ``` -------------------------------- ### Run Gopls MCP Server in Attached Mode Source: https://go.dev/gopls/features/mcp Starts the MCP server in attached mode, sharing memory with an active gopls LSP session. It uses Server-Sent Events (SSE) transport. ```bash gopls serve -mcp.listen=localhost:8092 ``` -------------------------------- ### Configure vim-lsp for Gopls Source: https://go.dev/gopls/editor/vim Register gopls as a language server and set omnifunc for Go files. ```vimscript augroup LspGo au! autocmd User lsp_setup call lsp#register_server({ \ 'name': 'gopls', \ 'cmd': {server_info->['gopls']}, \ 'whitelist': ['go'], \ }) autocmd FileType go setlocal omnifunc=lsp#complete "autocmd FileType go nmap gd (lsp-definition) "autocmd FileType go nmap ,n (lsp-next-error) "autocmd FileType go nmap ,p (lsp-previous-error) augroup END ``` -------------------------------- ### Run Go Tests with Short Flag Source: https://go.dev/gopls/contributing Use this command to run Go tests, skipping slower ones. It's the standard command for testing after changes. ```bash gopls$ go test -short ./... ``` -------------------------------- ### Method Set Issue with Unspecified Constant Type in Go Source: https://go.dev/gopls/analyzers This example illustrates how an unspecified type for a constant can lead to a loss of method sets, causing unexpected output when methods are associated with the intended type. ```Go package main import "fmt" type Enum int func (e Enum) String() string { return "an enum" } const ( EnumFirst Enum = 1 EnumSecond = 2 ) func main() { fmt.Println(EnumFirst) fmt.Println(EnumSecond) } ``` -------------------------------- ### Detect WaitGroup misuse: Add in new goroutine Source: https://go.dev/gopls/analyzers This analyzer detects mistaken calls to (*sync.WaitGroup).Add from inside a new goroutine, which can cause Add to race with Wait. The correct code calls Add before starting the goroutine. ```go var wg sync.WaitGroup go func() { wg.Add(1) // "WaitGroup.Add called from inside new goroutine" defer wg.Done() ... }() wg.Wait() // (may return prematurely before new goroutine starts) ``` ```go var wg sync.WaitGroup wg.Add(1) go func() { defer wg.Done() ... }() wg.Wait() ``` -------------------------------- ### Configure Symbol Style for Workspace Symbols Source: https://go.dev/gopls/settings Sets the algorithm for finding workspace symbols. Use 'Dynamic' to qualify symbols based on the best match. ```json { "gopls": { ... "symbolStyle": "Dynamic", ... } } ``` -------------------------------- ### Goroutine Loop Variable Capture (Pre Go 1.22) Source: https://go.dev/gopls/analyzers This example demonstrates loop variable capture with goroutines, which can lead to incorrect behavior and data races. The loop variable 'v' is accessed concurrently by multiple goroutines. ```go for _, v := range elem { go func() { use(v) // incorrect, and a data race }() } ``` -------------------------------- ### Configure Workspace Files Globs Source: https://go.dev/gopls/settings Define 'workspaceFiles' globs to match files that define the logical build of the workspace. Changes trigger a workspace reload. ```go workspaceFiles []string ``` -------------------------------- ### Loop Variable Capture in Closures (Pre Go 1.22) Source: https://go.dev/gopls/analyzers This example shows a common issue where deferred functions capture the loop variable, observing its final value after the loop completes. This is incorrect in Go versions prior to 1.22. ```go for _, v := range list { defer func() { use(v) // incorrect }() } ``` -------------------------------- ### Format a Go file using Gopls CLI Source: https://go.dev/gopls/features/transformation Demonstrates how to format a specific Go file using the gopls command-line interface. This command applies Go's canonical formatting algorithm to the specified file. ```bash gopls format file.go ``` -------------------------------- ### Print MCP Model Instructions Source: https://go.dev/gopls/features/mcp Outputs the model instructions for using gopls MCP tools to a specified file. This is useful for providing context to AI assistants. ```bash gopls mcp -instructions > /path/to/contextFile.md ``` -------------------------------- ### Connect Editor to Manually Managed Gopls Daemon via TCP Source: https://go.dev/gopls/daemon Configure your editor's gopls process to connect to a manually managed daemon by specifying the daemon's address with the `-remote` flag. This example connects to a daemon listening on TCP port 37374. ```bash gopls -remote=:37374 -logfile=auto -debug=:0 -rpc.trace ``` -------------------------------- ### Show Constant Values Source: https://go.dev/gopls/inlayHints Enables inlay hints for constant values, particularly useful with iota. Disabled by default, enable with "hints": {"constantValues": true}. ```go const ( KindNone Kind = iota/* = 0*/ KindPrint/* = 1*/ KindPrintf/* = 2*/ KindErrorf/* = 3*/ ) ``` -------------------------------- ### Simplify range statements Source: https://go.dev/gopls/analyzers Simplifies range statements by removing unnecessary variables. For example, 'for x, _ = range v' becomes 'for x = range v', and 'for _ = range v' becomes 'for range v'. This is a simplification also applied by 'gofmt -s'. ```go for x, _ = range v {...} ``` ```go for x = range v {...} ``` ```go for _ = range v {...} ``` ```go for range v {...} ``` -------------------------------- ### Use sort.Ints, sort.Float64s, and sort.Strings Source: https://go.dev/gopls/analyzers Prefer the specialized sort functions like sort.Strings(x) over the more verbose sort.Sort(sort.StringSlice(x)). ```go sort.Sort(sort.StringSlice(x)) ``` ```go sort.Strings(x) ``` -------------------------------- ### Minimal Global LSP Settings for Gopls Source: https://go.dev/gopls/editor/sublime Use this minimal configuration if gopls and go are already in your Sublime Text environment's PATH. Ensure 'gopls' is correctly identified. ```json { "clients": { "gopls": { "enabled": true, } } } ``` -------------------------------- ### Advanced Neovim LSP Configuration for Gopls Source: https://go.dev/gopls/editor/vim Configure gopls with specific analyses like unusedparams, staticcheck, and gofumpt in Neovim. ```lua local lspconfig = require("lspconfig") lspconfig.gopls.setup({ settings = { gopls = { analyses = { unusedparams = true, }, staticcheck = true, gofumpt = true, }, }, }) ``` -------------------------------- ### Execute command with shell arguments Source: https://go.dev/gopls/analyzers When running commands that require shell features like pipes or redirection, use '/bin/sh' with the '-c' flag. This ensures proper shell interpretation of the command string. ```go exec.Command("/bin/sh", "-c", "ls | grep Awesome") ``` -------------------------------- ### Run Jaeger All-in-One for Local Tracing Source: https://go.dev/gopls/contributing Run a local Jaeger instance using Podman to view traces. This command exposes the necessary ports for Jaeger's UI and OpenTelemetry collector. ```bash $ podman run --rm --name jaeger \ -p 16686:16686 \ -p 4318:4318 \ jaegertracing/all-in-one:1.76.0 ``` -------------------------------- ### Enable ST1020 Analyzer Source: https://go.dev/gopls/analyzers To enable the ST1020 analyzer, which checks documentation for exported functions, set "analyses": {"ST1020": true} in your configuration. ```json { "analyses": { "ST1020": true } } ``` -------------------------------- ### Replace x.Sub(time.Now()) with time.Until(x) Source: https://go.dev/gopls/analyzers Use time.Until(x) for a more readable alternative to x.Sub(time.Now()). ```go x.Sub(time.Now()) ``` ```go time.Until(x) ``` -------------------------------- ### Load LSP Mode and Configure Save Hooks in Emacs Source: https://go.dev/gopls/editor/emacs Loads LSP Mode and sets up before-save hooks for formatting and organizing imports in Go files. Ensure no other gofmt/goimports hooks are active. ```emacs-lisp (require 'lsp-mode) (add-hook 'go-mode-hook #'lsp-deferred) ;; Set up before-save hooks to format buffer and add/delete imports. ;; Make sure you don't have other gofmt/goimports hooks enabled. (defun lsp-go-install-save-hooks () (add-hook 'before-save-hook #'lsp-format-buffer t t) (add-hook 'before-save-hook #'lsp-organize-imports t t)) (add-hook 'go-mode-hook #'lsp-go-install-save-hooks) ``` -------------------------------- ### CLI for Document Highlight Source: https://go.dev/gopls/features/passive This command-line interface can be used to trigger document highlighting for a specific file and range. ```bash gopls signature file.go:#start-#end ``` -------------------------------- ### Direct command execution without shell Source: https://go.dev/gopls/analyzers For simple command execution without shell features, pass the command and its arguments directly to exec.Command. This avoids unnecessary shell overhead and potential security risks. ```go exec.Command("ls", "/", "/tmp") ``` -------------------------------- ### Use defer for Mutex Unlock Source: https://go.dev/gopls/analyzers Recommends using `defer mu.Unlock()` immediately after `mu.Lock()` to prevent deadlocks and ensure unlocks. ```go mu.Lock() deffer mu.Unlock() ``` -------------------------------- ### Configure vim-lsc for Gopls Source: https://go.dev/gopls/editor/vim Set up gopls as a language server command for vim-lsc, including logging configurations. ```vimscript let g:lsc_server_commands = { \ "go": { \ "command": "gopls serve", \ "log_level": -1, \ "suppress_stderr": v:true, \ }, \} ``` -------------------------------- ### Use context.TODO for nil contexts Source: https://go.dev/gopls/analyzers Passing a nil context.Context to functions can lead to unexpected behavior. It is recommended to use context.TODO() as a placeholder when a valid context is not available. ```go context.TODO() ``` -------------------------------- ### Organize Imports using Gopls CLI Source: https://go.dev/gopls/features/transformation Shows how to organize imports for a Go file using the gopls CLI. This command can fix imports, remove unused ones, and sort them according to Go conventions. ```bash gopls fix -a file.go:#offset source.organizeImports ``` -------------------------------- ### Emit Gemini CLI Model Instructions Source: https://go.dev/gopls/features/mcp Generates model instructions for Gemini CLI and saves them to the specified GEMINI.md file within the extension directory. ```bash $ gopls mcp -instructions > ~/.gemini/extensions/go/GEMINI.md ``` -------------------------------- ### Enable Rename to Move Subpackages Source: https://go.dev/gopls/settings Enable 'renameMovesSubpackages' to allow Rename operations to move subdirectories of the target package. ```go renameMovesSubpackages bool ``` -------------------------------- ### Expand Call to math.Pow (Go) Source: https://go.dev/gopls/analyzers Simplifies calls to `math.Pow(x, 2)` by replacing them with direct multiplication `x * x`. This is applicable when the exponent is a constant 2. ```go math.Pow(x, 2) ``` ```go x * x ``` -------------------------------- ### Enable Parameter Name Inlay Hints in VS Code Source: https://go.dev/gopls/features/passive This JSON configuration snippet enables parameter name inlay hints within VS Code settings. It is part of the broader `hints` configuration for gopls. ```json "hints": {"parameterNames": true} ``` -------------------------------- ### Load Eglot and Configure Save Hooks in Emacs Source: https://go.dev/gopls/editor/emacs Loads Eglot and integrates it with go-mode, optionally setting up a before-save hook for buffer formatting. Ensure other formatting hooks are managed to avoid conflicts. ```emacs-lisp ;; Optional: load other packages before eglot to enable eglot integrations. (require 'company) (require 'yasnippet) (require 'go-mode) (require 'eglot) (add-hook 'go-mode-hook 'eglot-ensure) ;; Optional: install eglot-format-buffer as a save hook. ;; The depth of -10 places this before eglot's willSave notification, ;; so that notification reports the actual contents that will be saved. (defun eglot-format-buffer-before-save () (add-hook 'before-save-hook #'eglot-format-buffer -10 t)) (add-hook 'go-mode-hook #'eglot-format-buffer-before-save) ``` -------------------------------- ### Configure coc.nvim for Auto-Formatting on Save Source: https://go.dev/gopls/editor/vim Automatically run code actions for organizing imports on file save using coc.nvim. ```vimscript autocmd BufWritePre *.go :call CocAction('runCommand', 'editor.action.organizeImport') ``` -------------------------------- ### Simplify error construction with fmt.Errorf Source: https://go.dev/gopls/analyzers Use fmt.Errorf directly for constructing errors instead of combining errors.New with fmt.Sprintf. ```go errors.New(fmt.Sprintf(...)) ``` ```go fmt.Errorf(...) ``` -------------------------------- ### Configure vim-go for Gopls Source: https://go.dev/gopls/editor/vim Set the definition and info modes to 'gopls' in vim-go for Go development. ```vimscript let g:go_def_mode='gopls' let g:go_info_mode='gopls' ``` -------------------------------- ### Connect Editor to Manually Managed Gopls Daemon via Unix Domain Socket Source: https://go.dev/gopls/daemon Configure your editor's gopls process to connect to a manually managed daemon using a Unix domain socket. The socket path must be enclosed in quotes. ```bash gopls -remote="unix;/tmp/gopls-daemon-socket" -logfile=auto -debug=:0 -rpc.trace ``` -------------------------------- ### Enable ST1021 Analyzer Source: https://go.dev/gopls/analyzers To enable the ST1021 analyzer, which checks documentation for exported types, set "analyses": {"ST1021": true} in your configuration. ```json { "analyses": { "ST1021": true } } ```