Skip to content

Commit

Permalink
Support Julia (#813)
Browse files Browse the repository at this point in the history
* Add dap-julia

* update copyright

* fix docstring length

* Update CHANGELOG.org
  • Loading branch information
subthedubdub authored Nov 1, 2024
1 parent ee1091c commit 605448b
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.org
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Changelog
** Unreleased 0.9
- Added ~dap-gdb~
- Added ~dap-julia~
** 0.8
- [Breaking Change] Change debug provider names to match VS Code's naming: ~lldb~ to ~lldb-mi~ and ~codelldb~ to ~lldb~
- Added ~dap-gdscript~
Expand Down
68 changes: 68 additions & 0 deletions dap-julia.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
;;; dap-julia.el --- Debug Adapter Protocol mode for Julia -*- lexical-binding: t; -*-

;; Copyright (C) 2024 Michael Kovarik

;; Author: Michael Kovarik <[email protected]>
;; Keywords: languages

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.

;;; Commentary:
;; Adapter for https://github.com/julia-vscode/DebugAdapter.jl

;;; Code:

(require 'dap-mode)
(require 'dap-utils)

(defun dap-julia--find-project-root (dir)
"Search upwards from DIR to find Julia project root."
(let ((parent (file-name-directory (directory-file-name dir))))
(cond
((or (file-exists-p (expand-file-name "Project.toml" dir))
(file-exists-p (expand-file-name "JuliaProject.toml" dir)))
dir)
((or (null parent) (equal parent dir))
(error "No Project.toml or JuliaProject.toml found in any parent directories. Is this a Julia project?"))
(t (dap-julia--find-project-root parent)))))

(defun dap-julia--populate-start-file-args (conf)
"Populate CONF with the required arguments."
(let* ((project-root (dap-julia--find-project-root (file-name-directory (buffer-file-name))))
(port (dap--find-available-port))
(command (format "julia --project=%s -e \"import DebugAdapter: DebugSession; using Sockets; \
port = %d; server = listen(port); \
while true; conn = accept(server); @async begin; \
session = DebugSession(conn); run(session); close(conn); end; end;\"" project-root port)))
(-> conf
(dap--put-if-absent :cwd project-root)
(dap--put-if-absent :name "Julia Debug")
(dap--put-if-absent :debugServer port)
(dap--put-if-absent :host "localhost")
(dap--put-if-absent :type "Julia")
(dap--put-if-absent :program (buffer-file-name))
(dap--put-if-absent :program-to-start command))))

(dap-register-debug-provider "Julia" #'dap-julia--populate-start-file-args)


(dap-register-debug-template "Julia Run Configuration"
(list :type "Julia"
:cwd nil
:request "launch"
:name "Julia Debug"
:sourceMaps t))

(provide 'dap-julia)
;;; dap-julia.el ends here
21 changes: 20 additions & 1 deletion docs/page/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -696,4 +696,23 @@ Core Attach (Console)" from `dap-debug` menu.
Call `dap-debug` and edit the "OCaml Debug Template". Make sure to set the program field as the path of your *byte-code* compiled program.
Note that this debugger _only_ works with bytecode compiled OCaml programs.
## Julia
[DebugAdapter.jl](https://github.com/julia-vscode/DebugAdapter.jl) is DAP-compatible server built on top of [Debugger.jl](https://github.com/JuliaDebug/Debugger.jl).
To setup, first install `DebugAdapter.jl`:
```
$ julia -e 'import Pkg; Pkg.add("DebugAdapter")'
```
Then add the following to your configuration:
``` elisp
(require 'dap-julia)
```
To launch a debug session, call `dap-debug` with the `Julia Run Configuration` template.

0 comments on commit 605448b

Please sign in to comment.