Skip to content

Commit 30842eb

Browse files
authored
conform to spec on nrepl's info op on :file and :column values (#1068)
Hi, could you please review patch to align the nrepl server's `info` op with the `cider-nrepl` spec. It fixes #1066. According to the spec, the `:file` return value should be a URI when it refers to an absolute path. It also specifies `:column` as a return key, which was previously missing. `cider-nrepl` `info` spec: https://docs.cider.mx/cider-nrepl/nrepl-api/ops.html#info The nrepl-server's `info` test has been updated accordingly. Thanks Co-authored-by: ikappaki <[email protected]>
1 parent dd7d239 commit 30842eb

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88

99
### Fixed
1010
* Fix a bug where the reader was double counting the CRLF newline seq in metadata (#1063)
11+
* Conform to the `cider-nrepl` `info` ops spec by ensuring result's `:file` is URI, also added missing :column number (#1066)
1112

1213
## [v0.2.3]
1314
### Added

src/basilisp/contrib/nrepl_server.lpy

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
[basilisp.string :as str])
77
(:import basilisp.logconfig
88
logging
9+
os
910
socketserver
1011
sys
1112
traceback
13+
urllib
1214
uuid))
1315

1416
(def ^:private logger
@@ -222,7 +224,7 @@
222224
"Look up ``:sym`` (CIDER) or ``:symbol`` (calva) from ``request`` in ``ns``
223225
(or if not provided ``:eval-ns`` from ``client*``) and pass results to ``send-fn``.
224226

225-
Serves both :eldoc and :info ``request`` :op's."
227+
Serves both cider-nrepl's :eldoc and :info ``request`` :op's."
226228
[{:keys [ns client*] :as request} send-fn]
227229
(let [mapping-type (-> request :op)
228230
{:keys [eval-ns]} @client*]
@@ -237,7 +239,7 @@
237239
[tp var-maybe] (symbol-identify lookup-ns sym-str)
238240
var-meta (when (= tp :var) (meta var-maybe))
239241

240-
{:keys [arglists doc file ns line] symname :name} var-meta
242+
{:keys [arglists doc file ns line col] symname :name} var-meta
241243

242244
ref (when (= tp :var) (var-get var-maybe))
243245
response (when symname
@@ -254,8 +256,12 @@
254256
:info {"doc" doc
255257
"ns" (str ns)
256258
"name" (str symname)
257-
"file" file
259+
"file" (if (os.path/isabs file)
260+
(->> (urllib.parse/quote file)
261+
(urllib.parse/urljoin "file:"))
262+
file)
258263
"line" line
264+
"column" col
259265
"arglists-str" (forms-join arglists)
260266
"status" ["done"]}))
261267
status (if (and (nil? symname) (= mapping-type :eldoc) )
@@ -322,8 +328,8 @@
322328
handlers for those operations."
323329
{:eval handle-eval
324330
:describe handle-describe
325-
:info handle-lookup
326-
:eldoc handle-lookup
331+
:info handle-lookup ;; cider-nrepl middleware
332+
:eldoc handle-lookup ;; cider-nrepl middleware
327333
:clone handle-clone
328334
:close handle-close
329335
:load-file handle-load-file

tests/basilisp/contrib/nrepl_server_test.lpy

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
socket
1313
tempfile
1414
threading
15-
time))
15+
time
16+
urllib))
1617

1718
(use-fixtures :each fixtures/tempdir)
1819

@@ -454,13 +455,17 @@
454455
(let [{:keys [status]} (client-recv! client)]
455456
(is (= ["done"] status)))
456457
(client-send! client {:id (id-inc!) :op "info" :ns "user" :sym "sort-by"})
457-
(let [{:keys [file line] :as response} (client-recv! client)
458-
{:keys [doc]
459-
meta-file :file} (meta (resolve 'sort-by))]
458+
(let [{:keys [file line column] :as response} (client-recv! client)
459+
{:keys [doc col]
460+
meta-file :file
461+
meta-line :line} (meta (resolve 'sort-by))
462+
meta-file-uri (->> (urllib.parse/quote meta-file)
463+
(urllib.parse/urljoin "file:"))]
460464
(is (= {:ns "basilisp.core" :status ["done"] :id @id* :arglists-str "[keyfn coll]\n[keyfn cmp coll]"
465+
:line line :column col
461466
:doc doc :name "sort-by"}
462-
(select-keys response [:ns :status :id :arglists-str :doc :name])))
463-
(is (= meta-file file)))
467+
(select-keys response [:ns :status :id :arglists-str :doc :name :line :column])))
468+
(is (= meta-file-uri file)))
464469

465470
;; test fqdn, aliases and refers
466471
(client-send! client {:id (id-inc!) :op "eval"

0 commit comments

Comments
 (0)