From 3a5fec82dbbec492b6bc81b875534d1a2362dbe8 Mon Sep 17 00:00:00 2001 From: Tyler Jang Date: Sun, 17 Mar 2024 11:22:27 -0700 Subject: [PATCH] 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 --- CHANGELOG.org | 1 + clients/lsp-trunk.el | 88 +++++++++++++++++++++++++++++++++++++++++++ docs/lsp-clients.json | 9 +++++ lsp-mode.el | 2 +- mkdocs.yml | 1 + 5 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 clients/lsp-trunk.el diff --git a/CHANGELOG.org b/CHANGELOG.org index d5d45bd349..fb488e8935 100644 --- a/CHANGELOG.org +++ b/CHANGELOG.org @@ -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. diff --git a/clients/lsp-trunk.el b/clients/lsp-trunk.el new file mode 100644 index 0000000000..f72c3d0203 --- /dev/null +++ b/clients/lsp-trunk.el @@ -0,0 +1,88 @@ +;;; lsp-trunk.el --- trunk support -*- lexical-binding: t; -*- +;; +;; Copyright (C) 2024 Trunk Technologies, Inc. +;; +;; Author: Tyler Jang +;; 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 . +;; 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 diff --git a/docs/lsp-clients.json b/docs/lsp-clients.json index 3cab5f3906..4a87d272ac 100644 --- a/docs/lsp-clients.json +++ b/docs/lsp-clients.json @@ -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)", diff --git a/lsp-mode.el b/lsp-mode.el index bd190cec2a..e3d208e484 100644 --- a/lsp-mode.el +++ b/lsp-mode.el @@ -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)) diff --git a/mkdocs.yml b/mkdocs.yml index 48036aad1b..13700faba7 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -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