Skip to content

Instantly share code, notes, and snippets.

@chmouel
Created December 9, 2024 12:46
Show Gist options
  • Save chmouel/f3021c8d12bca385fb14805f7d6cf793 to your computer and use it in GitHub Desktop.
Save chmouel/f3021c8d12bca385fb14805f7d6cf793 to your computer and use it in GitHub Desktop.
;;; Directory Local Variables -*- no-byte-compile: t -*-
;;; For more information see (info "(emacs) Directory Variables")
((nil . ((compile-command . "make -C $(git rev-parse --show-toplevel) lint-go")
(projectile-git-command . "fdfind -0")
(projectile-project-test-cmd . "make test lint")))
(nil . ((eval . (add-to-list 'dape-configs
`(pac-watcher
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" "--log=true")
command-cwd dape-cwd-fn
port :autoport
:type "debug"
:request "launch"
:program "./cmd/pipelines-as-code-watcher/")))
(eval . (add-to-list 'dape-configs
`(pac-controller
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" "--log=true")
command-cwd dape-cwd-fn
port :autoport
:type "debug"
:request "launch"
:program "./cmd/pipelines-as-code-controller/"))))))
(use-package gotest-ts)
(use-package dape
:preface
(defvar dape-configs nil)
:autoload (dape dape-stop dape-restart dape-breakpoint-toggle dape-next dape-step-in dape-step-out)
:after go-ts-mode
:commands
(my-dape-go-test-at-point)
:bind
(:map go-ts-mode-map
("C-x C-a b" . my-dape-breakpoint-toggle-and-hl))
:general
(:keymaps 'go-ts-mode-map
(general-define-key
"<f5>" 'dape
"S-<f5>" 'dape-stop
"C-S-<f5>" 'dape-restart
"<f9>" 'my-dape-breakpoint-toggle-and-hl
"<f10>" 'dape-next
"<f11>" 'dape-step-in
"<f12>" 'dape-step-out))
(general-leader "td" 'my-dape-go-test-at-point)
(general-leader "d" (general-simulate-key "C-x C-a"))
:hook
(go-ts-mode . dape-breakpoint-global-mode)
(go-ts-mode . (lambda()
(interactive)
(if (string-suffix-p "_test.go" (buffer-name))
(setq-local dape-command '(delve-unit-test)))))
:custom
(dape-info-buffer-window-groups '((dape-info-scope-mode)(dape-info-breakpoints-mode)))
:config
(defun highlight-current-line ()
"Highlight the current line using a custom face."
(interactive)
(let ((overlay (make-overlay (line-beginning-position) (line-end-position))))
(overlay-put overlay 'face 'highlight-current-line-face)
(overlay-put overlay 'evaporate t)))
(defface highlight-current-line-face
'((t (:background "grey80" :foreground "yellow")))
"Face for highlighting the current line.")
(defun clear-current-line-highlights ()
"Clear all current line highlights."
(interactive)
(remove-overlays nil nil 'face 'highlight-current-line-face))
(defun my-dape-breakpoint-toggle-and-hl ()
"Add or remove breakpoint at current line."
(interactive)
(if (cl-member nil (dape--breakpoints-at-point)
:key #'dape--breakpoint-type)
(progn
(clear-current-line-highlights)
(dape-breakpoint-remove-at-point))
(progn
(dape--breakpoint-place)
(highlight-current-line))))
(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 (gotest-ts-get-subtest-ts)))
(if test-name `["-test.run" ,test-name]
(error "No test selected")))))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment