summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelicián Németh <felician.nemeth@gmail.com>2024-08-18 12:06:01 +0200
committerFelicián Németh <felician.nemeth@gmail.com>2024-08-18 12:06:01 +0200
commit650a6c694e01a5b85747293def435c80b4682846 (patch)
tree4f5182d14898a152d1f646f941ab192d68b8c004
parent7bdfd266b7ab9c7e052a2743a0f53ab529191f7d (diff)
Add command to find typed holes (Ocaml-LSP)
Since flymake also lists the locations of the typed holes, this does not seem extremely useful. * eglot-x.el (eglot-x-find-typed-holes): New command. (eglot-x-menu): Append the new command to it.
-rw-r--r--eglot-x.el39
1 files changed, 38 insertions, 1 deletions
diff --git a/eglot-x.el b/eglot-x.el
index 02480e2..e7dbea9 100644
--- a/eglot-x.el
+++ b/eglot-x.el
@@ -352,7 +352,11 @@ connections."
:name))
["Show info about associated schema" eglot-x-taplo-show-associated-schema]
["Find associated schema" eglot-x-taplo-find-associated-schema]
- ["List schemas" eglot-x-taplo-list-schemas])))
+ ["List schemas" eglot-x-taplo-list-schemas])
+ ;; OCaml-LSP commands
+ ["Find typed holes" eglot-x-find-typed-holes
+ :visible (eglot-server-capable
+ :experimental :ocamllsp :handleTypedHoles)]))
(cl-defmethod eglot-client-capabilities :around
(_s)
@@ -2414,5 +2418,38 @@ Use `browse-url' for non-local schemas."
(find-file-noselect related-file) ; See Emacs bug#57325.
related-files)))))
+(defun eglot-x-find-typed-holes ()
+ "Find typed holes for the current buffer using ocaml-lsp.
+See URL `https://github.com/ocaml/ocaml-lsp/blob/master/ocaml-lsp-server/docs/ocamllsp/typedHoles-spec.md'"
+ (interactive)
+ (eglot-server-capable-or-lose :experimental :ocamllsp :handleTypedHoles)
+ (let* ((server (eglot--current-server-or-lose))
+ (tdi (eglot--TextDocumentIdentifier))
+ (uri (plist-get tdi :uri))
+ (res (jsonrpc-request server :ocamllsp/typedHoles tdi))
+ (xrefs
+ (mapcar (lambda (range)
+ (eglot--xref-make-match "typed hole" uri range))
+ res))
+ (xref-show-xrefs-function xref-show-definitions-function)
+ prev-xref prev-line)
+ ;; Ajust summaries when multiple xref items are on the same line.
+ ;; Assume the server sends the ranges sorted.
+ (dolist (xref xrefs)
+ (let* ((loc (xref-item-location xref))
+ (curr-line (xref-location-line loc))
+ (curr-postfix (substring (xref-item-summary xref)
+ (xref-file-location-column loc))))
+ (when (eq prev-line curr-line)
+ (oset xref summary curr-postfix)
+ (oset prev-xref summary (substring (xref-item-summary prev-xref)
+ 0
+ (* -1 (length curr-postfix)))))
+ (setq prev-xref xref
+ prev-line curr-line)))
+ (if xrefs
+ (xref-show-xrefs xrefs nil)
+ (user-error "[eglot-x] Can't find typed holes"))))
+
(provide 'eglot-x)
;;; eglot-x.el ends here