@@ -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
0 commit comments