Skip to content

Commit

Permalink
feat: update gopls
Browse files Browse the repository at this point in the history
  • Loading branch information
alisonjoe committed May 26, 2024
1 parent 1e19f33 commit e1f5cf1
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
41 changes: 41 additions & 0 deletions conf/.golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# .golangci.yml
run:
# timeout for the whole golangci-lint run, including linters loading, analyzing source code, etc
timeout: 10m

issues:
# Code is grouped by package for the application. If you have multiple projects inside a repository, this value can be `folder`
# You can also have issues grouped by default "none"
# Valid values are: package, folder, file
# Default is "package"
grouping: package

exclude-rules:
# Exclude some linters from all packages
- linters:
- errcheck
text: "SA4006" # exclude `SA4006` from `errcheck`

linters-settings:
govet:
check-shadowing: true

# configuration for `golint`
golint:
min-confidence: 0.8

gocyclo:
min-complexity: 10

misspell:
locale: US

linters:
disable-all: true
enable:
- govet
- golint
- gocyclo
- misspell


29 changes: 28 additions & 1 deletion lisp/init-golang-local.el
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
(eval-after-load 'flycheck
'(add-hook 'go-mode-hook #'flycheck-golangci-lint-setup))


(setq flycheck-gometalinter-vendor t)
(setq flycheck-gometalinter-enable-linters '("golangci-lint"))
(setq flycheck-gometalinter-deadline "10s")
Expand All @@ -58,8 +59,18 @@
(local-set-key (kbd "C-c s") #'alison-go-tag-add)
(local-set-key (kbd "C-c T") #'go-tag-remove)))

(defun restart-golangci-lint ()
"Restart golangci-lint."
(interactive)
(flycheck-stop)
(flycheck-buffer))

(add-hook 'go-mode-hook
(lambda ()
(local-set-key (kbd "C-c l") #'restart-golangci-lint)))

(setq gofmt-command "goimports")
(setq gofmt-args '("-local" "git.code.oa.com"))
;; (setq gofmt-args '("-local" "git.code.oa.com"))
(add-hook 'before-save-hook 'gofmt-before-save)

(setq go-test-args "-gcflags=all=-l")
Expand Down Expand Up @@ -115,6 +126,8 @@

(lsp-treemacs-sync-mode 1)

(setq lsp-log-io t)

(setq lsp-auto-guess-root t)
(setq lsp-enable-text-document-color t)

Expand All @@ -127,6 +140,20 @@

(advice-add #'company-yasnippet :around #'company-yasnippet/disable-after-dot)

(defun my-go-mode-hook ()
(add-hook 'after-save-hook 'go-mod-tidy nil 'make-it-local))

(defun go-mod-tidy ()
"Run 'go mod tidy' in the project root."
(interactive)
(when (and (string-equal major-mode 'go-mode)
(projectile-project-p))
(let ((default-directory (projectile-project-root)))
(shell-command "go mod tidy"))))

(add-hook 'go-mode-hook 'my-go-mode-hook)


(provide 'init-golang-local)
(provide 'init-lsp-mode-local)
;;; init-golang-local.el ends here
Expand Down

0 comments on commit e1f5cf1

Please sign in to comment.