From 53dc976142575ce97bde58e8622a638d7e6d79ea Mon Sep 17 00:00:00 2001 From: sjlwa Date: Wed, 19 Feb 2025 18:36:47 -0600 Subject: [PATCH 1/2] Extract dotnet project directory discovery as a function. --- dap-netcore.el | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/dap-netcore.el b/dap-netcore.el index 79eebfa3..0caa9b2f 100644 --- a/dap-netcore.el +++ b/dap-netcore.el @@ -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")) @@ -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) From c3cc3d43b1010a5fc28c1ea5a622f77e400b099f Mon Sep 17 00:00:00 2001 From: sjlwa Date: Wed, 19 Feb 2025 18:44:55 -0600 Subject: [PATCH 2/2] Fix arguments handling in netcore test functions to properly use them with a directory. --- dap-netcore.el | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/dap-netcore.el b/dap-netcore.el index 0caa9b2f..20673014 100644 --- a/dap-netcore.el +++ b/dap-netcore.el @@ -207,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." @@ -241,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 @@ -265,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