|
| 1 | +;;; lsp-clojure.el --- Clojure Client settings -*- lexical-binding: t; -*- |
| 2 | + |
| 3 | +;; Copyright (C) 2019 Benedek Fazekas |
| 4 | + |
| 5 | +;; Author: Benedek Fazekas <[email protected]> |
| 6 | +;; Keywords: |
| 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-clojure client |
| 24 | + |
| 25 | +;;; Code: |
| 26 | + |
| 27 | +(require 'lsp-mode) |
| 28 | + |
| 29 | +(defgroup lsp-clojure nil |
| 30 | + "Settings for clojure." |
| 31 | + :group 'tools |
| 32 | + :tag "Language Server") |
| 33 | + |
| 34 | +(defcustom lsp-clojure-server-command '("bash" "-c" "clojure-lsp") |
| 35 | + "The clojure-lisp server command." |
| 36 | + :group 'lsp-clojure |
| 37 | + :risky t |
| 38 | + :type 'list) |
| 39 | + |
| 40 | +;; enables jumping into jarred dependencies |
| 41 | +;; in order to make this work the project needs to have a .lsp/config.edn with |
| 42 | +;; {"dependency-scheme" "jar"} in it so the server returns the URI in the right format |
| 43 | +(defun lsp-clj--file-in-jar (uri) |
| 44 | + (string-match "^\\(jar\\|zip\\):\\(file:.+\\)!/\\(.+\\)" uri) |
| 45 | + (when-let* ((entry (match-string 3 uri)) |
| 46 | + (path (lsp--uri-to-path (match-string 2 uri))) |
| 47 | + (name (format "%s:%s" path entry)) |
| 48 | + (content (lsp-send-request (lsp-make-request "clojure/dependencyContents" (list :uri uri))))) |
| 49 | + (if (find-buffer-visiting name) |
| 50 | + (message "buffer %s exists" name) |
| 51 | + (with-current-buffer (generate-new-buffer name) |
| 52 | + (insert content) |
| 53 | + (set-visited-file-name name) |
| 54 | + (setq-local buffer-read-only t) |
| 55 | + (set-buffer-modified-p nil) |
| 56 | + (set-auto-mode) |
| 57 | + (current-buffer))) |
| 58 | + name)) |
| 59 | + |
| 60 | +(lsp-register-client |
| 61 | + (make-lsp-client :new-connection (lsp-stdio-connection |
| 62 | + (lambda () lsp-clojure-server-command)) |
| 63 | + :major-modes '(clojure-mode clojurec-mode clojurescript-mode) |
| 64 | + :uri-handlers (lsp-ht ("jar" #'lsp-clj--file-in-jar)) |
| 65 | + :server-id 'clojure-lsp)) |
| 66 | + |
| 67 | +(provide 'lsp-clojure) |
0 commit comments