Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing bad args handling in netcore test #831

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 24 additions & 18 deletions dap-netcore.el
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,14 @@ the function needs to examine, starting with FILE."
(setq file nil))))
(if root (file-name-as-directory root))))

(defun dap-netcore--locate-project-dir ()
"Locate .NET project directory."
(f-full
(or
(dap-netcore--locate-dominating-file-wildcard
default-directory "*.*proj")
(lsp-workspace-root))))

(defun dap-netcore--populate-args (conf)
"Populate CONF with arguments to launch or attach netcoredbg."
(dap--put-if-absent conf :dap-server-path (list (dap-netcore--debugger-locate-or-install) "--interpreter=vscode"))
Expand All @@ -160,11 +168,7 @@ the function needs to examine, starting with FILE."
(dap--put-if-absent
conf
:program
(let ((project-dir (f-full
(or
(dap-netcore--locate-dominating-file-wildcard
default-directory "*.*proj")
(lsp-workspace-root)))))
(let ((project-dir (dap-netcore--locate-project-dir)))
(save-mark-and-excursion
(find-file (concat (f-slash project-dir) "*.*proj") t)
(let ((res (if (libxml-available-p)
Expand Down Expand Up @@ -203,15 +207,18 @@ the function needs to examine, starting with FILE."
(setcdr config-cell (plist-put config-plist :processId pid))
(dap-debug (cdr config-cell))))

(defun dap-netcore-test-run (attach-buffer &optional args-string)
(defun dap-netcore-test-run (attach-buffer &optional args-string directory)
"Run .NET tests process to obtain PID to attach for debugging."
(with-environment-variables (("VSTEST_HOST_DEBUG" "1"))
(start-process "dap-netcore-attach-process"
attach-buffer
"dotnet"
"test"
"--verbosity=Quiet"
(concat "" args-string))))
(let ((args-list (append (list "dotnet"
"test"
"--configuration=Debug"
"--verbosity=Quiet"
"--nologo")
(split-string-shell-command args-string))))
(when directory
(push directory args-list))
(apply #'start-process "dap-netcore-attach-process" attach-buffer args-list))))

(defun dap-netcore-debug-tests-filter-pid (process output)
"Custom filter to extract PID from the process output in real-time."
Expand All @@ -237,14 +244,14 @@ the function needs to examine, starting with FILE."
;; Remove the filter to avoid further checks
(set-process-filter process nil))))))))

(defun dap-netcore-debug-test-init (&optional args-string)
(defun dap-netcore-debug-test-init (&optional args-string directory)
"Prepare .NET process to attach its PID for debugging."
(let ((attach-buffer "*dap-netcore-attach*"))
;; Kill existing buffer if it exists
(when (get-buffer attach-buffer)
(kill-buffer attach-buffer))
;; Run dotnet process
(let ((dotnet-process (dap-netcore-test-run attach-buffer args-string)))
(let ((dotnet-process (dap-netcore-test-run attach-buffer args-string directory)))
(when dotnet-process
(set-process-filter dotnet-process #'dap-netcore-debug-tests-filter-pid)
;; Set process finalization event
Expand All @@ -261,10 +268,9 @@ the function needs to examine, starting with FILE."
(let ((params '())
(filter (read-string "Filter: ")))
(unless (string-empty-p filter)
(push (concat params " --filter=" filter) params))
(when directory
(push directory params))
(dap-netcore-debug-test-init (string-join (reverse params) " "))))
(push (concat "--filter=" filter) params))
(dap-netcore-debug-test-init (string-join params " ") directory)))


(provide 'dap-netcore)
;;; dap-netcore.el ends here