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