Enhanced integration between gopls (the Go language server) and Eglot (the Emacs LSP client).
eglot-gopls-demo.mp4
When eglot-codelens is available, this package adds support for the following gopls/vscode-go codelens commands:
-
gopls.run_tests- Run tests and benchmarks in a compilation buffer with error navigation- Runs specific tests via
go test -runor benchmarks viago test -bench - Output is parsed automatically, allowing
next-errorto jump to failures
- Runs specific tests via
-
go.test.cursor/go.benchmark.cursor- Run individual tests or benchmarks- Supports testify suite test methods (e.g.,
(*MySuite).TestMethod) - Supports fuzz functions
- Supports testify suite test methods (e.g.,
-
go.test.package/go.test.file- Run all tests in the current package or file- Automatically enables code coverage for package test runs
-
go.benchmark.package/go.benchmark.file- Run all benchmarks in the current package or file -
go.debug.cursor- Debug tests and benchmarks using dape- Requires dape to be installed
- Automatically registers the
go-debug-testdape adapter for seamless debugging - Supports test function debugging
-
gopls.run_govulncheck/gopls.vulncheck- Run vulnerability checking on Go dependencies
Install eglot-codelens first to enable the codelens UI.
(unless (package-installed-p 'eglot-gopls)
(package-vc-install
'(eglot-gopls :url "https://github.com/zsxh/eglot-gopls")))Download eglot-gopls.el and add it to your load-path:
(add-to-list 'load-path "/path/to/eglot-gopls")
(require 'eglot-gopls)Add the following to your Emacs configuration:
(require 'eglot-gopls)
(push '((go-mode go-dot-mod-mode go-dot-work-mode go-ts-mode go-mod-ts-mode go-work-ts-mode)
. (eglot-gopls-server . ("gopls")))
eglot-server-programs)Then enable eglot in Go buffers with M-x eglot.
For custom gopls setting, eglot config:
(setq-default eglot-workspace-configuration
'(:gopls
(:codelenses (:generate t
:regenerate_cgo t
:tidy t
:upgrade_dependency t
:vendor t
:test t
:run_govulncheck t))))To use a custom vulnerability database, set eglot-gopls-vulncheck-db
(setq eglot-gopls-vulncheck-db "https://vuln.go.dev")To pass environment variables to the debugger when debugging tests:
;; Environment variables for debugging tests
(setq eglot-gopls-test-env-vars '(:KEY "value" :ANOTHER_KEY "another_value"))To configure test coverage:
;; Directory for storing coverage profiles (default: temp-dir/eglot-gopls)
(setq eglot-gopls-test-cover-path "/path/to/coverage")
;; Coverage mode: set, count, or atomic (default: nil)
(setq eglot-gopls-test-covermode 'atomic)To set test timeout:
;; Test timeout duration (default: "30s")
(setq eglot-gopls-test-timeout "1m")To pass additional flags to go test:
;; Additional flags passed to go test and the debugger
;; Falls back to gopls.buildFlags if nil or empty
(setq eglot-gopls-test-flags '("-tags" "integration"))- Emacs 30.1+
- eglot 1.17.30+
- jsonrpc 1.0.24+
- eglot-codelens (for codelens ui)
- dape (optional, for debugging tests)
- gopls
- govulncheck (optional, for vulnerability checking)
- Support testify suite debugging
Copyright (C) 2026 Zsxh Chen
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
See LICENSE for details.
