Skip to content

Commit 7868b87

Browse files
authored
Merge pull request #172 from shivjm/improve-windows-support
Allow `.exe` executables on Windows
2 parents 64c93a0 + 3f06917 commit 7868b87

File tree

4 files changed

+29
-18
lines changed

4 files changed

+29
-18
lines changed

lsp-dart-utils.el

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ Used by features that needs to know project entrypoint like DAP support."
6565

6666
(defvar-local lsp-dart--project-type-cache nil)
6767

68+
(defvar lsp-dart--executable-suffixes (if (eq system-type 'windows-nt)
69+
'(".exe" ".bat")
70+
'("")))
71+
6872
(defun lsp-dart--set-project-type-cache (flutter?)
6973
"Update project type cache checking FLUTTER?."
7074
(if flutter?
@@ -137,34 +141,34 @@ FLUTTER_ROOT environment variable."
137141

138142
(defun lsp-dart-dart-command ()
139143
"Return the dart executable from Dart SDK dir."
140-
(let* ((executable-path (if (eq system-type 'windows-nt) "bin/dart.bat" "bin/dart"))
141-
(command (expand-file-name executable-path (lsp-dart-get-sdk-dir))))
142-
(if (file-exists-p command)
144+
(let* ((command (lsp-dart--executable-find "dart" (lsp-dart-get-sdk-dir))))
145+
(if command
143146
command
144147
(lsp-dart-log "Dart command not found in path '%s'" command))))
145148

146149
(defun lsp-dart-pub-command ()
147150
"Return the pub executable path from Dart SDK path."
148151
(if (lsp-dart-version-at-least-p "2.16.0")
149152
(list (lsp-dart-dart-command) "pub")
150-
(if (eq system-type 'windows-nt)
151-
(list (expand-file-name "bin/pub.bat" (lsp-dart-get-sdk-dir)))
152-
(list (expand-file-name "bin/pub" (lsp-dart-get-sdk-dir))))))
153+
(list (lsp-dart--executable-find "pub" (lsp-dart-get-sdk-dir)))))
153154

154155
(defun lsp-dart-pub-snapshot-command ()
155156
"Return the pub snapshot executable path from Dart SDK path."
156157
(expand-file-name "bin/snapshots/pub.dart.snapshot" (lsp-dart-get-sdk-dir)))
157158

158159
(defun lsp-dart-flutter-command ()
159160
"Return the flutter executable from Flutter SDK dir."
160-
(let* ((executable-path (if (eq system-type 'windows-nt)
161-
"bin/flutter.bat"
162-
(concat "bin/" lsp-dart-flutter-executable)))
163-
(command (expand-file-name executable-path (lsp-dart-get-flutter-sdk-dir))))
164-
(if (file-exists-p command)
161+
(let ((command (lsp-dart--executable-find lsp-dart-flutter-executable (lsp-dart-get-flutter-sdk-dir))))
162+
(if command
165163
(list command)
166164
(lsp-dart-log "Flutter command not found in path '%s'" command))))
167165

166+
(defun lsp-dart--executable-find (name dir)
167+
"Find an executable named `name' in `dir'."
168+
(let* ((bin-dir (expand-file-name "bin" dir))
169+
(candidates (--map (expand-file-name (concat name it) bin-dir) lsp-dart--executable-suffixes)))
170+
(-find #'file-regular-p candidates)))
171+
168172

169173
;; Project
170174

test/fixtures/dart-sdk/bin/pub

Whitespace-only changes.

test/fixtures/dart-sdk/bin/pub.exe

Whitespace-only changes.

test/lsp-dart-utils-test.el

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
(ert-deftest lsp-dart--flutter-repo-p--true-test ()
2626
(with-mock
2727
(mock (locate-dominating-file * "flutter") => "/sdk/bin")
28-
(mock (file-regular-p (f-join (f-root) "/sdk/bin/flutter")) => t)
29-
(mock (file-directory-p (f-join (f-root) "/sdk/bin/cache/dart-sdk")) => t)
28+
(mock (file-regular-p (f-join (f-root) "sdk/bin/flutter")) => t)
29+
(mock (file-directory-p (f-join (f-root) "sdk/bin/cache/dart-sdk")) => t)
3030
(should (lsp-dart--flutter-repo-p))))
3131

3232
(ert-deftest lsp-dart--flutter-repo-p--not-flutter-executable-test ()
@@ -38,8 +38,8 @@
3838
(ert-deftest lsp-dart--flutter-repo-p--not-flutter-executable-test ()
3939
(with-mock
4040
(mock (locate-dominating-file * "flutter") => "/not-sdk/bin")
41-
(mock (file-regular-p (f-join (f-root) "/not-sdk/bin/flutter")) => t)
42-
(mock (file-directory-p (f-join (f-root) "/not-sdk/bin/cache/dart-sdk")) => nil)
41+
(mock (file-regular-p (f-join (f-root) "not-sdk/bin/flutter")) => t)
42+
(mock (file-directory-p (f-join (f-root) "not-sdk/bin/cache/dart-sdk")) => nil)
4343
(should-not (lsp-dart--flutter-repo-p))))
4444

4545
(ert-deftest lsp-dart-flutter-project-p--flutter-repo-test ()
@@ -73,7 +73,7 @@
7373

7474
(ert-deftest lsp-dart-get-sdk-dir--flutter-project-test ()
7575
(let ((dart-sdk (if (eq system-type 'windows-nt)
76-
(f-join (f-root) "/flutter-sdk/bin/cache/dart-sdk/")
76+
(f-join (f-root) "flutter-sdk/bin/cache/dart-sdk/")
7777
"/flutter-sdk/bin/cache/dart-sdk/")))
7878
(lsp-dart-test-from-flutter-project
7979
(mock (lsp-dart-flutter-project-p) => t)
@@ -108,12 +108,19 @@
108108
(ert-deftest lsp-dart-pub-command--old-version-test ()
109109
(lsp-dart-test-with-dart-sdk
110110
(mock (lsp-dart-get-dart-version) => "2.15.5")
111-
(should (equal (lsp-dart-pub-command) (list (f-expand "bin/pub" dart-sdk))))))
111+
(should (equal (lsp-dart-pub-command) (list (f-expand (if (eq system-type 'windows-nt)
112+
"bin/pub.exe"
113+
"bin/pub")
114+
dart-sdk))))))
112115

113116
(ert-deftest lsp-dart-pub-command--new-version-test ()
114117
(lsp-dart-test-with-dart-sdk
115118
(mock (lsp-dart-get-dart-version) => "2.16.0")
116-
(should (equal (lsp-dart-pub-command) (list (f-expand "bin/dart" dart-sdk) "pub")))))
119+
(should (equal (lsp-dart-pub-command) (list (f-expand (if (eq system-type 'windows-nt)
120+
"bin/dart.bat"
121+
"bin/dart")
122+
dart-sdk)
123+
"pub")))))
117124

118125
(ert-deftest lsp-dart-pub-snapshot-command--test ()
119126
(lsp-dart-test-with-dart-sdk

0 commit comments

Comments
 (0)