Skip to content

Commit 7a83b08

Browse files
Don't pass :same if context string hasn't changed (#3614)
This has been a quite awkward premature optimization that turned up to be unnecessary. The support for it had been broken in Compliment 0.5.1.
1 parent 60c9cea commit 7a83b08

File tree

3 files changed

+20
-18
lines changed

3 files changed

+20
-18
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Bugs fixed
66

77
- [#3605](https://github.com/clojure-emacs/cider/issues/3605): avoid `cider--error-phase-of-last-exception` recursive loop.
8+
- [#3613](https://github.com/clojure-emacs/cider/issues/3613): adapt `cider-completion-context.el` to upstream changes in Compliment.
89

910
## 1.13.0 (2024-01-14)
1011

cider-completion-context.el

+11-17
Original file line numberDiff line numberDiff line change
@@ -96,27 +96,21 @@ form, with symbol at point replaced by __prefix__."
9696
"__prefix__"
9797
(substring context (- pref-end expr-start)))))))
9898

99-
(defvar cider-completion-last-context nil)
100-
10199
(defun cider-completion-get-context (&optional info)
102100
"Extract context depending (maybe of INFO type).
103101
104102
Output depends on `cider-completion-use-context' and the current major mode."
105-
(let ((context (if cider-completion-use-context
106-
;; We use ignore-errors here since grabbing the context
107-
;; might fail because of unbalanced parens, or other
108-
;; technical reasons, yet we don't want to lose all
109-
;; completions and throw error to user because of that.
110-
(or (ignore-errors
111-
(if info
112-
(cider-completion-get-info-context-at-point)
113-
(cider-completion-get-context-at-point)))
114-
"nil")
115-
"nil")))
116-
(if (string= cider-completion-last-context context)
117-
":same"
118-
(setq cider-completion-last-context context)
119-
context)))
103+
(if cider-completion-use-context
104+
;; We use ignore-errors here since grabbing the context
105+
;; might fail because of unbalanced parens, or other
106+
;; technical reasons, yet we don't want to lose all
107+
;; completions and throw error to user because of that.
108+
(or (ignore-errors
109+
(if info
110+
(cider-completion-get-info-context-at-point)
111+
(cider-completion-get-context-at-point)))
112+
"nil")
113+
"nil"))
120114

121115
(provide 'cider-completion-context)
122116
;;; cider-completion-context.el ends here

test/cider-completion-context-tests.el

+8-1
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,11 @@
4545
(it "Returns different things depending on the :info param"
4646
(with-clojure-buffer "user> (.foo|bar \"\")"
4747
(expect (cider-completion-get-context) :to-equal "(__prefix__bar \"\")")
48-
(expect (cider-completion-get-info-context-at-point) :to-equal "(__prefix__ \"\")"))))))
48+
(expect (cider-completion-get-info-context-at-point) :to-equal "(__prefix__ \"\")")))))
49+
50+
(it "Returns the same context when invoked twice at the same place"
51+
(with-clojure-buffer "(ns foo)
52+
53+
(.foo| \"\")"
54+
(expect (cider-completion-get-context) :to-equal "(__prefix__ \"\")")
55+
(expect (cider-completion-get-context) :to-equal "(__prefix__ \"\")"))))

0 commit comments

Comments
 (0)