Skip to content

Commit 3a5fec8

Browse files
feat: Add support for Trunk (#4293)
* Add trunk-lsp client to lsp-mode Trunk is a meta-linter designed to offer a single interface for managing and running over 100 linters and formatters. This lsp-mode client attempts to provide a similar experience to the official Trunk VSCode extension. See https://docs.trunk.io/check for more info. * address styling comment --------- Co-authored-by: Jen-Chieh Shen <[email protected]>
1 parent c704948 commit 3a5fec8

File tree

5 files changed

+100
-1
lines changed

5 files changed

+100
-1
lines changed

CHANGELOG.org

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
* Add support for clojure-ts derived modes.
111111
* Add support for installing Ada Language Server.
112112
* Add Nushell support
113+
* Add [[https://docs.trunk.io][Trunk]] support
113114

114115
** Release 8.0.0
115116
* Add ~lsp-clients-angular-node-get-prefix-command~ to get the Angular server from another location which is still has ~/lib/node_modules~ in it.

clients/lsp-trunk.el

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
;;; lsp-trunk.el --- trunk support -*- lexical-binding: t; -*-
2+
;;
3+
;; Copyright (C) 2024 Trunk Technologies, Inc.
4+
;;
5+
;; Author: Tyler Jang <[email protected]>
6+
;; Keywords: trunk, lsp, meta-linter
7+
;;
8+
;; This program is free software; you can redistribute it and/or modify
9+
;; it under the terms of the GNU General Public License as published by
10+
;; the Free Software Foundation, either version 3 of the License, or
11+
;; (at your option) any later version.
12+
;;
13+
;; This program is distributed in the hope that it will be useful,
14+
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
;; GNU General Public License for more details.
17+
;;
18+
;; You should have received a copy of the GNU General Public License
19+
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
20+
;; This file is not part of GNU Emacs.
21+
;;
22+
;;; Commentary:
23+
;;
24+
;; Trunk support for lsp-mode
25+
;;
26+
;;; Code:
27+
28+
(require 'lsp-mode)
29+
30+
(defgroup lsp-trunk nil
31+
"LSP support for Trunk."
32+
:group 'lsp-mode
33+
:link `(url-link "https://docs.trunk.io"))
34+
35+
(defcustom lsp-trunk-executable "trunk"
36+
"Path to the trunk executable"
37+
:group 'lsp-trunk
38+
:type 'string)
39+
40+
(defcustom lsp-trunk-args '("lsp-proxy")
41+
"Additional arguments to pass to the trunk startup"
42+
:group 'lsp-trunk
43+
:type '(repeat string))
44+
45+
(defun lsp-trunk-check-for-init (filename &optional _)
46+
"Check if the file exists in a workspace that has a .trunk/trunk.yaml"
47+
(let ((dir (file-name-directory filename))
48+
(trunk-file ".trunk/trunk.yaml"))
49+
(locate-dominating-file dir trunk-file)))
50+
51+
(defun lsp-trunk-check-disable (command)
52+
"Disable a linter in your repo."
53+
(shell-command
54+
(concat lsp-trunk-executable " check disable "
55+
(mapconcat 'identity (gethash "arguments" command) " "))))
56+
57+
(defun lsp-trunk-check-enable (command)
58+
"Enable a linter in your repo."
59+
(shell-command
60+
(concat lsp-trunk-executable " check enable "
61+
(mapconcat 'identity (gethash "arguments" command) " "))))
62+
63+
(defun lsp-trunk-open-config (&optional _command)
64+
"Open the trunk config file."
65+
(find-file ".trunk/trunk.yaml"))
66+
67+
(lsp-register-client
68+
(make-lsp-client
69+
:activation-fn #'lsp-trunk-check-for-init
70+
:new-connection (lsp-stdio-connection
71+
(lambda () (append (list lsp-trunk-executable) lsp-trunk-args)))
72+
:server-id 'trunk-lsp
73+
:initialization-options (lambda ()
74+
(list
75+
:version "0.1.0"
76+
:clientType "emacs"
77+
:clientVersion (symbol-value 'emacs-version)))
78+
:notification-handlers (ht ("$/progress" #'ignore))
79+
:action-handlers (ht ("trunk.checkDisable" #'lsp-trunk-check-disable)
80+
("trunk.checkEnable" #'lsp-trunk-check-enable)
81+
("trunk.openConfigFile" #'lsp-trunk-open-config))
82+
:priority -2
83+
:add-on? t))
84+
85+
(lsp-consistency-check lsp-trunk)
86+
87+
(provide 'lsp-trunk)
88+
;;; lsp-trunk.el ends here

docs/lsp-clients.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,6 +1066,15 @@
10661066
"installation": "cargo install taplo-cli --features lsp",
10671067
"debugger": "Not available"
10681068
},
1069+
{
1070+
"name": "trunk",
1071+
"full-name": "Trunk",
1072+
"server-name": "trunk-lsp",
1073+
"server-url": "https://docs.trunk.io",
1074+
"installation": "curl https://get.trunk.io -fsSL | bash -s -- -y; trunk init",
1075+
"installation-url": "https://docs.trunk.io/check",
1076+
"debugger": "Not available"
1077+
},
10691078
{
10701079
"name": "typeprof",
10711080
"full-name": "Ruby (TypeProf)",

lsp-mode.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ As defined by the Language Server Protocol 3.16."
190190
lsp-sonarlint lsp-tailwindcss lsp-tex lsp-terraform lsp-toml lsp-ttcn3
191191
lsp-typeprof lsp-v lsp-vala lsp-verilog lsp-vetur lsp-volar lsp-vhdl
192192
lsp-vimscript lsp-xml lsp-yaml lsp-ruby-lsp lsp-ruby-syntax-tree
193-
lsp-solidity lsp-sqls lsp-svelte lsp-steep lsp-tilt lsp-zig lsp-jq)
193+
lsp-solidity lsp-sqls lsp-svelte lsp-steep lsp-tilt lsp-trunk lsp-zig lsp-jq)
194194
"List of the clients to be automatically required."
195195
:group 'lsp-mode
196196
:type '(repeat symbol))

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ nav:
160160
- TeX, LaTeX, etc (texlab, external): page/lsp-latex.md
161161
- Tilt: page/lsp-tilt.md
162162
- TOML: page/lsp-toml.md
163+
- Trunk: page/lsp-trunk.md
163164
- TTCN3: page/lsp-ttcn3.md
164165
- V: page/lsp-v.md
165166
- Vala: page/lsp-vala.md

0 commit comments

Comments
 (0)