config

Personal configuration.
git clone git://code.dwrz.net/config
Log | Files | Refs

lsp-credo.el (3196B)


      1 ;;; lsp-credo.el --- lsp-mode Credo integration -*- lexical-binding: t; -*-
      2 
      3 ;; Copyright (C) 2023 Wilhelm H Kirschbaum
      4 
      5 ;; Author: Wilhelm H Kirschbaum
      6 ;; Keywords: lsp, elixir, credo
      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 Elixir Credo
     24 
     25 ;;; Code:
     26 
     27 (require 'lsp-mode)
     28 
     29 (defgroup lsp-credo nil
     30   "Settings for credo language server."
     31   :group 'lsp-mode
     32   :link '(url-link "https://github.com/elixir-tools/credo-language-server")
     33   :package-version '(lsp-mode . "9.0.0"))
     34 
     35 (defcustom lsp-credo-command
     36   `(,(f-join lsp-server-install-dir "credo-language-server"
     37             "credo-language-server")
     38     "--stdio=true")
     39   "The command that starts credo-language-server."
     40   :type '(repeat :tag "List of string values" string)
     41   :group 'lsp-credo
     42   :package-version '(lsp-mode . "9.0.0"))
     43 
     44 (defcustom lsp-credo-version "0.3.0"
     45   "Credo language server version to download.
     46 It has to be set before `lsp-credo.el' is loaded and it has to
     47 be available here: https://github.com/elixir-tools/credo-language-server/releases."
     48   :type 'string
     49   :group 'lsp-credo
     50   :package-version '(lsp-mode . "9.0.0"))
     51 
     52 (defcustom lsp-credo-download-url
     53   (format (concat "https://github.com/elixir-tools/credo-language-server"
     54                   "/releases/download/v%s/credo-language-server")
     55           lsp-credo-version)
     56   "Automatic download url for credo-language-server."
     57   :type 'string
     58   :group 'lsp-credo
     59   :package-version '(lsp-mode . "9.0.0"))
     60 
     61 (defcustom lsp-credo-binary-path
     62   (f-join lsp-server-install-dir
     63           "credo-language-server"
     64           "credo-language-server")
     65   "The path to `credo-language-server' binary."
     66   :type 'file
     67   :group 'lsp-credo
     68   :package-version '(lsp-mode . "9.0.0"))
     69 
     70 (lsp-dependency
     71  'credo-language-server
     72  `(:download :url lsp-credo-download-url
     73              :store-path lsp-credo-binary-path
     74              :set-executable? t))
     75 
     76 (lsp-register-client
     77  (make-lsp-client
     78   :new-connection (lsp-stdio-connection
     79                    (lambda ()
     80                      `(,(or (executable-find
     81                              (cl-first lsp-credo-command))
     82                             (lsp-package-path 'credo-language-server))
     83                        ,@(cl-rest lsp-credo-command))))
     84   :activation-fn (lsp-activate-on "elixir")
     85   :priority -1
     86   :add-on? t
     87   :multi-root nil
     88   :server-id 'credo-language-server
     89   :download-server-fn
     90   (lambda (_client callback error-callback _update?)
     91     (lsp-package-ensure 'credo-language-server callback error-callback))))
     92 
     93 (lsp-consistency-check lsp-credo)
     94 
     95 (provide 'lsp-credo)
     96 
     97 ;;; lsp-credo.el ends here