Skip to content

Fix #3010 - middleware error on invalid keywords #3016

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
### Bugs fixed

* [#3012](https://github.com/clojure-emacs/cider/issues/3012): Allow connecting sibling repls from any buffer.

* [#3010](https://github.com/clojure-emacs/cider/issues/3010): Remove :: auto-resolved keyword expansion logic from cider-symbol-at-point, moving it to cider-browse-spec.

## 1.1.0 (2021-04-22)

Expand Down
4 changes: 4 additions & 0 deletions cider-browse-spec.el
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,10 @@ a more user friendly representation of SPEC-FORM."
"Browse SPEC."
(cider-ensure-connected)
(cider-ensure-op-supported "spec-form")
;; Expand auto-resolved keywords
(when-let* ((val (and (string-match-p "^::.+" spec)
(nrepl-dict-get (cider-sync-tooling-eval spec (cider-current-ns)) "value"))))
(setq spec val))
(with-current-buffer (cider-popup-buffer cider-browse-spec-buffer 'select #'cider-browse-spec-view-mode 'ancillary)
(setq-local cider-browse-spec--current-spec spec)
(cider-browse-spec--draw-spec-buffer (current-buffer)
Expand Down
9 changes: 3 additions & 6 deletions cider-util.el
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@
(require 'cider-compat)
(require 'clojure-mode)

(declare-function cider-sync-request:macroexpand "cider-macroexpansion")

(defalias 'cider-pop-back 'pop-tag-mark)

(defcustom cider-font-lock-max-length 10000
Expand Down Expand Up @@ -127,11 +125,10 @@ instead."
(defun cider-symbol-at-point (&optional look-back)
"Return the name of the symbol at point, otherwise nil.
Ignores the REPL prompt. If LOOK-BACK is non-nil, move backwards trying to
find a symbol if there isn't one at point."
find a symbol if there isn't one at point.
Does not strip the : from keywords, nor attempt to expand :: auto-resolved
keywords."
(or (when-let* ((str (thing-at-point 'symbol)))
;; resolve ns-aliased keywords
(when (string-match-p "^::.+" str)
(setq str (or (ignore-errors (cider-sync-request:macroexpand "macroexpand-1" str)) "")))
(unless (text-property-any 0 (length str) 'field 'cider-repl-prompt str)
;; remove font-locking
(setq str (substring-no-properties str))
Expand Down
8 changes: 3 additions & 5 deletions test/cider-util-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,11 @@ buffer."
(with-clojure-buffer ":abc/foo"
(expect (cider-symbol-at-point) :to-equal ":abc/foo")))

(it "attempts to resolve namespaced keywords"
(spy-on 'cider-sync-request:macroexpand :and-return-value ":foo.bar/abc")
(it "does not attempt to resolve auto-resolved keywords"
(with-clojure-buffer "(ns foo.bar) ::abc"
(expect (cider-symbol-at-point) :to-equal ":foo.bar/abc"))
(spy-on 'cider-sync-request:macroexpand :and-return-value ":clojure.string/abc")
(expect (cider-symbol-at-point) :to-equal "::abc"))
(with-clojure-buffer "(ns foo.bar (:require [clojure.string :as str])) ::str/abc"
(expect (cider-symbol-at-point) :to-equal ":clojure.string/abc"))))
(expect (cider-symbol-at-point) :to-equal "::str/abc"))))

(describe "when there's nothing at point"
(it "returns nil"
Expand Down