Skip to content

[completion] Don't pass :same if context string hasn't changed #3614

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 1 commit into from
Jan 29, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Bugs fixed

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

## 1.13.0 (2024-01-14)

Expand Down
28 changes: 11 additions & 17 deletions cider-completion-context.el
Original file line number Diff line number Diff line change
Expand Up @@ -96,27 +96,21 @@ form, with symbol at point replaced by __prefix__."
"__prefix__"
(substring context (- pref-end expr-start)))))))

(defvar cider-completion-last-context nil)

(defun cider-completion-get-context (&optional info)
"Extract context depending (maybe of INFO type).

Output depends on `cider-completion-use-context' and the current major mode."
(let ((context (if cider-completion-use-context
;; We use ignore-errors here since grabbing the context
;; might fail because of unbalanced parens, or other
;; technical reasons, yet we don't want to lose all
;; completions and throw error to user because of that.
(or (ignore-errors
(if info
(cider-completion-get-info-context-at-point)
(cider-completion-get-context-at-point)))
"nil")
"nil")))
(if (string= cider-completion-last-context context)
":same"
(setq cider-completion-last-context context)
context)))
(if cider-completion-use-context
;; We use ignore-errors here since grabbing the context
;; might fail because of unbalanced parens, or other
;; technical reasons, yet we don't want to lose all
;; completions and throw error to user because of that.
(or (ignore-errors
(if info
(cider-completion-get-info-context-at-point)
(cider-completion-get-context-at-point)))
"nil")
"nil"))

(provide 'cider-completion-context)
;;; cider-completion-context.el ends here
9 changes: 8 additions & 1 deletion test/cider-completion-context-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,11 @@
(it "Returns different things depending on the :info param"
(with-clojure-buffer "user> (.foo|bar \"\")"
(expect (cider-completion-get-context) :to-equal "(__prefix__bar \"\")")
(expect (cider-completion-get-info-context-at-point) :to-equal "(__prefix__ \"\")"))))))
(expect (cider-completion-get-info-context-at-point) :to-equal "(__prefix__ \"\")")))))

(it "Returns the same context when invoked twice at the same place"
(with-clojure-buffer "(ns foo)

(.foo| \"\")"
(expect (cider-completion-get-context) :to-equal "(__prefix__ \"\")")
(expect (cider-completion-get-context) :to-equal "(__prefix__ \"\")"))))