|
| 1 | +;;; dap-pwsh.el --- Debug Adapter Protocol mode for Pwsh -*- lexical-binding: t; -*- |
| 2 | + |
| 3 | +;; Copyright (C) 2019 Kien Nguyen |
| 4 | + |
| 5 | +;; Author: Kien Nguyen <[email protected]> |
| 6 | +;; Keywords: languages |
| 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 | +;; URL: https://github.com/yyoncho/dap-mode |
| 22 | +;; Package-Requires: ((emacs "25.1") (lsp-mode "4.0") (dap-mode "0.2")) |
| 23 | +;; Version: 0.2 |
| 24 | + |
| 25 | +;;; Commentary: |
| 26 | + |
| 27 | +;;; Code: |
| 28 | + |
| 29 | +(require 'dap-mode) |
| 30 | +(require 'lsp-pwsh) |
| 31 | +(require 'f) |
| 32 | +(require 'dash) |
| 33 | + |
| 34 | +(defgroup dap-pwsh nil |
| 35 | + "Debugger support for PowerShell." |
| 36 | + :group 'dap-mode |
| 37 | + :package-version '(dap-mode . "0.2")) |
| 38 | + |
| 39 | +(defcustom dap-pwsh-program |
| 40 | + `(,lsp-pwsh-exe "-NoProfile" "-NonInteractive" "-NoLogo" |
| 41 | + ,@(if (eq system-type 'windows-nt) '("-ExecutionPolicy" "Bypass")) |
| 42 | + "-OutputFormat" "Text" |
| 43 | + "-File" |
| 44 | + ,(f-join lsp-pwsh-dir "PowerShellEditorServices/Start-EditorServices.ps1") |
| 45 | + "-HostName" "'Emacs Host'" |
| 46 | + "-HostProfileId" "'Emacs.LSP'" |
| 47 | + "-HostVersion" "0.1" |
| 48 | + "-LogPath" ,(f-join lsp-pwsh-log-path "emacs-powershell-debug.log") |
| 49 | + "-LogLevel" ,lsp-pwsh-developer-editor-services-log-level |
| 50 | + "-SessionDetailsPath" |
| 51 | + ,(format "%s/PSES-VSCode-%d-Debug" lsp-pwsh-log-path lsp-pwsh--sess-id) |
| 52 | + ;; "-AdditionalModules" "@('PowerShellEditorServices.VSCode')" |
| 53 | + "-Stdio" |
| 54 | + "-DebugServiceOnly" |
| 55 | + "-BundledModulesPath" ,lsp-pwsh-dir |
| 56 | + "-FeatureFlags" "@()") |
| 57 | + "The command to run the pwsh debugger." |
| 58 | + :group 'dap-pwsh |
| 59 | + :type '(repeat string)) |
| 60 | + |
| 61 | +(defun dap-pwsh--populate-start-file-args (conf) |
| 62 | + "Populate CONF with the required arguments." |
| 63 | + (-> conf |
| 64 | + (dap--put-if-absent :dap-server-path dap-pwsh-program) |
| 65 | + (dap--put-if-absent :type "PowerShell") |
| 66 | + (dap--put-if-absent :cwd (lsp-find-session-folder (lsp-session) (buffer-file-name))) |
| 67 | + (dap--put-if-absent :script (read-file-name "Select the file to run:" nil (buffer-file-name) t)) |
| 68 | + (dap--put-if-absent :name "PowerShell: Debug") |
| 69 | + (dap--put-if-absent :args []))) |
| 70 | + |
| 71 | +(dap-register-debug-provider "PowerShell" #'dap-pwsh--populate-start-file-args) |
| 72 | + |
| 73 | +(dap-register-debug-template "PowerShell: Launch Script" |
| 74 | + (list :type "PowerShell" |
| 75 | + :cwd nil |
| 76 | + :request "launch" |
| 77 | + :script nil |
| 78 | + :args nil |
| 79 | + :name "PowerShell: Launch Script")) |
| 80 | + |
| 81 | +(provide 'dap-pwsh) |
| 82 | +;;; dap-pwsh.el ends here |
0 commit comments