Skip to content

Commit c45f2d9

Browse files
committed
feat: add dart capabilities & refactor server cmd
Lets us track which capabilities the current dart version supports, which will help for version regressions that may be introduced or for deciding what features we can use.
1 parent b59a485 commit c45f2d9

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

lsp-dart.el

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,25 @@ If unspecified, diagnostics will not be generated."
110110
(append (list (file-name-directory (buffer-file-name))) lsp-dart-extra-library-directories)
111111
lsp-dart-extra-library-directories)))
112112

113+
(defun lsp-dart--dart-capabiliities (&optional sdk-root)
114+
"Given an SDK-ROOT, return capabilities for that dart version.
115+
Default to `lsp-dart-get-sdk-dir' if no root is passed.
116+
Returns nil if an invalid SDK-ROOT has been passed."
117+
(when-let* ((root (or sdk-root lsp-dart-sdk-dir (lsp-dart-get-sdk-dir)))
118+
(dart-version (string-trim
119+
(with-temp-buffer
120+
(insert-file-contents (expand-file-name "version" root))
121+
(buffer-string)))))
122+
`((canUseLanguageServer . ,(version<= "3.14.4" dart-version)))))
123+
113124
(defun lsp-dart--server-command ()
114125
"Generate LSP startup command."
115126
(or lsp-dart-server-command
116127
(list (lsp-dart-dart-command)
117-
"language-server"
128+
(if (alist-get 'canUseLanguageServer (lsp-dart--dart-capabiliities))
129+
"language-server"
130+
(expand-file-name "bin/snapshots/analysis_server.dart.snapshot" (lsp-dart-get-sdk-dir))
131+
"--lsp")
118132
"--client-id emacs.lsp-dart"
119133
(format "--client-version %s" lsp-dart-version-string))))
120134

0 commit comments

Comments
 (0)