Skip to content

zsxh/eglot-gopls

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

eglot-gopls

License

Enhanced integration between gopls (the Go language server) and Eglot (the Emacs LSP client).

Screenshot

eglot-gopls-demo.mp4

Features

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 -run or benchmarks via go test -bench
    • Output is parsed automatically, allowing next-error to jump to failures
  • go.test.cursor / go.benchmark.cursor - Run individual tests or benchmarks

    • Supports testify suite test methods (e.g., (*MySuite).TestMethod)
    • Supports fuzz functions
  • 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-test dape adapter for seamless debugging
    • Supports test function debugging
  • gopls.run_govulncheck / gopls.vulncheck - Run vulnerability checking on Go dependencies

Installation

Install eglot-codelens first to enable the codelens UI.

Using package-vc

(unless (package-installed-p 'eglot-gopls)
  (package-vc-install
   '(eglot-gopls :url "https://github.com/zsxh/eglot-gopls")))

Manual installation

Download eglot-gopls.el and add it to your load-path:

(add-to-list 'load-path "/path/to/eglot-gopls")
(require 'eglot-gopls)

Usage

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.

Advanced Configuration

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"))

Requirements

TODOs

  • Support testify suite debugging

License

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.

About

gopls integration with eglot

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors