commit 7474b0110843d0c24f15b2d7d0330329f03dd88a parent 8e4b51453fdf57de77701e4d6094c658e1fb98a6 Author: Vincent Demeester <vincent@sbr.pm> Date: Wed, 21 Feb 2024 19:20:49 +0100 tools/emacs: dape configuration… stolen from chmouel Signed-off-by: Vincent Demeester <vincent@sbr.pm> Diffstat:
M | tools/emacs/config/programming-config.el | | | 57 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 57 insertions(+), 0 deletions(-)
diff --git a/tools/emacs/config/programming-config.el b/tools/emacs/config/programming-config.el @@ -75,6 +75,63 @@ :after flymake :hook (prog-mode . flymake-codespell-setup-backend)) +(defun my-gotest-get-current-test() + "Get the current test name, if we have a subtest (starting with name) then use it." + (interactive) + (require 'which-func) + (let ((subtest (when-let* ((subtest + (progn + (save-excursion + (goto-char (line-beginning-position)) + (re-search-forward "name:[[:blank:]]*\"\\([^\"]*\\)\"" (line-end-position) t))))) + (if subtest + (shell-quote-argument (replace-regexp-in-string " " "_" (match-string-no-properties 1)))))) + (gotest (when-let* ((test-name (which-function))) + (if test-name test-name + (error "No test selected"))))) + (concat (format "^%s%s$" gotest (if subtest (concat "/" subtest) ""))))) + +(use-package dape + :commands (my-dape-go-test-at-point) + :after go-ts-mode + :bind + (:map go-ts-mode-map + ("<f5>" . (lambda()(interactive) + (if (dape--live-connections) + (call-interactively 'dape-continue) + (call-interactively 'dape)))) + ("S-<f5>" . dape-stop) + ("C-S-<f5>" . dape-restart) + ("<f9>" . dape-breakpoint-toggle) + ("<f10>" . dape-next) + ("<f11>" . dape-step-in) + ("S-<f11>" . dape-step-out)) + :hook + (go-ts-mode . (lambda() + (interactive) + (if (string-suffix-p "_test.go" (buffer-name)) + (setq-local dape-command '(delve-unit-test))))) + :config + (defun my-dape-go-test-at-point () + (interactive) + (dape (dape--config-eval-1 + `(modes (go-mode go-ts-mode) + ensure dape-ensure-command + fn dape-config-autoport + command "dlv" + command-args ("dap" "--listen" "127.0.0.1::autoport") + command-cwd dape-cwd-fn + port :autoport + :type "debug" + :request "launch" + :mode "test" + :cwd dape-cwd-fn + :program (lambda () (concat "./" (file-relative-name default-directory (funcall dape-cwd-fn)))) + :args (lambda () + (when-let* ((test-name (my-gotest-get-current-test))) + (if test-name `["-test.run" ,test-name] + (error "No test selected"))))))))) + ;; (use-package copilot ;; :preface ;; (unless (package-installed-p 'copilot)