Skip to content

Commit 8da7339

Browse files
kiennqyyoncho
authored andcommitted
Moving dap-pwsh from kiennq/dap-pwsh (#161)
1 parent dd6473a commit 8da7339

File tree

2 files changed

+90
-1
lines changed

2 files changed

+90
-1
lines changed

README.org

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@
5151
- [[#node][Node]]
5252
- [[#installation-7][Installation]]
5353
- [[#usage-5][Usage]]
54+
- [[#powershell][Powershell]]
5455
- [[#extending-dap-with-new-debug-servers][Extending DAP with new Debug servers]]
55-
- [[#example][Example]]
56+
- [[#example][Example]]
5657
- [[#links][Links]]
5758
- [[#troubleshooting][Troubleshooting]]
5859
- [[#acknowledgments][Acknowledgments]]
@@ -359,6 +360,12 @@ case, define a template:
359360
#+END_SRC
360361
**** Usage
361362
~dap-debug~ or ~dap-debug-edit-template~ and select the node template. For additional documentation on the supported template parameters or about different configuration templates refer to [[https://code.visualstudio.com/docs/nodejs/nodejs-debugging][Nodejs Debugging]].
363+
** Powershell
364+
#+BEGIN_SRC elisp
365+
(require 'dap-pwsh)
366+
#+END_SRC
367+
Start debugging by selecting "Powershell: Launch Script" from ~dap-debug~ menu.
368+
362369
* Extending DAP with new Debug servers
363370
There are two methods that are used for registering remote extensions:
364371
- ~dap-register-debug-provider~ - register a method to call for populating

dap-pwsh.el

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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

Comments
 (0)