config

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

lsp-magik.el (4812B)


      1 ;;; lsp-magik.el --- Language server client for Magik  -*- lexical-binding: t; -*-
      2 
      3 ;; Copyright (C) 2022 Keronic
      4 
      5 ;; Author: <robin.putters@keronic.com>
      6 ;; Keywords: lsp, magik
      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 the Magik programming language
     24 ;; https://github.com/StevenLooman/magik-tools
     25 
     26 ;;; Code:
     27 
     28 (require `lsp-mode)
     29 
     30 (defgroup lsp-magik nil
     31   "LSP support for Magik."
     32   :link '(url-link "https://github.com/StevenLooman/magik-tools")
     33   :group 'lsp-mode
     34   :tag "Lsp Magik"
     35   :package-version '(lsp-mode . "9.0.0"))
     36 
     37 (defcustom lsp-magik-version "0.9.0"
     38   "Version of LSP server."
     39   :type `string
     40   :group `lsp-magik
     41   :package-version '(lsp-mode . "9.0.0"))
     42 
     43 (defcustom lsp-magik-download-url-lsp (format "https://github.com/StevenLooman/magik-tools/releases/download/%s/magik-language-server-%s.jar" lsp-magik-version lsp-magik-version)
     44   "URL of LSP server to download."
     45   :type `string
     46   :group `lsp-magik
     47   :package-version '(lsp-mode . "9.0.0"))
     48 
     49 (lsp-dependency
     50  'magik-ls
     51  `(:download :url lsp-magik-download-url-lsp
     52              :store-path ,(f-join lsp-server-install-dir "magik-ls" (format "magik-language-server-%s.jar" lsp-magik-version))))
     53 
     54 (defcustom lsp-magik-ls-path
     55   (f-join lsp-server-install-dir (format "magik-ls/magik-language-server-%s.jar" lsp-magik-version))
     56   "Path of the language server."
     57   :type 'string
     58   :group `lsp-magik
     59   :package-version '(lsp-mode . "9.0.0"))
     60 
     61 (defcustom lsp-magik-java-home nil
     62   "Path to Java Runtime, Java 11 minimum."
     63   :type `string
     64   :group `lsp-magik
     65   :package-version '(lsp-mode . "9.0.0"))
     66 
     67 (defcustom lsp-magik-smallworld-gis nil
     68   "Path to Smallworld Core."
     69   :type `string
     70   :group `lsp-magik
     71   :package-version '(lsp-mode . "9.0.0"))
     72 
     73 (defcustom lsp-magik-typing-type-database-paths []
     74   "Paths to type databases."
     75   :type `lsp-string-vector
     76   :group `lsp-magik
     77   :package-version '(lsp-mode . "9.0.0"))
     78 
     79 (defcustom lsp-magik-typing-enable-checks nil
     80   "Enable typing checks."
     81   :type `boolean
     82   :group `lsp-magik
     83   :package-version '(lsp-mode . "9.0.0"))
     84 
     85 (defcustom lsp-magik-trace-server "off"
     86   "Traces the communication between VS Code and the Magik language server."
     87   :type `(choice (const "off") (const "message") (const "verbose"))
     88   :group `lsp-magik
     89   :package-version '(lsp-mode . "9.0.0"))
     90 
     91 (defcustom lsp-magik-java-path (lambda ()
     92                                  (cond ((eq system-type 'windows-nt)
     93                                         (or (lsp-resolve-value (executable-find (expand-file-name "bin/java" (getenv "JAVA_HOME"))))
     94                                             (lsp-resolve-value (executable-find "java"))))
     95                                        (t "java")))
     96   "Path of the java executable."
     97   :type 'string
     98   :group `lsp-magik
     99   :package-version '(lsp-mode . "9.0.0"))
    100 
    101 (defcustom lsp-magik-lint-override-config-file nil
    102   "Override path to magiklintrc.properties."
    103   :type 'string
    104   :group `lsp-magik
    105   :package-version '(lsp-mode . "9.0.0"))
    106 
    107 (lsp-register-client
    108  (make-lsp-client
    109   :download-server-fn (lambda (_client callback error-callback _update?)
    110                         (lsp-package-ensure 'magik-ls callback error-callback))
    111   :new-connection (lsp-stdio-connection
    112                    (lambda ()
    113                      (list
    114                       (substitute-in-file-name (lsp-resolve-value lsp-magik-java-path))
    115                       "-jar"
    116                       (substitute-in-file-name lsp-magik-ls-path)
    117                       "--debug")))
    118   :activation-fn (lsp-activate-on "magik")
    119   :initialized-fn (lambda (workspace)
    120                     (with-lsp-workspace workspace
    121                       (lsp--set-configuration (lsp-configuration-section "magik"))))
    122   :server-id 'magik))
    123 
    124 (lsp-register-custom-settings
    125  `(("magik.javaHome" lsp-magik-java-home)
    126    ("magik.smallworldGis" lsp-magik-smallworld-gis)
    127    ("magik.typing.typeDatabasePaths" lsp-magik-typing-type-database-paths)
    128    ("magik.typing.enableChecks" lsp-magik-typing-enable-checks)
    129    ("magik.trace.server" lsp-magik-trace-server)
    130    ("magik.lint.overrideConfigFile" lsp-magik-lint-override-config-file)))
    131 
    132 (lsp-consistency-check lsp-magik)
    133 
    134 (provide 'lsp-magik)
    135 ;;; lsp-magik.el ends here