|
| 1 | +;;; lsp-dart-dap.el --- DAP support for lsp-dart -*- lexical-binding: t; -*- |
| 2 | +;; |
| 3 | +;; Version: 1.5 |
| 4 | +;; Keywords: languages, extensions |
| 5 | +;; URL: https://github.com/emacs-lsp/lsp-dart.el |
| 6 | +;; |
| 7 | +;; This program is free software; you can redistribute it and/or modify |
| 8 | +;; it under the terms of the GNU General Public License as published by |
| 9 | +;; the Free Software Foundation, either version 3 of the License, or |
| 10 | +;; (at your option) any later version. |
| 11 | + |
| 12 | +;; This program is distributed in the hope that it will be useful, |
| 13 | +;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | +;; GNU General Public License for more details. |
| 16 | + |
| 17 | +;; You should have received a copy of the GNU General Public License |
| 18 | +;; along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 19 | + |
| 20 | +;;; Commentary: |
| 21 | + |
| 22 | +;; DAP support for lsp-dart |
| 23 | + |
| 24 | +;;; Code: |
| 25 | + |
| 26 | +(require 'lsp-mode) |
| 27 | +(require 'dap-mode) |
| 28 | +(require 'dap-utils) |
| 29 | + |
| 30 | +(defcustom lsp-dart-dap--extension-version "3.9.1" |
| 31 | + "The extension version." |
| 32 | + :group 'lsp-dart-dap |
| 33 | + :type 'string) |
| 34 | + |
| 35 | +(defcustom lsp-dart-dap--debugger-path |
| 36 | + (expand-file-name "github/Dart-Code.Dart-Code" |
| 37 | + dap-utils-extension-path) |
| 38 | + "The path to dart vscode extension." |
| 39 | + :group 'lsp-dart-dap |
| 40 | + :type 'string) |
| 41 | + |
| 42 | +(defcustom lsp-dart-dap-debugger-program |
| 43 | + `("node" ,(f-join lsp-dart-dap--debugger-path "extension/out/src/debug/dart_debug_entry.js")) |
| 44 | + "The path to the dart debugger." |
| 45 | + :group 'lsp-dart-dap |
| 46 | + :type '(repeat string)) |
| 47 | + |
| 48 | +(defcustom lsp-dart-dap-executable "dart" |
| 49 | + "The dart executable from dart SDK dir." |
| 50 | + :group 'lsp-dart-dap |
| 51 | + :type 'string) |
| 52 | + |
| 53 | +(defun lsp-dart-dap--get-project-root () |
| 54 | + "Return the project root path." |
| 55 | + (file-truename (locate-dominating-file default-directory "pubspec.yaml"))) |
| 56 | + |
| 57 | +(defun lsp-dart-dap--setup-extension () |
| 58 | + "Setup dart debugger extension to run `lsp-dart-dap-debugger-program`." |
| 59 | + (message "DAP Dart :: Setting up...") |
| 60 | + (lsp-async-start-process |
| 61 | + (lambda () |
| 62 | + (lsp-async-start-process |
| 63 | + (lambda () (message "DAP Dart :: Setup done!")) |
| 64 | + (lambda () (message "DAP Dart :: Error setting up lsp-dart-dap, check if `npm` is on $PATH")) |
| 65 | + (f-join lsp-dart-dap--debugger-path "extension/node_modules/typescript/bin/tsc") |
| 66 | + "--project" (f-join lsp-dart-dap--debugger-path "extension"))) |
| 67 | + (lambda () (message "DAP Dart :: Error setting up lsp-dart-dap, check if `npm` is on $PATH")) |
| 68 | + "npm" "install" "--prefix" (f-join lsp-dart-dap--debugger-path "extension") |
| 69 | + "--no-package-lock" "--silent" "--no-save")) |
| 70 | + |
| 71 | +(dap-utils-github-extension-setup-function |
| 72 | + "dap-dart" |
| 73 | + "Dart-Code" |
| 74 | + "Dart-Code" |
| 75 | + lsp-dart-dap--extension-version |
| 76 | + lsp-dart-dap--debugger-path |
| 77 | + #'lsp-dart-dap--setup-extension) |
| 78 | + |
| 79 | +(defun lsp-dart-dap--populate-start-file-args (conf) |
| 80 | + "Populate CONF with the required arguments." |
| 81 | + (-> conf |
| 82 | + (dap--put-if-absent :dap-server-path lsp-dart-dap-debugger-program) |
| 83 | + (dap--put-if-absent :type "dart") |
| 84 | + (dap--put-if-absent :cwd (lsp-dart-dap--get-project-root)) |
| 85 | + (dap--put-if-absent :program (buffer-file-name)) |
| 86 | + (dap--put-if-absent :name "Dart Debug") |
| 87 | + (dap--put-if-absent :dartPath lsp-dart-dap-executable) |
| 88 | + (dap--put-if-absent :debuggerType 0) |
| 89 | + (dap--put-if-absent :debugExternalLibraries nil) |
| 90 | + (dap--put-if-absent :debugSdkLibraries nil))) |
| 91 | + |
| 92 | +(dap-register-debug-provider "dart" 'lsp-dart-dap--populate-start-file-args) |
| 93 | +(dap-register-debug-template "Dart :: Run Configuration" |
| 94 | + (list :type "dart" |
| 95 | + :cwd nil |
| 96 | + :request "launch" |
| 97 | + :program nil |
| 98 | + :name "Dart::Run")) |
| 99 | + |
| 100 | +(provide 'lsp-dart-dap) |
| 101 | +;;; lsp-dart-dap.el ends here |
0 commit comments