Skip to content

Commit 83fbaf6

Browse files
committed
Check for project type before handling flutter notifications
Fixes #89 #88
1 parent 8180a46 commit 83fbaf6

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

lsp-dart-utils.el

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ Useful if multiple Flutter installations are present."
5151

5252
;; Internal
5353

54+
(defvar-local lsp-dart--project-type-cache nil)
55+
56+
(defun lsp-dart--set-project-type-cache (flutter?)
57+
"Update project type cache checking FLUTTER?."
58+
(if flutter?
59+
(setq lsp-dart--project-type-cache 'flutter)
60+
(setq lsp-dart--project-type-cache 'dart))
61+
flutter?)
62+
5463
(defun lsp-dart--flutter-repo-p ()
5564
"Return non-nil if buffer is the flutter repository."
5665
(if-let (bin-path (locate-dominating-file default-directory lsp-dart-flutter-executable))
@@ -61,13 +70,17 @@ Useful if multiple Flutter installations are present."
6170

6271
(defun lsp-dart--flutter-project-p ()
6372
"Return non-nil if buffer is a flutter project."
64-
(or (lsp-dart--flutter-repo-p)
65-
(-when-let (pubspec-path (-some->> (lsp-dart-get-project-root)
66-
(expand-file-name "pubspec.yaml")))
67-
(with-temp-buffer
68-
(insert-file-contents pubspec-path)
69-
(goto-char (point-min))
70-
(re-search-forward "sdk\s*:\s*flutter" nil t)))))
73+
(if lsp-dart--project-type-cache
74+
(eq lsp-dart--project-type-cache 'flutter)
75+
(let ((flutter-project? (or (-when-let (pubspec-path (-some->> (lsp-dart-get-project-root)
76+
(expand-file-name "pubspec.yaml")))
77+
(with-temp-buffer
78+
(insert-file-contents pubspec-path)
79+
(goto-char (point-min))
80+
(re-search-forward "sdk\s*:\s*flutter" nil t)))
81+
(lsp-dart--flutter-repo-p))))
82+
(lsp-dart--set-project-type-cache flutter-project?)
83+
flutter-project?)))
7184

7285
(defun lsp-dart-remove-from-alist (key alist)
7386
"Remove item with KEY from ALIST."

lsp-dart.el

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ imported into the current file."
142142
("dart/textDocument/publishOutline" (lambda (_workspace notification)
143143
(run-hook-with-args 'lsp-dart-outline-arrived-hook notification)))
144144
("dart/textDocument/publishFlutterOutline" (lambda (_workspace notification)
145-
(run-hook-with-args 'lsp-dart-flutter-outline-arrived-hook notification)))
145+
(when (lsp-dart--flutter-project-p)
146+
(run-hook-with-args 'lsp-dart-flutter-outline-arrived-hook notification))))
146147
("$/analyzerStatus" #'ignore))
147148
:request-handlers (lsp-ht ("workspace/configuration" #'lsp-dart--configuration))
148149
:after-open-fn #'lsp-dart--activate-features

0 commit comments

Comments
 (0)