Skip to content

Commit a8939d6

Browse files
committed
Fix find definition of external files on Flutter, not asking for project root anymore
1 parent 33455a4 commit a8939d6

File tree

4 files changed

+20
-16
lines changed

4 files changed

+20
-16
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
* Fix `lsp-dart-run` when default-directory is not the project root. #173
66
* Add `lsp-dart-project-root-discovery-strategies` variable to search project root with different startegies and orders.
7+
* Fix find definition of external files on Flutter, not asking for project root anymore.
78

89
## 1.22.2
910

lsp-dart-utils.el

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
;;; Code:
2323

2424
(require 'dash)
25+
(require 'f)
2526
(require 'lsp-mode)
2627

2728
(defcustom lsp-dart-sdk-dir nil
@@ -87,11 +88,12 @@ Order is important."
8788

8889
(defun lsp-dart--flutter-repo-p ()
8990
"Return non-nil if buffer is the flutter repository."
90-
(if-let (bin-path (locate-dominating-file default-directory lsp-dart-flutter-executable))
91-
(and (file-regular-p (expand-file-name lsp-dart-flutter-executable bin-path))
92-
(->> bin-path
93-
(expand-file-name "cache/dart-sdk")
94-
file-directory-p))))
91+
(let ((bin-command (f-join "bin" lsp-dart-flutter-executable)))
92+
(when-let (root-path (locate-dominating-file default-directory bin-command))
93+
(and (file-regular-p (expand-file-name bin-command root-path))
94+
(->> root-path
95+
(expand-file-name (f-join "bin" "cache" "dart-sdk"))
96+
file-directory-p)))))
9597

9698
(defun lsp-dart-flutter-project-p ()
9799
"Return non-nil if buffer is a flutter project."
@@ -119,12 +121,12 @@ Order is important."
119121
list))
120122

121123
(defun lsp-dart-flutter-snap-install-p ()
122-
;; Detecting whether this is a Linux system with a Snap style install
124+
"Detecting whether this is a Linux system with a Snap style install."
123125
(and (string= system-type "gnu/linux")
124126
(let ((first-dir (-some-> (executable-find lsp-dart-flutter-executable) f-split cdr car)))
125-
(and first-dir
126-
(string= first-dir "snap")
127-
(file-exists-p "~/snap/flutter/common/flutter/bin/flutter")))))
127+
(and first-dir
128+
(string= first-dir "snap")
129+
(file-exists-p "~/snap/flutter/common/flutter/bin/flutter")))))
128130

129131

130132
;; SDKs

lsp-dart.el

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ If unspecified, diagnostics will not be generated."
106106
(let ((sdk-root (if (lsp-dart-flutter-project-p)
107107
(lsp-dart-get-flutter-sdk-dir)
108108
(lsp-dart-get-sdk-dir))))
109-
(if (string-prefix-p sdk-root (buffer-file-name))
109+
(if (or (string-prefix-p sdk-root (buffer-file-name))
110+
(lsp-dart--flutter-repo-p))
110111
(append (list (file-name-directory (buffer-file-name))) lsp-dart-extra-library-directories)
111112
lsp-dart-extra-library-directories)))
112113

test/lsp-dart-utils-test.el

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,22 @@
2222
(require 'lsp-dart-utils)
2323
(require 'el-mock)
2424

25-
(ert-deftest lsp-dart--flutter-repo-p--true-test ()
25+
(ert-deftest lsp-dart--flutter-repo-p--on-flutter-project-root-test ()
2626
(with-mock
27-
(mock (locate-dominating-file * "flutter") => "/sdk/bin")
27+
(mock (locate-dominating-file * (f-join "bin" "flutter")) => (f-join (f-root) "sdk"))
2828
(mock (file-regular-p (f-join (f-root) "sdk/bin/flutter")) => t)
2929
(mock (file-directory-p (f-join (f-root) "sdk/bin/cache/dart-sdk")) => t)
3030
(should (lsp-dart--flutter-repo-p))))
3131

32-
(ert-deftest lsp-dart--flutter-repo-p--not-flutter-executable-test ()
32+
(ert-deftest lsp-dart--flutter-repo-p--not-flutter-executable-1-test ()
3333
(with-mock
34-
(mock (locate-dominating-file * "flutter") => "/not-sdk/bin")
34+
(mock (locate-dominating-file * (f-join "bin" "flutter")) => "/not-sdk")
3535
(stub file-regular-p => nil)
3636
(should-not (lsp-dart--flutter-repo-p))))
3737

38-
(ert-deftest lsp-dart--flutter-repo-p--not-flutter-executable-test ()
38+
(ert-deftest lsp-dart--flutter-repo-p--not-flutter-executable-2-test ()
3939
(with-mock
40-
(mock (locate-dominating-file * "flutter") => "/not-sdk/bin")
40+
(mock (locate-dominating-file * (f-join "bin" "flutter")) => "/not-sdk")
4141
(mock (file-regular-p (f-join (f-root) "not-sdk/bin/flutter")) => t)
4242
(mock (file-directory-p (f-join (f-root) "not-sdk/bin/cache/dart-sdk")) => nil)
4343
(should-not (lsp-dart--flutter-repo-p))))

0 commit comments

Comments
 (0)