Last active
June 23, 2022 20:48
-
-
Save psanford/b5d2689ff1565ec7e46867245e3d2c76 to your computer and use it in GitHub Desktop.
gopls (go lsp-mode) config for emacs with useful optional packages.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;;; Pre gopls/lsp-mode/go-mode setup | |
;;; This section installs use-package from melpa if it isn't | |
;;; already installed. You can skip this if you already have use-package | |
;; enable melpa if it isn't enabled | |
(require 'package) | |
(when (not (assoc "melpa" package-archives)) | |
(setq package-archives (append '(("melpa" . "https://melpa.org/packages/")) package-archives))) | |
(package-initialize) | |
;; refresh package list if it is not already available | |
(when (not package-archive-contents) (package-refresh-contents)) | |
;; install use-package if it isn't already installed | |
(when (not (package-installed-p 'use-package)) | |
(package-install 'use-package)) | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;; Install and configure pacakges | |
;; optional, provides snippets for method signature completion | |
(use-package yasnippet | |
:ensure t) | |
(use-package lsp-mode | |
:ensure t | |
;; uncomment to enable gopls http debug server | |
;; :custom (lsp-gopls-server-args '("-debug" "127.0.0.1:0")) | |
:commands (lsp lsp-deferred) | |
:config (progn | |
;; use flycheck, not flymake | |
(setq lsp-prefer-flymake nil))) | |
;; optional - provides fancy overlay information | |
(use-package lsp-ui | |
:ensure t | |
:commands lsp-ui-mode | |
:config (progn | |
;; disable inline documentation | |
(setq lsp-ui-sideline-enable nil) | |
;; disable showing docs on hover at the top of the window | |
(setq lsp-ui-doc-enable nil)) | |
) | |
(use-package company | |
:ensure t | |
:config (progn | |
;; don't add any dely before trying to complete thing being typed | |
;; the call/response to gopls is asynchronous so this should have little | |
;; to no affect on edit latency | |
(setq company-idle-delay 0) | |
;; start completing after a single character instead of 3 | |
(setq company-minimum-prefix-length 1) | |
;; align fields in completions | |
(setq company-tooltip-align-annotations t) | |
) | |
) | |
;; optional package to get the error squiggles as you edit | |
(use-package flycheck | |
:ensure t) | |
;; if you use company-mode for completion (otherwise, complete-at-point works out of the box): | |
(use-package company-lsp | |
:ensure t | |
:commands company-lsp) | |
(use-package go-mode | |
:ensure t | |
:bind ( | |
;; If you want to switch existing go-mode bindings to use lsp-mode/gopls instead | |
;; uncomment the following lines | |
;; ("C-c C-j" . lsp-find-definition) | |
;; ("C-c C-d" . lsp-describe-thing-at-point) | |
) | |
:hook ((go-mode . lsp-deferred) | |
(before-save . lsp-format-buffer) | |
(before-save . lsp-organize-imports))) | |
(provide 'gopls-config) |
I removed the set-library-path piece of the config as that is now integrated into lsp-mode.
This config is now out of date. You probably want to look at the example in the gopls docs instead: https://github.com/golang/tools/blob/master/gopls/doc/emacs.md
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think you have to set
(setq lsp-prefer-flymake nil)
to make it actually use flycheck.