File tree Expand file tree Collapse file tree 4 files changed +39
-19
lines changed
Expand file tree Collapse file tree 4 files changed +39
-19
lines changed Original file line number Diff line number Diff line change @@ -90,10 +90,11 @@ Used by features that needs to know project entrypoint like DAP support."
9090 (eq lsp-dart--project-type-cache 'flutter )
9191 (let ((flutter-project? (or (-when-let (pubspec-path (-some->> (lsp-dart-get-project-root)
9292 (expand-file-name " pubspec.yaml" )))
93- (with-temp-buffer
94- (insert-file-contents (-some->> (lsp-dart-get-project-root) (expand-file-name " pubspec.yaml" )))
95- (goto-char (point-min ))
96- (re-search-forward " sdk\s *:\s *flutter" nil t )))
93+ (when (file-exists-p pubspec-path)
94+ (with-temp-buffer
95+ (insert-file-contents (-some->> (lsp-dart-get-project-root) (expand-file-name " pubspec.yaml" )))
96+ (goto-char (point-min ))
97+ (re-search-forward " sdk\s *:\s *flutter" nil t ))))
9798 (lsp-dart--flutter-repo-p))))
9899 (lsp-dart--set-project-type-cache flutter-project?)
99100 flutter-project?) ))
@@ -144,7 +145,8 @@ FLUTTER_ROOT environment variable."
144145 (let* ((command (lsp-dart--executable-find " dart" (lsp-dart-get-sdk-dir))))
145146 (if command
146147 command
147- (lsp-dart-log " Dart command not found in path '%s'" command))))
148+ (lsp-dart-log " Dart command not found in path '%s'" command)
149+ nil )))
148150
149151(defun lsp-dart-pub-command ()
150152 " Return the pub executable path from Dart SDK path."
Original file line number Diff line number Diff line change @@ -110,14 +110,20 @@ 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 ()
114+ " Return capabilities for current dart version."
115+ `((canUseLanguageServer . ,(lsp-dart-version-at-least-p " 2.14.4" ))))
116+
113117(defun lsp-dart--server-command ()
114118 " Generate LSP startup command."
115119 (or lsp-dart-server-command
116- (list (lsp-dart-dart-command)
117- (expand-file-name (f-join (lsp-dart-get-sdk-dir) " bin/snapshots/analysis_server.dart.snapshot" ))
118- " --lsp"
119- " --client-id emacs.lsp-dart"
120- (format " --client-version %s " lsp-dart-version-string))))
120+ `(,(lsp-dart-dart-command)
121+ ,@(if (alist-get 'canUseLanguageServer (lsp-dart--dart-capabiliities))
122+ (list " language-server" )
123+ (list (expand-file-name " bin/snapshots/analysis_server.dart.snapshot" (lsp-dart-get-sdk-dir))
124+ " --lsp" ))
125+ " --client-id emacs.lsp-dart"
126+ ,(format " --client-version %s " lsp-dart-version-string))))
121127
122128(defun lsp-dart--activate-features ()
123129 " Activate lsp-dart features if enabled."
Original file line number Diff line number Diff line change 5454
5555(ert-deftest lsp-dart--server-command--default-test ()
5656 (with-mock
57- (stub lsp-dart-dart-command => " /sdk/bin/dart" )
58- (stub lsp-dart-get-sdk-dir => " /sdk" )
59- (should (equal (lsp-dart--server-command)
60- `(" /sdk/bin/dart"
61- ,(f-expand " /sdk/bin/snapshots/analysis_server.dart.snapshot" (f-root))
62- " --lsp"
63- " --client-id emacs.lsp-dart"
64- ,(concat " --client-version " lsp-dart-version-string))))))
57+ (stub lsp-dart-dart-command => " /sdk/bin/dart" )
58+ (stub lsp-dart-get-sdk-dir => " /sdk" )
59+ (stub lsp-dart-get-dart-version => " 2.14.1" )
60+ (should (equal (lsp-dart--server-command)
61+ `(" /sdk/bin/dart"
62+ ,(f-expand " /sdk/bin/snapshots/analysis_server.dart.snapshot" (f-root))
63+ " --lsp"
64+ " --client-id emacs.lsp-dart"
65+ ,(concat " --client-version " lsp-dart-version-string))))))
66+
67+ (ert-deftest lsp-dart--server-command--lsp-test ()
68+ (with-mock
69+ (stub lsp-dart-dart-command => " /sdk/bin/dart" )
70+ (stub lsp-dart-get-sdk-dir => " /sdk" )
71+ (stub lsp-dart-get-dart-version => " 2.14.4" )
72+ (should (equal (lsp-dart--server-command)
73+ `(" /sdk/bin/dart"
74+ " language-server"
75+ " --client-id emacs.lsp-dart"
76+ ,(concat " --client-version " lsp-dart-version-string))))))
6577
6678(ert-deftest lsp-dart-version--test ()
6779 (with-mock
Original file line number Diff line number Diff line change 3232(ert-deftest lsp-dart--flutter-repo-p--not-flutter-executable-test ()
3333 (with-mock
3434 (mock (locate-dominating-file * " flutter" ) => " /not-sdk/bin" )
35- (mock ( file-regular-p " /sdk/bin/flutter " ) => nil )
35+ (stub file-regular-p => nil )
3636 (should-not (lsp-dart--flutter-repo-p))))
3737
3838(ert-deftest lsp-dart--flutter-repo-p--not-flutter-executable-test ()
You can’t perform that action at this time.
0 commit comments