Skip to content

Commit 2f73f61

Browse files
authored
Fix compatibility with golangci-lint version 2+ (#4810)
From: https://github.com/nametake/golangci-lint-langserver/tree/main?tab=readme-ov-file#golangci-lint-version-compatibility - For golangci-lint v2+: Use `--output.json.path stdout --show-stats=false` parameters - For golangci-lint v1: Use `--out-format json` parameter
1 parent ab3cca2 commit 2f73f61

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

clients/lsp-golangci-lint.el

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,25 @@
142142
(setq args (append args lsp-golangci-lint-run-args)))
143143
args))
144144

145+
(defun lsp-golangci-lint--get-version ()
146+
"Get the version of golangci-lint."
147+
(with-temp-buffer
148+
(when (= 0 (call-process lsp-golangci-lint-path nil t nil "version"))
149+
(goto-char (point-min))
150+
(when (re-search-forward "has version \\([0-9]+\\)\\." nil t)
151+
(string-to-number (match-string 1))))))
152+
145153
(defun lsp-golangci-lint--get-initialization-options ()
146154
"Return initialization options for golangci-lint-langserver."
147-
(let ((opts (make-hash-table :test 'equal))
148-
(command (vconcat `(,lsp-golangci-lint-path)
149-
["run" "--out-format=json" "--issues-exit-code=1"]
155+
(let* ((opts (make-hash-table :test 'equal))
156+
(version (lsp-golangci-lint--get-version))
157+
(format-args (if (and version (>= version 2))
158+
["--output.json.path" "stdout" "--show-stats=false"]
159+
["--out-format" "json"]))
160+
(command (vconcat `(,lsp-golangci-lint-path)
161+
["run"]
162+
format-args
163+
["--issues-exit-code=1"]
150164
(lsp-golangci-lint--run-args))))
151165
(puthash "command" command opts)
152166
opts))

0 commit comments

Comments
 (0)