Skip to content

Commit 062bc80

Browse files
Add support for Clojure/ClojureScript via clojure-lsp
Additionally enable jumping into jarred dependencies if the server is configured to return the URI in the right format. Command to start server is configurable via a defcustom.
1 parent 4c87e81 commit 062bc80

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed

README.org

+1
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
| C++ | [[https://github.com/MaskRay/ccls][ccls]] | [[https://github.com/MaskRay/emacs-ccls][emacs-ccls]] | [[https://github.com/MaskRay/ccls][ccls]] | Yes (gdb or lldb) |
107107
| C++ | [[https://clang.llvm.org/extra/clangd.html][clangd]] | Yes | [[https://clang.llvm.org/extra/clangd.html][clangd]] | Yes (gdb or lldb) |
108108
| C++ | [[https://github.com/cquery-project/cquery][cquery]] | [[https://github.com/cquery-project/emacs-cquery][emacs-cquery]] | [[https://github.com/cquery-project/cquery][cquery]] | Yes (gdb or lldb) |
109+
| Clojure | [[https://github.com/snoe/clojure-lsp][clojure-lsp]] | Yes | [[https://github.com/snoe/clojure-lsp][clojure-lisp]] | |
109110
| CSS/LessCSS/SASS/SCSS | [[https://github.com/vscode-langservers/vscode-css-languageserver-bin][css]] | Yes | npm install -g vscode-css-languageserver-bin | |
110111
| Dart | [[https://github.com/natebosch/dart_language_server][dart_language_server]] | Yes | pub global activate dart_language_server | |
111112
| Elixir | [[https://github.com/JakeBecker/elixir-ls][elixir-ls]] | Yes | [[https://github.com/JakeBecker/elixir-ls][elixir-ls]] | Yes |

lsp-clients.el

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
(require 'lsp-css)
3636
(require 'lsp-xml)
3737
(require 'lsp-go)
38+
(require 'lsp-clojure)
3839

3940
;;; Bash
4041
(lsp-register-client

lsp-clojure.el

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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

Comments
 (0)