Skip to content

Commit c66a7eb

Browse files
committed
assert version on tree features
1 parent 0128e74 commit c66a7eb

File tree

1 file changed

+38
-18
lines changed

1 file changed

+38
-18
lines changed

lsp-dart.el

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,12 @@
2727
(require 'ht)
2828
(require 'f)
2929
(require 'dash)
30-
(require 'lsp-mode)
3130
(require 'lsp-treemacs)
3231

32+
(require 'lsp-mode)
33+
34+
(defconst lsp-dart-tests-buffer-name "*LSP Dart tests*")
35+
3336
(defgroup lsp-dart nil
3437
"LSP support for Dart, using dart analysis server."
3538
:prefix "lsp-dart-"
@@ -125,17 +128,33 @@ Defaults to side following treemacs default."
125128

126129
;;; Internal
127130

128-
(defun lsp-dart--find-sdk-dir ()
129-
"Find dart sdk by searching for dart executable or flutter cache dir."
130-
(-when-let (dart (or (executable-find "dart")
131-
(-when-let (flutter (-> lsp-dart-flutter-command
132-
executable-find
133-
file-truename))
134-
(expand-file-name "cache/dart-sdk/bin/dart"
135-
(file-name-directory flutter)))))
136-
(-> dart
137-
file-truename
138-
(locate-dominating-file "bin"))))
131+
(defun lsp-dart--get-sdk-dir ()
132+
"Return the dart sdk.
133+
Check for `lsp-dart-sdk-dir` otherwise search for dart executable or
134+
flutter cache dir."
135+
(or lsp-dart-sdk-dir
136+
(-when-let (dart (or (executable-find "dart")
137+
(-when-let (flutter (-> lsp-dart-flutter-command
138+
executable-find
139+
file-truename))
140+
(expand-file-name "cache/dart-sdk/bin/dart"
141+
(file-name-directory flutter)))))
142+
(-> dart
143+
file-truename
144+
(locate-dominating-file "bin")))))
145+
146+
(defun lsp-dart--get-dart-version ()
147+
"Retrieve the dart version from shell command."
148+
(->> (concat (lsp-dart--get-sdk-dir) "bin/dart --version")
149+
shell-command-to-string
150+
split-string
151+
(nth 3)))
152+
153+
(defun lsp-dart--assert-sdk-min-version (version)
154+
"Assert dart sdk min version is VERSION."
155+
(cl-assert (string-prefix-p version (lsp-dart--get-dart-version))
156+
t
157+
"Feature not supported before dart SDK %s"))
139158

140159
(defun lsp-dart--outline-kind->icon (kind)
141160
"Maps an outline KIND to a treemacs icon symbol.
@@ -297,7 +316,7 @@ It updates the Flutter outline view if it already exists."
297316
(defun lsp-dart--server-command ()
298317
"Generate LSP startup command."
299318
(or lsp-dart-server-command
300-
(let ((sdk-dir (or lsp-dart-sdk-dir (lsp-dart--find-sdk-dir))))
319+
(let ((sdk-dir (lsp-dart--get-sdk-dir)))
301320
`(,(expand-file-name (f-join sdk-dir "bin/dart"))
302321
,(expand-file-name (f-join sdk-dir "bin/snapshots/analysis_server.dart.snapshot"))
303322
"--lsp"))))
@@ -383,10 +402,9 @@ IGNORE-CASE is a optional arg to ignore the case sensitive on regex search."
383402
"Build the dart or flutter build command.
384403
If the given BUFFER is a flutter test file, return the flutter command
385404
otherwise the dart command."
386-
(let ((sdk-dir (or lsp-dart-sdk-dir (lsp-dart--find-sdk-dir))))
387-
(if (lsp-dart--test-flutter-test-file-p buffer)
388-
lsp-dart-flutter-command
389-
(concat (file-name-as-directory sdk-dir) "bin/pub run"))))
405+
(if (lsp-dart--test-flutter-test-file-p buffer)
406+
lsp-dart-flutter-command
407+
(concat (file-name-as-directory (lsp-dart--get-sdk-dir)) "bin/pub run")))
390408

391409
(defun lsp-dart--build-test-name (names)
392410
"Build the test name from a group of test NAMES."
@@ -426,7 +444,7 @@ from NAMES."
426444
(or test-arg "")
427445
test-file)
428446
t
429-
(lambda (_) "*LSP Dart tests*")))))
447+
(lambda (_) lsp-dart-tests-buffer-name)))))
430448

431449
(defun lsp-dart--build-test-overlay (buffer names kind range test-range)
432450
"Build an overlay for a test NAMES of KIND in BUFFER file.
@@ -489,12 +507,14 @@ PARAMS is the notification data from outline."
489507
(defun lsp-dart-show-outline (ignore-focus?)
490508
"Show an outline tree and focus on it if IGNORE-FOCUS? is nil."
491509
(interactive "P")
510+
(lsp-dart--assert-sdk-min-version "2.8.0")
492511
(lsp-dart--show-outline ignore-focus?))
493512

494513
;;;###autoload
495514
(defun lsp-dart-show-flutter-outline (ignore-focus?)
496515
"Show a Flutter outline tree and focus on it if IGNORE-FOCUS? is nil."
497516
(interactive "P")
517+
(lsp-dart--assert-sdk-min-version "2.8.0")
498518
(lsp-dart--show-flutter-outline ignore-focus?))
499519

500520
;;;###autoload

0 commit comments

Comments
 (0)