summaryrefslogtreecommitdiff
path: root/modules/prog-go.el
diff options
context:
space:
mode:
Diffstat (limited to 'modules/prog-go.el')
-rw-r--r--modules/prog-go.el51
1 files changed, 49 insertions, 2 deletions
diff --git a/modules/prog-go.el b/modules/prog-go.el
index 0e56e5d0..1526698e 100644
--- a/modules/prog-go.el
+++ b/modules/prog-go.el
@@ -5,9 +5,17 @@
;; Configuration for Go programming using go-ts-mode (tree-sitter based).
;; Requires go-mode package for gofmt and related commands.
;;
-;; Tools installation:
+;; Installation:
;; go install golang.org/x/tools/cmd/goimports@latest
+;; go install golang.org/x/tools/gopls@latest
;; go install honnef.co/go/tools/cmd/staticcheck@latest
+;;
+;; LSP will provide:
+;; - Intelligent code completion
+;; - Jump to definition (M-.)
+;; - Find references
+;; - On-the-fly error checking
+;; - Code lenses (run tests, show package stats)
;;; Code:
@@ -15,9 +23,23 @@
"Path to Go binaries directory.
This is where tools like goimports and staticcheck are installed.")
+(defvar gopls-path "gopls"
+ "Path to gopls (Go language server).
+Install with: go install golang.org/x/tools/gopls@latest")
+
(defvar go-ts-mode-map)
(defvar go-mod-ts-mode-map)
+;; Forward declarations for LSP
+(declare-function lsp-deferred "lsp-mode")
+(defvar lsp-go-gopls-server-path)
+(defvar lsp-go-analyses)
+(defvar lsp-go-codelenses)
+
+;; Forward declarations for external packages
+(declare-function company-mode "company")
+(defvar gofmt-command)
+
;; ---------------------------------- Go Setup ---------------------------------
;; golang preferences following Go community standards
@@ -27,7 +49,12 @@ This is where tools like goimports and staticcheck are installed.")
(setq-local tab-width 4) ;; Go standard tab width
(setq-local standard-indent 4) ;; indent 4 spaces per level
(setq-local indent-tabs-mode t) ;; use real tabs (Go convention)
- (electric-pair-mode t)) ;; match delimiters automatically
+ (electric-pair-mode t) ;; match delimiters automatically
+
+ ;; Enable LSP if available
+ (when (and (fboundp 'lsp-deferred)
+ (executable-find gopls-path))
+ (lsp-deferred)))
(defun cj/go-staticcheck ()
"Run staticcheck on the current Go package."
@@ -58,5 +85,25 @@ This is where tools like goimports and staticcheck are installed.")
;; Use goimports for formatting (adds/removes imports automatically)
(setq gofmt-command "goimports"))
+;; -------------------------------- LSP for Go ---------------------------------
+;; Go-specific LSP configuration using gopls
+;; Core LSP setup is in prog-general.el
+
+(use-package lsp-mode
+ :hook ((go-ts-mode go-mod-ts-mode) . lsp-deferred)
+ :config
+ (setq lsp-go-gopls-server-path gopls-path)
+
+ ;; Configure gopls
+ (setq lsp-go-analyses '((shadow . t)
+ (simplifycompositelit . :json-false)))
+ (setq lsp-go-codelenses '((gc_details . t)
+ (generate . t)
+ (regenerate_cgo . t)
+ (test . t)
+ (tidy . t)
+ (upgrade_dependency . t)
+ (vendor . t))))
+
(provide 'prog-go)
;;; prog-go.el ends here