config

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

lsp-ada.el (7014B)


      1 ;;; lsp-ada.el --- description -*- lexical-binding: t; -*-
      2 
      3 ;; Copyright (C) 2020 emacs-lsp maintainers
      4 
      5 ;; Author: emacs-lsp maintainers
      6 ;; Keywords: lsp, ada
      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 Clients for the Ada Programming Language
     24 
     25 ;;; Code:
     26 
     27 (require 'lsp-mode)
     28 (require 'lsp-semantic-tokens)
     29 
     30 (defgroup lsp-ada nil
     31   "Settings for Ada Language Server."
     32   :group 'tools
     33   :tag "Language Server"
     34   :package-version '(lsp-mode . "6.2"))
     35 
     36 (lsp-defcustom lsp-ada-project-file nil
     37   "GNAT Project file used to configure the Language Server.
     38 
     39 Both absolute and relative paths are supported within the project file
     40 name.  When a relative path is used, the path is relative to the root
     41 folder.
     42 
     43 When the project file is not specified, the Language Server will attempt
     44 to determine the project file itself, either by querying \\='alr\\=', if
     45 the root folder contains an alire.toml file and \\='alr\\=' was found in
     46 the path, or otherwise by searching for a unique project file in the
     47 root folder.  For Alire projects, whose project file was discovered by
     48 querying \\='alr\\=', the server will also query and populate the Alire
     49 environment."
     50   :type '(choice (string :tag "File")
     51                  (const  :tag "Not Specified" nil))
     52   :group 'lsp-ada
     53   :link '(url-link :tag "Configuration Example"
     54                    "https://github.com/AdaCore/ada_language_server")
     55   :package-version '(lsp-mode . "9.0.1")
     56   :lsp-path "ada.projectFile")
     57 ;;;###autoload(put 'lsp-ada-project-file 'safe-local-variable 'stringp)
     58 
     59 (lsp-defcustom lsp-ada-option-charset "UTF-8"
     60   "The charset to use by the Ada Language server. Defaults to \\='UTF-8\\='."
     61   :type 'string
     62   :group 'lsp-ada
     63   :package-version '(lsp-mode . "6.2")
     64   :lsp-path "ada.defaultCharset")
     65 
     66 (lsp-defcustom lsp-ada-enable-diagnostics t
     67   "A boolean to disable diagnostics. Defaults to true."
     68   :type 'boolean
     69   :group 'lsp-ada
     70   :package-version '(lsp-mode . "6.2")
     71   :lsp-path "ada.enableDiagnostics")
     72 
     73 (defcustom lsp-ada-als-executable "ada_language_server"
     74   "Command to start the Ada language server."
     75   :group 'lsp-ada
     76   :risky t
     77   :type 'file)
     78 
     79 (defcustom lsp-ada-semantic-token-face-overrides
     80   '(("namespace" . default)
     81     ("modifier"  . lsp-face-semhl-keyword))
     82   "Semantic token face overrides to be applied."
     83   :type '(alist :key-type string
     84                 :value-type (choice (face  :tag "Face")
     85                                     (const :tag "No Face" nil)))
     86   :group 'lsp-ada
     87   :package-version '(lsp-mode "9.0.0"))
     88 
     89 (defcustom lsp-ada-semantic-token-modifier-face-overrides
     90   '(("declaration")
     91     ("definition")
     92     ("implementation")
     93     ("static")
     94     ("modification")
     95     ("documentation")
     96     ("defaultLibrary"))
     97   "Semantic token modifier face overrides to be applied."
     98   :type '(alist :key-type string
     99                 :value-type (choice (face  :tag "Face")
    100                                     (const :tag "No Face" nil)))
    101   :group 'lsp-ada
    102   :package-version '(lsp-mode "9.0.0"))
    103 
    104 (defvar lsp-ada--als-download-url-cache nil)
    105 
    106 (defvar lsp-ada--als-downloaded-executable
    107   (f-join lsp-server-install-dir
    108           "ada-ls"
    109           (symbol-name (lsp-resolve-value lsp--system-arch))
    110           (pcase system-type
    111             ('gnu/linux  "linux")
    112             ('darwin     "darwin")
    113             ('windows-nt "win32")
    114             (_           "linux"))
    115           (concat "ada_language_server"
    116                   (pcase system-type
    117                     ('windows-nt ".exe")
    118                     (_ "")))))
    119 
    120 (defun lsp-ada--als-latest-release-url ()
    121   "URL for the latest release of the Ada Language Server."
    122   (setq lsp-ada--als-download-url-cache
    123         (lsp--find-latest-gh-release-url
    124          "https://api.github.com/repos/AdaCore/ada_language_server/releases/latest"
    125          (format "%s.zip"
    126                  (pcase (list system-type (lsp-resolve-value lsp--system-arch))
    127                    ('(gnu/linux  x64)   "Linux_amd64")
    128                    ('(gnu/linux  arm64) "Linux_aarch64")
    129                    ('(darwin     x64)   "macOS_amd64")
    130                    ('(darwin     arm64) "macOS_aarch64")
    131                    ('(windows-nt x64)   "Windows_amd64")
    132                    (`(,_         x64)   "Linux_amd64"))))))
    133 
    134 (defun lsp-ada--als-store-path ()
    135   "Store Path for the downloaded Ada Language Server."
    136   (f-join lsp-server-install-dir
    137           "ada-ls"
    138           (file-name-base (or lsp-ada--als-download-url-cache
    139                               (lsp-ada--als-latest-release-url)
    140                               "ada-ls"))))
    141 
    142 (lsp-dependency
    143  'ada-ls
    144  '(:download :url lsp-ada--als-latest-release-url
    145              :store-path lsp-ada--als-store-path
    146              :decompress :zip
    147              :binary-path lsp-ada--als-downloaded-executable
    148              :set-executable? t)
    149  '(:system lsp-ada-als-executable))
    150 
    151 (lsp-register-client
    152  (make-lsp-client :new-connection (lsp-stdio-connection
    153                                    (lambda () (lsp-package-path 'ada-ls)))
    154                   :major-modes '(ada-mode ada-ts-mode)
    155                   :priority -1
    156                   :initialized-fn (lambda (workspace)
    157                                     (with-lsp-workspace workspace
    158                                       (lsp--set-configuration
    159                                        (lsp-configuration-section "ada"))))
    160                   :download-server-fn (lambda (_client callback error-callback _update?)
    161                                         (lsp-package-ensure 'ada-ls callback error-callback))
    162                   :semantic-tokens-faces-overrides `( :types ,lsp-ada-semantic-token-face-overrides
    163                                                       :modifiers ,lsp-ada-semantic-token-modifier-face-overrides)
    164                   :server-id 'ada-ls
    165                   :synchronize-sections '("ada")))
    166 
    167 (lsp-register-client
    168  (make-lsp-client :new-connection (lsp-stdio-connection
    169                                    (lambda () (list (lsp-package-path 'ada-ls)
    170                                                     "--language-gpr")))
    171                   :major-modes '(gpr-mode gpr-ts-mode)
    172                   :priority -1
    173                   :download-server-fn (lambda (_client callback error-callback _update?)
    174                                         (lsp-package-ensure 'ada-ls callback error-callback))
    175                   :server-id 'gpr-ls))
    176 
    177 (lsp-consistency-check lsp-ada)
    178 
    179 (provide 'lsp-ada)
    180 ;;; lsp-ada.el ends here