merlin
merlin copied to clipboard
merlin-construct should include suggestions from available terms that are in-scope and match the requisite type
If I have some code like
type t = T
let x = T
let f T = ()
let z = f _
It would be great if instead of merlin-construct
only offering T
, it also offered x
, because x : t
and is in scope. Maybe the command would need to be renamed since "construct" suggests it operates on constructors specifically, but I think supporting this would make the command much more useful.
We do have something like that implemented in the backend (but not used by the editors plugins). The thing is, on such a simple example it seems straightforward, but having values from the environment can add a lot of clutter to construct's answers in a larger buffer.
But I think it can be worth it to experiment with that. Right now their is no easy way to configure it, but if you can edit Merlin's Emacs plugin you can add this argument to the construct command (line 1462):
(defun merlin--construct-point (point)
"Execute a construct on POINT"
(progn
(ignore point) ; Without this Emacs bytecode compiler complains about an
; unused variable. This may be a bug in the compiler
(let ((result (merlin-call "construct"
+ "-with-values" "local"
"-position" (merlin-unmake-point (point)))))
(when result
(let* ((loc (car result))
(start (cdr (assoc 'start loc)))
(stop (cdr (assoc 'end loc))))
(merlin--construct-complete start stop (cadr result)))))))
Not really about the bug at hand, but this:
(ignore point) ; Without this Emacs bytecode compiler complains about an
; unused variable. This may be a bug in the compiler
is not a bug in the compiler but more likely in the code, which calls the function point
(which returns the current cursor location) but does not use the variable of the same name. (Remember elisp is a 'Lisp-2' with separate namespaces for variables and functions.) Do you remember what this was about?
If you really have an unused parameter in Elisp, prepend its name with an underscore (as in _point
) and the compiler won't complain about it. And next time you suspect an elisp compiler bug, tell us and we'll investigate!
Thanks for your explanation @mattiase. I didn't know that there were separate namespaces for variables and functions.
And next time you suspect an elisp compiler bug, tell us and we'll investigate!
Right, that was a bit presumptuous xD