1
submitted 11 months ago by FreeAd7233@alien.top to c/emacs@communick.news

https://github.com/svaante/dape#

Given that eglot has been part of the core emacs, I believe this is a long lasting wish for a lot of emacsers that has finally been fulfilled. (a stand alone DAP implementation that does not rely on LSP-mode)

you are viewing a single comment's thread
view the rest of the comments
[-] jakejxdev@alien.top 1 points 11 months ago

Tried using dape recently with Go and managed to get it to debug Go tests. Sharing the snippet incase its helpful for others (requires go treesitter).

  (setq treesit-go-tests-query (treesit-query-compile 'go
                                                      '((function_declaration
                                                         name: (identifier) @testname
                                                         parameters: (parameter_list :anchor (parameter_declaration type: (pointer_type) @type :anchor))
                                                         (:match "*testing.\\(T\\|M\\)" @type) (:match "^Test.+$" @testname)) @parent)))
  (defun jake/query-go-test-nodes ()
    (when (treesit-ready-p 'go)
      (treesit-query-capture (treesit-buffer-root-node) treesit-go-tests-query)))

  (defun jake/completing-read-go-tests ()
    (let* ((test-matches (jake/query-go-test-nodes))
           (test-name-matches (cl-remove-if-not (lambda (match) (eq (car match) 'testname)) test-matches))
           (test-names (mapcar (lambda (match) (treesit-node-text (cdr match))) test-name-matches)))
      (completing-read "Test:" test-names nil t)))


  (defun jake/dape--select-go-test-args ()
    (when-let* ((test-name (jake/completing-read-go-tests))
                (test-regexp (concat "^" test-name "$")))
      (if test-name
          `["-test.run" ,test-regexp]
        (error "No test selected"))))

  (defun jake/file-relative-dir ()
    "Return the file directory relative to dape's cwd. This is used by Delve debugger."
    (concat "./" (file-relative-name default-directory (funcall dape-cwd-fn))))

;; inside your dape-config
(add-to-list 'dape-configs
               `(test
                 modes (go-mode go-ts-mode)
                 command "dlv"
                 command-cwd dape-cwd-fn
                 command-args ("dap" "--listen" "127.0.0.1:55878")
                 host "127.0.0.1"
                 port 55878
                 :type "go"
                 :name "debug test"
                 :request "launch"
                 :mode "test"
                 :cwd dape-cwd-fn
                 :program jake/file-relative-dir
                 :args jake/dape--select-go-test-args))
[-] noooit@alien.top 1 points 11 months ago

Compared to gud, it's a lot of config, it's also nasty that it looks like you have to code the program path to your config.

but, it's a great effort in any case, both from you and the plugin author. Configuration snippets like this help a lot of people.

load more comments (1 replies)
this post was submitted on 20 Oct 2023
1 points (100.0% liked)

Emacs

310 readers
1 users here now

A community for the timeless and infinitely powerful editor. Want to see what Emacs is capable of?!

Get Emacs

Rules

  1. Posts should be emacs related
  2. Be kind please
  3. Yes, we already know: Google results for "emacs" and "vi" link to each other. We good.

Emacs Resources

Emacs Tutorials

Useful Emacs configuration files and distributions

Quick pain-saver tip

founded 1 year ago
MODERATORS