Skip to content

Changes to cider-symbol-at-point #2826

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 4 commits into from
Mar 28, 2020
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
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@

### Changes

* [#2617](https://github.com/clojure-emacs/cider/pull/2617): Add menu bar entry for `Insert last sexp in REPL and eval` under `CIDER Eval`.
* [#2826](https://github.com/clojure-emacs/cider/pull/2826): Add support for symbols with quotes and resolving of ns-aliased keywords in `cider-symbol-at-point`.

* [#2617](https://github.com/clojure-emacs/cider/pull/2617): Add menu bar entry for `Insert last sexp in REPL

### Bugs fixed

Expand Down
8 changes: 6 additions & 2 deletions cider-util.el
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
(require 'cider-compat)
(require 'clojure-mode)
(require 'nrepl-dict)
(declare-function cider-sync-request:macroexpand "cider-macroexpansion")

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

Expand Down Expand Up @@ -128,9 +129,12 @@ instead."
Ignores the REPL prompt. If LOOK-BACK is non-nil, move backwards trying to
find a symbol if there isn't one at point."
(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 and trailing . from constructors like Record.
(string-remove-suffix "." (substring-no-properties str))))
;; Remove font-locking, prefix quotes, and trailing . from constructors like Record.
(string-remove-prefix "'" (string-remove-suffix "." (substring-no-properties str)))))
(when look-back
(save-excursion
(ignore-errors
Expand Down
20 changes: 20 additions & 0 deletions test/cider-util-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,26 @@ buffer."
(with-clojure-buffer "SomeRecord."
(expect (cider-symbol-at-point) :to-equal "SomeRecord"))))

(describe "when the symbol at point is quoted"
(it "returns the symbol without the preceding '"
(with-clojure-buffer "'foo'bar"
(expect (cider-symbol-at-point) :to-equal "foo'bar"))))

(describe "when point is on a keyword"
(it "returns the keyword along with beginning : character"
(with-clojure-buffer ":abc"
(expect (cider-symbol-at-point) :to-equal ":abc"))
(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")
(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")
(with-clojure-buffer "(ns foo.bar (:require [clojure.string :as str])) ::str/abc"
(expect (cider-symbol-at-point) :to-equal ":clojure.string/abc"))))

(describe "when there's nothing at point"
(it "returns nil"
(spy-on 'thing-at-point :and-return-value nil)
Expand Down