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