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
auto-completion of java method names for global symbols in repl buffer not working #2528
Comments
The completion middleware and completion library itself seem to work correctly, as
|
Looking at this code (which extract the context), seem to suggest that it is not foreseen to work in the situation of above (completing a global var in the repl) (defun cider-completion-get-context-at-point ()
"Extract the context at point.
If point is not inside the list, returns nil; otherwise return \"top-level\"
form, with symbol at point replaced by __prefix__."
(when (save-excursion
(condition-case _
(progn
(up-list)
(check-parens)
t)
(scan-error nil)
(user-error nil)))
(save-excursion
(let* ((pref-end (point))
(pref-start (cider-completion-symbol-start-pos))
(context (cider-defun-at-point))
(_ (beginning-of-defun))
(expr-start (point)))
(concat (when pref-start (substring context 0 (- pref-start expr-start)))
"__prefix__"
(substring context (- pref-end expr-start)))))))
(defun cider-completion-get-context ()
"Extract context depending on `cider-completion-use-context' and major mode."
(let ((context (if (and cider-completion-use-context
;; Important because `beginning-of-defun' and
;; `ending-of-defun' work incorrectly in the REPL
;; buffer, so context extraction fails there.
(derived-mode-p 'clojure-mode))
(or (cider-completion-get-context-at-point)
"nil")
"nil")))
(message "context: %s " context)
(if (string= cider-completion-last-context context)
":same"
(setq cider-completion-last-context context)
context))) I work very much repl-first style, so basically all my code gets created in the repl and the copied to clojure files. So for me a very well working completion in the repl would be very useful, specially in java inter op scenarios. It is clear that extracting the correct "context" for compliment to work, can be challenging. |
Ah, yes, that's true it is not supposed to work in the REPL buffer. I wrote that code originally, and my assumption was that code in the REPL buffer would most often not be a complete Clojure form for context to parse it (bacause people usually don't enable Paredit there). Another way to tackle this would be to somehow solve alexander-yakushev/compliment#53. |
I am just realizing that is does work in a clojure file.... I need to confess, that I did not realize so far, that most of what I do in the repl, I could do in a clojure file. And I have paredit in the repl enabled. Why would people not do so ? My workflow so far was "repl buffer" focused. So I edited code in repl buffer and copy pasted it then into clojure files, when it worked. I start to see only now, that I could work by starting with global vars in a clj file and move them then into methods, without hardly using the repl buffer |
Well, nobody tries to enforce any particular workflow, and your approach is completely fine; yet indeed, writing and evaluating code in the buffer directly is usually much more convenient :).
Yeah, avoiding copy-pasting code is the primary reason why many developers develop and evaluate the code in Clojure code buffers. It's incredibly cool when you try it!
Last time I looked at that (and that was some long time ago), Paredit was confused by the REPL's |
Ok, I made some more tests. The completion action always the same "network" is a global var defined in the namespace I am "in". The buffer types which I tried where
so I excepted the same completions. But I got different results. I got different results and had a hard time to understand, what they depend on. Being in the cider scratch pad or the repl, did typically not work UNLESS Sometimes it did not work, but I had a hard time to reproduce it.
The moment I type once the import: it started to work for that current name space. Hhmm. I tried more stuff... There is somewhere an edge case of mixing:
where I end in a situations where a var is defined, but the completion does not work.
In the first two it mostly works, I would say. |
I found one reproducible szenario which does not work.
evaluate:
Here the completion does not work. Now, after having imported the class, it will work on the same var:
From "now on" I can create new vars either with the full qualified name or the class name only, So the completion depends somehow on the "state" of the ns, |
I could verify the same behavior with compliment.sources.class-members/members-candidates Should we move the discusion there ? It seems to be related to the import caching done in "populate-members-cache", In my case, the "import" is not in the ns-map, as I use a full qualified class name to create the object. |
Yes, the class member completion is not expected to work at all unless the class is imported. It can be made to work in case when context with a global Var is available; but I haven't gotten to that yet. |
There was also a bug in caching imported classes which I fixed only yesterday, and it is not in CIDER yet. |
Should this maybe be documented ? I would think that via reflection we can get the required information, independent of the class being imported or not. That it depends as well on the state of the name space is unexpected. I changed as well the title of this issue.
|
I'd rather not document it but added this is a feature. I'll try that sometime soon. |
Great ! |
Is it possible to make CIDER completion work for two dots (.. (java.util.Date.) |toString (|endsWith "2019")) Here is an example where |
Expected behavior
From the "compliment" documentation it should work to auto complete the methods of a var precisely
(meaning that it shows only applicable methods, which can be called on the object)
https://camo.githubusercontent.com/2739aa5c45d1f82542d9bc2c9e1f0433f94c9f44/68747470733a2f2f7261772e6769746875622e636f6d2f616c6578616e6465722d79616b75736865762f636f6d706c696d656e742f6d61737465722f646f632f696d616765732f6d656d6265722d636f6e746578742e706e67
Actual behavior
It shows a far longer list of possible methods, most completely irrelevant to the object
see screenshot
Steps to reproduce the problem
The following code in the repl should be able to autocomplete all applicable methods for java.lang.String and nothing more
(where | is the cursor position)
Instead it will list far more methods.
The tests of the "compliment" library suggest that this is supported:
https://github.com/alexander-yakushev/compliment/blob/558ccac9e46c39ad512ec200d175b9dc73547b5b/test/compliment/t_core.clj#L66
The text was updated successfully, but these errors were encountered: