lsp-rubocop.el (2147B)
1 ;;; lsp-rubocop.el --- lsp-mode for RuboCop -*- lexical-binding: t; -*- 2 3 ;; Copyright (C) 2023 Koichi Ito 4 5 ;; Author: Koichi Ito <koic.ito@gmail.com> 6 ;; Keywords: lsp, ruby, languages 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 21 ;;; Commentary: 22 23 ;; LSP client for RuboCop which is a Ruby static code analyzer (a.k.a. linter) 24 ;; and code formatter. 25 26 ;;; Code: 27 28 (require 'lsp-mode) 29 30 (defgroup lsp-rubocop nil 31 "LSP support for RuboCop, using the RuboCop built-in language server." 32 :group 'lsp-mode 33 :link '(url-link "https://github.com/rubocop/rubocop") 34 :package-version '(lsp-mode . "9.0.0")) 35 36 (defcustom lsp-rubocop-use-bundler nil 37 "Run RuboCop using Bundler." 38 :type 'boolean 39 :safe #'booleanp 40 :group 'lsp-rubocop 41 :package-version '(lsp-mode . "9.0.0")) 42 43 (defcustom lsp-rubocop-server-path nil 44 "Path of the RuboCop built-in language server executable. 45 If specified, `lsp-rubocop-use-bundler' is ignored." 46 :type 'file 47 :group 'lsp-rubocop 48 :package-version '(lsp-mode . "9.0.0")) 49 50 (defun lsp-rubocop--build-command () 51 "Build a command to start the RuboCop built-in language server." 52 (append 53 (if (and lsp-rubocop-use-bundler (not lsp-rubocop-server-path)) '("bundle" "exec")) 54 (list (or lsp-rubocop-server-path "rubocop") "--lsp"))) 55 56 (lsp-register-client 57 (make-lsp-client 58 :new-connection (lsp-stdio-connection #'lsp-rubocop--build-command) 59 :activation-fn (lsp-activate-on "ruby") 60 :priority -1 61 :server-id 'rubocop-ls)) 62 63 (lsp-consistency-check lsp-rubocop) 64 65 (provide 'lsp-rubocop) 66 ;;; lsp-rubocop.el ends here