Skip to content

Commit b8ffd22

Browse files
committed
Add pub commands
1 parent dbd28e2 commit b8ffd22

File tree

4 files changed

+101
-10
lines changed

4 files changed

+101
-10
lines changed

lsp-dart-commands.el

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
;;; lsp-dart-commands.el --- LSP dart commands -*- lexical-binding: t; -*-
2+
;;
3+
;; Copyright (C) 2020 Eric Dallo
4+
;;
5+
;; This program is free software; you can redistribute it and/or modify
6+
;; it under the terms of the GNU General Public License as published by
7+
;; the Free Software Foundation, either version 3 of the License, or
8+
;; (at your option) any later version.
9+
10+
;; This program is distributed in the hope that it will be useful,
11+
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
;; GNU General Public License for more details.
14+
15+
;; You should have received a copy of the GNU General Public License
16+
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
;;
18+
;;; Commentary:
19+
;;
20+
;; LSP dart commands
21+
;;
22+
;;; Code:
23+
24+
(require 'lsp-dart-utils)
25+
26+
(defconst lsp-dart-commands-buffer-name "*LSP Dart commands*")
27+
28+
(defun lsp-dart--run-command (command args)
29+
"Run COMMAND with ARGS from the project root."
30+
(lsp-dart-from-project-root
31+
(compilation-start (format "%s %s" command args)
32+
t
33+
(lambda (_) lsp-dart-commands-buffer-name))))
34+
35+
(defun lsp-dart--pub-get ()
36+
"Run `pub get` from the root project."
37+
(lsp-dart--run-command (lsp-dart-pub-command) "get"))
38+
39+
(defun lsp-dart--flutter-pub-get ()
40+
"Run `flutter pub get` from the root project."
41+
(lsp-dart--run-command (lsp-dart-flutter-command) "pub get"))
42+
43+
(defun lsp-dart--pub-upgrade ()
44+
"Run `pub upgrade` from the root project."
45+
(lsp-dart--run-command (lsp-dart-pub-command) "upgrade"))
46+
47+
(defun lsp-dart--flutter-pub-upgrade ()
48+
"Run `flutter pub upgrade` from the root project."
49+
(lsp-dart--run-command (lsp-dart-flutter-command) "pub upgrade"))
50+
51+
(defun lsp-dart--pub-outdated ()
52+
"Run `pub outdated` from the root project."
53+
(lsp-dart--run-command (lsp-dart-pub-command) "outdated"))
54+
55+
(defun lsp-dart--flutter-pub-outdated ()
56+
"Run `flutter pub outdated` from the root project."
57+
(lsp-dart--run-command (lsp-dart-flutter-command) "pub outdated"))
58+
59+
;;;###autoload
60+
(defun lsp-dart-pub-get ()
61+
"Run pub get on a Dart or Flutter project.
62+
If it is Flutter project, run `flutter pub get` otherwise run
63+
`pub get`."
64+
(interactive)
65+
(if (lsp-dart--flutter-project-p)
66+
(lsp-dart--flutter-pub-get)
67+
(lsp-dart--pub-get)))
68+
69+
;;;###autoload
70+
(defun lsp-dart-pub-upgrade ()
71+
"Run pub upgrade on a Dart or Flutter project.
72+
If it is Flutter project, run `flutter pub upgrade` otherwise run
73+
`pub upgrade`."
74+
(interactive)
75+
(if (lsp-dart--flutter-project-p)
76+
(lsp-dart--flutter-pub-upgrade)
77+
(lsp-dart--pub-upgrade)))
78+
79+
;;;###autoload
80+
(defun lsp-dart-pub-outdated ()
81+
"Run pub outdated on a Dart or Flutter project.
82+
If it is Flutter project, run `flutter pub outdated` otherwise run
83+
`pub outdated`."
84+
(interactive)
85+
(if (lsp-dart--flutter-project-p)
86+
(lsp-dart--flutter-pub-outdated)
87+
(lsp-dart--pub-outdated)))
88+
89+
(provide 'lsp-dart-commands)
90+
;;; lsp-dart-commands.el ends here

lsp-dart-test-support.el

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,6 @@ IGNORE-CASE is a optional arg to ignore the case sensitive on regex search."
5454
(setq start (match-end 0)))
5555
idx))
5656

57-
(defmacro lsp-dart-test--from-project-root (&rest body)
58-
"Execute BODY with cwd set to the project root."
59-
`(let ((project-root (lsp-dart-get-project-root)))
60-
(if project-root
61-
(let ((default-directory project-root))
62-
,@body)
63-
(error "Dart or Flutter project not found (pubspec.yaml not found)"))))
64-
6557
(defun lsp-dart-test--build-command ()
6658
"Build the dart or flutter build command checking project type."
6759
(if (lsp-dart--flutter-project-p)
@@ -92,7 +84,7 @@ IGNORE-CASE is a optional arg to ignore the case sensitive on regex search."
9284
If TEST is nil, it will run all tests from project.
9385
If TEST is non nil, it will check if contains any test specific name
9486
to run otherwise run all tests from file-name in TEST."
95-
(lsp-dart-test--from-project-root
87+
(lsp-dart-from-project-root
9688
(if test
9789
(let* ((file-name (lsp-dart-test-file-name test))
9890
(names (lsp-dart-test-names test))
@@ -175,7 +167,7 @@ Search for the last test overlay."
175167
(interactive)
176168
(if (lsp-dart-test-file-p (buffer-file-name))
177169
(lsp-dart-test--run (->> (current-buffer) buffer-name file-truename (make-lsp-dart-test :file-name)))
178-
(user-error "Current buffer is not a Dart/Flutter test file")))
170+
(lsp-dart-log "Current buffer is not a Dart/Flutter test file.")))
179171

180172
;;;###autoload
181173
(defun lsp-dart-run-all-tests ()

lsp-dart-utils.el

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,14 @@ FLUTTER_ROOT environment variable."
137137
((file-exists-p bin-entry)
138138
bin-entry))))
139139

140+
(defmacro lsp-dart-from-project-root (&rest body)
141+
"Execute BODY with cwd set to the project root."
142+
`(let ((project-root (lsp-dart-get-project-root)))
143+
(if project-root
144+
(let ((default-directory project-root))
145+
,@body)
146+
(error "Project not found (pubspec.yaml not found)"))))
147+
140148

141149
;; Log
142150

lsp-dart.el

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
(require 'lsp-dart-outline)
3939
(require 'lsp-dart-flutter-fringe-colors)
4040
(require 'lsp-dart-flutter-widget-guide)
41+
(require 'lsp-dart-commands)
4142

4243
(defgroup lsp-dart nil
4344
"LSP support for Dart, using dart analysis server."

0 commit comments

Comments
 (0)