Skip to content

Commit 3461d78

Browse files
Merge pull request #227 from juergenhoetzel/LSP-part2
Lsp part2
2 parents 7e13a57 + 1cf5bce commit 3461d78

File tree

6 files changed

+59
-10
lines changed

6 files changed

+59
-10
lines changed

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ before_install:
2828
- sudo dpkg -i packages-microsoft-prod.deb
2929
- sudo apt-get update
3030
- sudo apt-get install apt-transport-https
31+
- sudo apt-get update
3132
- sudo apt-get install dotnet-sdk-2.1
3233
- export PATH="$HOME/bin:$PATH"
3334
- export EMACS=$EMACS_VERSION

Makefile

+4-3
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@ build: elpa version
2121
version:
2222
$(EMACS) --version
2323

24-
test/Test1/project.assets.json:
24+
test/Test1/restored:
2525
dotnet restore test/Test1
26+
touch test/Test1/restored
2627

27-
test: version build test/eglot-tests.el test/Test1/project.assets.json
28-
$(CASK) exec buttercup -L . -L ./test
28+
test: version build test/eglot-tests.el test/Test1/restored
29+
$(CASK) exec buttercup -L . -L ./test --traceback full
2930

3031
clean:
3132
rm -f .depend elpa-$(EMACS) $(OBJECTS) $(PKG)-autoloads.el

eglot-fsharp.el

+12
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)

test/Test1/Error.fs

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module Error
2+
3+
let x = nonexisting()
4+

test/Test1/Test1.fsproj

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<Compile Include="Program.fs" />
9+
<Compile Include="Error.fs" />
1010
<Compile Include="FileTwo.fs" />
11+
<Compile Include="Program.fs" />
1112
</ItemGroup>
1213

1314
</Project>

test/integration-tests.el

+36-6
Original file line numberDiff line numberDiff line change
@@ -28,28 +28,58 @@
2828
(require 'eglot-fsharp)
2929
(require 'eglot-tests)
3030

31+
(defun eglot-fsharp--sniff-diagnostics ()
32+
(eglot--sniffing (:server-notifications s-notifs)
33+
(eglot--wait-for (s-notifs 20)
34+
(&key _id method &allow-other-keys)
35+
(string= method "textDocument/publishDiagnostics"))))
36+
3137
(describe "F# LSP server"
3238
(it "Can be installed"
3339
(eglot-fsharp--maybe-install)
3440
(expect (file-exists-p (eglot-fsharp--path-to-server)) :to-be t))
41+
(it "shows flymake errors"
42+
(with-current-buffer (eglot--find-file-noselect "test/Test1/Error.fs")
43+
(eglot--tests-connect 10)
44+
(search-forward "nonexisting")
45+
(flymake-mode t)
46+
(flymake-start)
47+
(goto-char (point-min))
48+
(eglot-fsharp--sniff-diagnostics)
49+
(flymake-goto-next-error 1 '() t)
50+
(expect (face-at-point) :to-be 'flymake-error )))
3551
(it "is enabled on F# Files"
3652
(with-current-buffer (eglot--find-file-noselect "test/Test1/FileTwo.fs")
37-
(eglot--tests-connect 30)
3853
(expect (type-of (eglot--current-server-or-lose)) :to-be 'eglot-fsautocomplete)))
3954
(it "provides completion"
4055
(with-current-buffer (eglot--find-file-noselect "test/Test1/FileTwo.fs")
56+
(eglot-fsharp--sniff-diagnostics)
4157
(expect (plist-get (eglot--capabilities (eglot--current-server-or-lose)) :completionProvider) :not :to-be nil)))
4258
(it "completes function in other modules"
4359
(with-current-buffer (eglot--find-file-noselect "test/Test1/Program.fs")
4460
(search-forward "X.func")
4561
(delete-char -3)
4662
;; ERROR in fsautocomplet.exe? Should block instead of "no type check results"
47-
(eglot--sniffing (:server-notifications s-notifs)
48-
(eglot--wait-for (s-notifs 90)
49-
(&key _id method &allow-other-keys)
50-
(string= method "textDocument/publishDiagnostics")))
63+
(eglot-fsharp--sniff-diagnostics)
5164
(completion-at-point)
52-
(expect (looking-back "X\\.func") :to-be t))))
65+
(expect (looking-back "X\\.func") :to-be t)))
66+
(it "doesn't throw error when definition does not exist"
67+
(with-current-buffer (eglot--find-file-noselect "test/Test1/Program.fs")
68+
(eglot-fsharp--sniff-diagnostics)
69+
(goto-char 253)
70+
(expect (current-word) :to-equal "printfn") ;sanity check
71+
(expect
72+
(condition-case err
73+
(call-interactively #'xref-find-definitions)
74+
(user-error
75+
(cadr err)))
76+
:to-equal "No definitions found for: LSP identifier at point.")))
77+
(it "finds definitions in other files of Project"
78+
(with-current-buffer (eglot--find-file-noselect "test/Test1/Program.fs")
79+
(goto-char 150)
80+
(expect (current-word) :to-equal "NewObjectType") ;sanity check
81+
(call-interactively #'xref-find-definitions)
82+
(expect (file-name-nondirectory (buffer-file-name)) :to-equal "FileTwo.fs"))))
5383

5484
(provide 'integration-tests)
5585
;;; integration-tests.el ends here

0 commit comments

Comments
 (0)