config

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

lsp-lisp.el (2675B)


      1 ;;; lsp-lisp.el --- LSP client for Lisp  -*- lexical-binding: t; -*-
      2 
      3 ;; Copyright (C) 2024  Shen, Jen-Chieh
      4 
      5 ;; This file is not part of GNU Emacs.
      6 
      7 ;; This program is free software: you can redistribute it and/or modify
      8 ;; it under the terms of the GNU General Public License as published by
      9 ;; the Free Software Foundation, either version 3 of the License, or
     10 ;; (at your option) any later version.
     11 
     12 ;; This program is distributed in the hope that it will be useful,
     13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 ;; GNU General Public License for more details.
     16 
     17 ;; You should have received a copy of the GNU General Public License
     18 ;; along with this program. If not, see <https://www.gnu.org/licenses/>.
     19 
     20 ;;; Commentary:
     21 ;;
     22 ;; LSP client for Lisp.
     23 ;;
     24 
     25 ;;; Code:
     26 
     27 (require 'lsp-mode)
     28 
     29 (defgroup lsp-lisp nil
     30   "LSP support for Lisp."
     31   :group 'lsp-mode
     32   :package-version `(lsp-mode . "9.0.0"))
     33 
     34 (defcustom lsp-lisp-active-modes
     35   '( lisp-mode)
     36   "List of major mode that work with lisp."
     37   :type 'list
     38   :group 'lsp-lisp)
     39 
     40 (defcustom lsp-lisp-alive-port 8006
     41   "Port to connect server to."
     42   :type 'integer
     43   :group 'lsp-lisp)
     44 
     45 ;;
     46 ;;; Server
     47 
     48 ;;;###autoload
     49 (defun lsp-lisp-alive-start-ls ()
     50   "Start the alive-lsp."
     51   (interactive)
     52   (when-let ((exe (executable-find "sbcl"))
     53              ((lsp--port-available "localhost" lsp-lisp-alive-port)))
     54     (lsp-async-start-process #'ignore #'ignore
     55                              exe
     56                              "--noinform"
     57                              "--eval"
     58                              "(ql:quickload \"alive-lsp\")"
     59                              "--eval"
     60                              (format "(alive/server::start :port %s)"
     61                                      lsp-lisp-alive-port))))
     62 
     63 ;;
     64 ;;; Core
     65 
     66 (defun lsp-lisp-alive--tcp-connect-to-port ()
     67   "Define a TCP connection to language server."
     68   (list
     69    :connect
     70    (lambda (filter sentinel name _environment-fn _workspace)
     71      (let* ((host "localhost")
     72             (port lsp-lisp-alive-port)
     73             (tcp-proc (lsp--open-network-stream host port (concat name "::tcp"))))
     74 
     75        ;; TODO: Same :noquery issue (see above)
     76        (set-process-query-on-exit-flag tcp-proc nil)
     77        (set-process-filter tcp-proc filter)
     78        (set-process-sentinel tcp-proc sentinel)
     79        (cons tcp-proc tcp-proc)))
     80    :test? (lambda () t)))
     81 
     82 (lsp-register-client
     83  (make-lsp-client
     84   :new-connection (lsp-lisp-alive--tcp-connect-to-port)
     85   :major-modes lsp-lisp-active-modes
     86   :priority -1
     87   :server-id 'alive-lsp))
     88 
     89 (lsp-consistency-check lsp-lisp)
     90 
     91 (provide 'lsp-lisp)
     92 ;;; lsp-lisp.el ends here