config

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

lsp-asm.el (3055B)


      1 ;;; lsp-asm.el --- Assembly Language Client settings         -*- lexical-binding: t; -*-
      2 
      3 ;; Copyright (C) 2023  Jen-Chieh Shen
      4 
      5 ;; Author: Jen-Chieh Shen <jcs090218@gmail.com>
      6 ;; Keywords: asm lsp
      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 Assembly Language
     24 
     25 ;;; Code:
     26 
     27 (require 'lsp-mode)
     28 
     29 (defgroup lsp-asm nil
     30   "LSP support for Assembly Language."
     31   :group 'lsp-mode
     32   :link '(url-link "https://github.com/bergercookie/asm-lsp")
     33   :package-version `(lsp-mode . "9.0.0"))
     34 
     35 (defcustom lsp-asm-active-modes
     36   '( asm-mode fasm-mode masm-mode nasm-mode gas-mode)
     37   "List of major mode that work with asm-lsp."
     38   :type '(list symbol)
     39   :group 'lsp-asm)
     40 
     41 (defcustom lsp-asm-home-url
     42   "https://github.com/bergercookie/asm-lsp"
     43   "Url we use to install asm-lsp."
     44   :type 'string
     45   :group 'lsp-asm
     46   :package-version '(lsp-mode . "9.0.0"))
     47 
     48 (defcustom lsp-asm-store-path (f-join lsp-server-install-dir "asm")
     49   "The path to the file in which `asm-lsp' will be stored."
     50   :type 'file
     51   :group 'lsp-asm
     52   :package-version '(lsp-mode . "9.0.0"))
     53 
     54 (defun lsp-asm--download-server (_client callback error-callback update?)
     55   "Install/update asm-ls language server using `cargo install'.
     56 
     57 Will invoke CALLBACK or ERROR-CALLBACK based on result.
     58 Will update if UPDATE? is t."
     59   (when update?
     60     (ignore-errors (delete-directory lsp-asm-store-path t)))
     61   (lsp-async-start-process
     62    callback
     63    error-callback
     64    "cargo" "install" "--git" lsp-asm-home-url "--root" lsp-asm-store-path))
     65 
     66 (defun lsp-asm--executable ()
     67   "Return asm-lsp executable."
     68   (let ((local (f-join lsp-asm-store-path "bin"
     69                        (if (eq system-type 'windows-nt)
     70                            "asm-lsp.exe"
     71                          "asm-lsp"))))
     72     (or (and (f-exists? local) local)
     73         (executable-find "asm-lsp")
     74         (user-error "`asm-lsp' is not installed; for installation see %s for more information" lsp-asm-home-url))))
     75 
     76 (defun lsp-asm--server-command ()
     77   "Startup command for Assembly language server."
     78   (list (lsp-asm--executable)))
     79 
     80 (lsp-register-client
     81  (make-lsp-client
     82   :new-connection (lsp-stdio-connection
     83                    #'lsp-asm--server-command
     84                    (lambda () (f-exists? lsp-asm-store-path)))
     85   :major-modes lsp-asm-active-modes
     86   :priority -1
     87   :server-id 'asm-lsp
     88   :download-server-fn #'lsp-asm--download-server))
     89 
     90 (lsp-consistency-check lsp-asm)
     91 
     92 (provide 'lsp-asm)
     93 ;;; lsp-asm.el ends here