config

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

lsp-perlnavigator.el (7690B)


      1 ;;; lsp-perlnavigator.el --- Integrates the Perl Navigator LSP Server with lsp-mode  -*- lexical-binding: t; -*-
      2 
      3 ;; Copyright (C) 2022  Matthew Feinberg
      4 
      5 ;; Author: Matthew Feinberg <matthew.feinberg@gmail.com>
      6 ;; Keywords: lsp, perl
      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 ;;
     24 
     25 ;;; Code:
     26 
     27 (require 'lsp-mode)
     28 
     29 (defgroup lsp-perlnavigator nil
     30   "LSP support for Perl Navigator."
     31   :group 'lsp-mode
     32   :link '(url-link "https://github.com/bscan/PerlNavigator")
     33   :package-version '(lsp-mode . "9.0.0"))
     34 
     35 (defcustom lsp-perlnavigator-perl-path "perl"
     36   "Full path to the perl executable (no aliases, .bat files or ~/)."
     37   :type 'string
     38   :group 'lsp-perlnavigator
     39   :package-version '(lsp-mode . "9.0.0"))
     40 
     41 (defcustom lsp-perlnavigator-enable-warnings t
     42   "Enable warnings using -Mwarnings command switch."
     43   :type 'boolean
     44   :group 'lsp-perlnavigator
     45   :package-version '(lsp-mode . "9.0.0"))
     46 
     47 (defcustom lsp-perlnavigator-perltidy-profile nil
     48   "Path to perl tidy profile (no aliases, .bat files or ~/)."
     49   :type 'string
     50   :group 'lsp-perlnavigator
     51   :package-version '(lsp-mode . "9.0.0"))
     52 
     53 (defcustom lsp-perlnavigator-perlcritic-profile nil
     54   "Path to perl critic profile. Otherwise perlcritic itself will
     55 default to ~/.perlcriticrc. (no aliases, .bat files or ~/)."
     56   :type 'string
     57   :group 'lsp-perlnavigator
     58   :package-version '(lsp-mode . "9.0.0"))
     59 
     60 (defcustom lsp-perlnavigator-perlcritic-enabled t
     61   "Enable perl critic."
     62   :type 'boolean
     63   :group 'lsp-perlnavigator
     64   :package-version '(lsp-mode . "9.0.0"))
     65 
     66 (defcustom lsp-perlnavigator-severity5 "warning"
     67   "Editor Diagnostic severity level for Critic severity 5."
     68   :type '(choice (:tag "error" "warning" "info" "hint" "none"))
     69   :group 'lsp-perlnavigator
     70   :package-version '(lsp-mode . "9.0.0"))
     71 
     72 (defcustom lsp-perlnavigator-severity4 "info"
     73   "Editor Diagnostic severity level for Critic severity 4."
     74   :type '(choice (:tag "error" "warning" "info" "hint" "none"))
     75   :group 'lsp-perlnavigator
     76   :package-version '(lsp-mode . "9.0.0"))
     77 
     78 (defcustom lsp-perlnavigator-severity3 "hint"
     79   "Editor Diagnostic severity level for Critic severity 3."
     80   :type '(choice (:tag "error" "warning" "info" "hint" "none"))
     81   :group 'lsp-perlnavigator
     82   :package-version '(lsp-mode . "9.0.0"))
     83 
     84 (defcustom lsp-perlnavigator-severity2 "hint"
     85   "Editor Diagnostic severity level for Critic severity 2."
     86   :type '(choice (:tag "error" "warning" "info" "hint" "none"))
     87   :group 'lsp-perlnavigator
     88   :package-version '(lsp-mode . "9.0.0"))
     89 
     90 (defcustom lsp-perlnavigator-severity1 "hint"
     91   "Editor Diagnostic severity level for Critic severity 1."
     92   :type '(choice (:tag "error" "warning" "info" "hint" "none"))
     93   :group 'lsp-perlnavigator
     94   :package-version '(lsp-mode . "9.0.0"))
     95 
     96 (defcustom lsp-perlnavigator-include-paths nil
     97   "Array of paths added to @INC.  You can use $workspaceRoot as a placeholder."
     98   :type 'lsp-string-vector
     99   :group 'lsp-perlnavigator
    100   :package-version '(lsp-mode . "9.0.0"))
    101 
    102 (defcustom lsp-perlnavigator-logging t
    103   "Log to stdout from the navigator.  Viewable in the Perl Navigator LSP log."
    104   :type 'boolean
    105   :group 'lsp-perlnavigator
    106   :package-version '(lsp-mode . "9.0.0"))
    107 
    108 (defcustom lsp-perlnavigator-trace-server "messages"
    109   "Traces the communication between VS Code and the language server."
    110   :type '(choice (:tag "off" "messages" "verbose"))
    111   :group 'lsp-perlnavigator
    112   :package-version '(lsp-mode . "9.0.0"))
    113 
    114 (lsp-register-custom-settings
    115  '(("perlnavigator.trace.server" lsp-perlnavigator-trace-server)
    116    ("perlnavigator.logging" lsp-perlnavigator-logging t)
    117    ("perlnavigator.includePaths" lsp-perlnavigator-include-paths)
    118    ("perlnavigator.severity1" lsp-perlnavigator-severity1)
    119    ("perlnavigator.severity2" lsp-perlnavigator-severity2)
    120    ("perlnavigator.severity3" lsp-perlnavigator-severity3)
    121    ("perlnavigator.severity4" lsp-perlnavigator-severity4)
    122    ("perlnavigator.severity5" lsp-perlnavigator-severity5)
    123    ("perlnavigator.perlcriticEnabled" lsp-perlnavigator-perlcritic-enabled t)
    124    ("perlnavigator.perlcriticProfile" lsp-perlnavigator-perlcritic-profile)
    125    ("perlnavigator.perltidyProfile" lsp-perlnavigator-perltidy-profile)
    126    ("perlnavigator.enableWarnings" lsp-perlnavigator-enable-warnings t)
    127    ("perlnavigator.perlPath" lsp-perlnavigator-perl-path)))
    128 
    129 (defcustom lsp-perlnavigator-executable "perlnavigator"
    130   "Location of the perlnavigator binary."
    131   :group 'lsp-perlnavigator
    132   :risky t
    133   :type 'file)
    134 
    135 (defvar lsp-perlnavigator--os-suffix
    136   (let ((x86_64 (eq (string-match "^x86_64" system-configuration) 0)))
    137     (cond ((and x86_64 (eq system-type 'windows-nt))
    138            "-win-x86_64")
    139 
    140           ((and x86_64 (eq system-type 'darwin))
    141            "-macos-x86_64")
    142 
    143           ((and x86_64 (eq system-type 'gnu/linux))
    144            "-linux-x86_64")))
    145 
    146   "The suffix used to specify the download for this operating system.")
    147 
    148 (defcustom lsp-perlnavigator-download-url
    149   (let ((base-url "https://github.com/bscan/PerlNavigator/releases/latest/download/"))
    150     (if lsp-perlnavigator--os-suffix
    151         (concat base-url "perlnavigator" lsp-perlnavigator--os-suffix ".zip")))
    152 
    153   "Automatic download url for PerlNavigator."
    154   :group 'lsp-perlnavigator
    155   :type 'string)
    156 
    157 (defcustom lsp-perlnavigator-autoinstall-dir
    158   (f-join lsp-server-install-dir "perlnavigator")
    159   "Automatic installation directory for Perl Navigator."
    160   :group 'lsp-perlnavigator
    161   :type 'directory)
    162 
    163 (defvar lsp-perlnavigator--autoinstall-store-path
    164   (f-join lsp-perlnavigator-autoinstall-dir "latest" (concat "perlnavigator" lsp-perlnavigator--os-suffix ".zip"))
    165   "The path where the downloaded PerlNavigator .zip archive will be stored.")
    166 
    167 
    168 (defvar lsp-perlnavigator--autoinstall-binary-path
    169     (let ((exe-name (if (eq system-type 'windows-nt) "perlnavigator.exe" "perlnavigator")))
    170       (f-join lsp-perlnavigator-autoinstall-dir "latest" (concat "perlnavigator" lsp-perlnavigator--os-suffix) exe-name))
    171     "The path to the automatically installed language server executable.")
    172 
    173 (lsp-dependency
    174  'perlnavigator
    175  '(:system lsp-perlnavigator-executable)
    176  `(:download
    177    :decompress
    178    :zip
    179    :binary-path lsp-perlnavigator--autoinstall-binary-path
    180    :url lsp-perlnavigator-download-url
    181    :store-path lsp-perlnavigator--autoinstall-store-path
    182    :set-executable? t))
    183 
    184 (lsp-register-client
    185  (make-lsp-client :new-connection (lsp-stdio-connection (lambda ()
    186                                                           (list
    187                                                            (or (lsp-package-path 'perlnavigator)
    188                                                                lsp-perlnavigator-executable)
    189                                                            "--stdio")))
    190                   :activation-fn (lsp-activate-on "perl")
    191                   :priority 0
    192                   :download-server-fn (lambda (_client callback error-callback _update?)
    193                                         (lsp-package-ensure 'perlnavigator callback error-callback))
    194                   :server-id 'perlnavigator))
    195 
    196 (provide 'lsp-perlnavigator)
    197 ;;; lsp-perlnavigator.el ends here