Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5e54c15

Browse files
xref: Handle missing definitions gracfully
fsautocomplete doesnt follow LSP spec: :textDocument/definition throws an error when no definition is found (instead of returning an empty result).
1 parent 7e13a57 commit 5e54c15

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

eglot-fsharp.el

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,18 @@ Ensure FsAutoComplete is installed (when called INTERACTIVE)."
107107
"Passes through required FsAutoComplete initialization options."
108108
'(:automaticWorkspaceInit t))
109109

110+
;; FIXME: this should be fixed in FsAutocomplete
111+
(cl-defmethod xref-backend-definitions :around ((type symbol) _identifier)
112+
"FsAutoComplete breaks spec and and returns error instead of empty list."
113+
(if (eq major-mode 'fsharp-mode)
114+
(condition-case err
115+
(cl-call-next-method)
116+
(jsonrpc-error
117+
(when (equal (cadddr err) '(jsonrpc-error-message . "Could not find declaration"))
118+
nil)))
119+
(when (cl-next-method-p)
120+
(cl-call-next-method))))
121+
110122
(add-to-list 'eglot-server-programs `(fsharp-mode . eglot-fsharp))
111123

112124
(provide 'eglot-fsharp)

0 commit comments

Comments
 (0)