Skip to content

Commit e3dce5c

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
1 parent 4c87e81 commit e3dce5c

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

README.org

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+
;; enables jumping into jarred dependencies
30+
;; in order to make this work the project needs to have a .lsp/config.edn with
31+
;; {"dependency-scheme" "jar"} in it so the server returns the URI in the right format
32+
(defun lsp-clj--file-in-jar (uri)
33+
(string-match "^\\(jar\\|zip\\):\\(file:.+\\)!/\\(.+\\)" uri)
34+
(when-let* ((entry (match-string 3 uri))
35+
(path (lsp--uri-to-path (match-string 2 uri)))
36+
(name (format "%s:%s" path entry))
37+
(content (lsp-send-request (lsp-make-request "clojure/dependencyContents" (list :uri uri)))))
38+
(if (find-buffer-visiting name)
39+
(message "buffer %s exists" name)
40+
(with-current-buffer (generate-new-buffer name)
41+
(insert content)
42+
(set-visited-file-name name)
43+
(setq-local buffer-read-only t)
44+
(set-buffer-modified-p nil)
45+
(set-auto-mode)
46+
(current-buffer)))
47+
name))
48+
49+
(lsp-register-client
50+
(make-lsp-client :new-connection (lsp-stdio-connection '("bash" "-c" "clojure-lsp"))
51+
:major-modes '(clojure-mode clojurec-mode clojurescript-mode)
52+
:uri-handlers (lsp-ht ("jar" #'lsp-clj--file-in-jar))
53+
:server-id 'clojure-lsp))
54+
55+
(provide 'lsp-clojure)

0 commit comments

Comments
 (0)