Skip to content

Commit

Permalink
feat: Add support for Trunk (#4293)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
TylerJang27 and jcs090218 authored Mar 17, 2024
1 parent c704948 commit 3a5fec8
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.org
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
* Add support for clojure-ts derived modes.
* Add support for installing Ada Language Server.
* Add Nushell support
* Add [[https://docs.trunk.io][Trunk]] support

** Release 8.0.0
* 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.
Expand Down
88 changes: 88 additions & 0 deletions clients/lsp-trunk.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
;;; lsp-trunk.el --- trunk support -*- lexical-binding: t; -*-
;;
;; Copyright (C) 2024 Trunk Technologies, Inc.
;;
;; Author: Tyler Jang <[email protected]>
;; Keywords: trunk, lsp, meta-linter
;;
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
;; This file is not part of GNU Emacs.
;;
;;; Commentary:
;;
;; Trunk support for lsp-mode
;;
;;; Code:

(require 'lsp-mode)

(defgroup lsp-trunk nil
"LSP support for Trunk."
:group 'lsp-mode
:link `(url-link "https://docs.trunk.io"))

(defcustom lsp-trunk-executable "trunk"
"Path to the trunk executable"
:group 'lsp-trunk
:type 'string)

(defcustom lsp-trunk-args '("lsp-proxy")
"Additional arguments to pass to the trunk startup"
:group 'lsp-trunk
:type '(repeat string))

(defun lsp-trunk-check-for-init (filename &optional _)
"Check if the file exists in a workspace that has a .trunk/trunk.yaml"
(let ((dir (file-name-directory filename))
(trunk-file ".trunk/trunk.yaml"))
(locate-dominating-file dir trunk-file)))

(defun lsp-trunk-check-disable (command)
"Disable a linter in your repo."
(shell-command
(concat lsp-trunk-executable " check disable "
(mapconcat 'identity (gethash "arguments" command) " "))))

(defun lsp-trunk-check-enable (command)
"Enable a linter in your repo."
(shell-command
(concat lsp-trunk-executable " check enable "
(mapconcat 'identity (gethash "arguments" command) " "))))

(defun lsp-trunk-open-config (&optional _command)
"Open the trunk config file."
(find-file ".trunk/trunk.yaml"))

(lsp-register-client
(make-lsp-client
:activation-fn #'lsp-trunk-check-for-init
:new-connection (lsp-stdio-connection
(lambda () (append (list lsp-trunk-executable) lsp-trunk-args)))
:server-id 'trunk-lsp
:initialization-options (lambda ()
(list
:version "0.1.0"
:clientType "emacs"
:clientVersion (symbol-value 'emacs-version)))
:notification-handlers (ht ("$/progress" #'ignore))
:action-handlers (ht ("trunk.checkDisable" #'lsp-trunk-check-disable)
("trunk.checkEnable" #'lsp-trunk-check-enable)
("trunk.openConfigFile" #'lsp-trunk-open-config))
:priority -2
:add-on? t))

(lsp-consistency-check lsp-trunk)

(provide 'lsp-trunk)
;;; lsp-trunk.el ends here
9 changes: 9 additions & 0 deletions docs/lsp-clients.json
Original file line number Diff line number Diff line change
Expand Up @@ -1066,6 +1066,15 @@
"installation": "cargo install taplo-cli --features lsp",
"debugger": "Not available"
},
{
"name": "trunk",
"full-name": "Trunk",
"server-name": "trunk-lsp",
"server-url": "https://docs.trunk.io",
"installation": "curl https://get.trunk.io -fsSL | bash -s -- -y; trunk init",
"installation-url": "https://docs.trunk.io/check",
"debugger": "Not available"
},
{
"name": "typeprof",
"full-name": "Ruby (TypeProf)",
Expand Down
2 changes: 1 addition & 1 deletion lsp-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ As defined by the Language Server Protocol 3.16."
lsp-sonarlint lsp-tailwindcss lsp-tex lsp-terraform lsp-toml lsp-ttcn3
lsp-typeprof lsp-v lsp-vala lsp-verilog lsp-vetur lsp-volar lsp-vhdl
lsp-vimscript lsp-xml lsp-yaml lsp-ruby-lsp lsp-ruby-syntax-tree
lsp-solidity lsp-sqls lsp-svelte lsp-steep lsp-tilt lsp-zig lsp-jq)
lsp-solidity lsp-sqls lsp-svelte lsp-steep lsp-tilt lsp-trunk lsp-zig lsp-jq)
"List of the clients to be automatically required."
:group 'lsp-mode
:type '(repeat symbol))
Expand Down
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ nav:
- TeX, LaTeX, etc (texlab, external): page/lsp-latex.md
- Tilt: page/lsp-tilt.md
- TOML: page/lsp-toml.md
- Trunk: page/lsp-trunk.md
- TTCN3: page/lsp-ttcn3.md
- V: page/lsp-v.md
- Vala: page/lsp-vala.md
Expand Down

0 comments on commit 3a5fec8

Please sign in to comment.