Skip to content

Commit 605448b

Browse files
authored
Support Julia (emacs-lsp#813)
* Add dap-julia * update copyright * fix docstring length * Update CHANGELOG.org
1 parent ee1091c commit 605448b

File tree

3 files changed

+89
-1
lines changed

3 files changed

+89
-1
lines changed

CHANGELOG.org

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Changelog
55
** Unreleased 0.9
66
- Added ~dap-gdb~
7+
- Added ~dap-julia~
78
** 0.8
89
- [Breaking Change] Change debug provider names to match VS Code's naming: ~lldb~ to ~lldb-mi~ and ~codelldb~ to ~lldb~
910
- Added ~dap-gdscript~

dap-julia.el

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
;;; dap-julia.el --- Debug Adapter Protocol mode for Julia -*- lexical-binding: t; -*-
2+
3+
;; Copyright (C) 2024 Michael Kovarik
4+
5+
;; Author: Michael Kovarik <[email protected]>
6+
;; Keywords: languages
7+
8+
;; This program is free software; you can redistribute it and/or modify
9+
;; it under the terms of the GNU General Public License as published by
10+
;; the Free Software Foundation, either version 3 of the License, or
11+
;; (at your option) any later version.
12+
13+
;; This program is distributed in the hope that it will be useful,
14+
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
;; GNU General Public License for more details.
17+
18+
;; You should have received a copy of the GNU General Public License
19+
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
20+
21+
;;; Commentary:
22+
;; Adapter for https://github.com/julia-vscode/DebugAdapter.jl
23+
24+
;;; Code:
25+
26+
(require 'dap-mode)
27+
(require 'dap-utils)
28+
29+
(defun dap-julia--find-project-root (dir)
30+
"Search upwards from DIR to find Julia project root."
31+
(let ((parent (file-name-directory (directory-file-name dir))))
32+
(cond
33+
((or (file-exists-p (expand-file-name "Project.toml" dir))
34+
(file-exists-p (expand-file-name "JuliaProject.toml" dir)))
35+
dir)
36+
((or (null parent) (equal parent dir))
37+
(error "No Project.toml or JuliaProject.toml found in any parent directories. Is this a Julia project?"))
38+
(t (dap-julia--find-project-root parent)))))
39+
40+
(defun dap-julia--populate-start-file-args (conf)
41+
"Populate CONF with the required arguments."
42+
(let* ((project-root (dap-julia--find-project-root (file-name-directory (buffer-file-name))))
43+
(port (dap--find-available-port))
44+
(command (format "julia --project=%s -e \"import DebugAdapter: DebugSession; using Sockets; \
45+
port = %d; server = listen(port); \
46+
while true; conn = accept(server); @async begin; \
47+
session = DebugSession(conn); run(session); close(conn); end; end;\"" project-root port)))
48+
(-> conf
49+
(dap--put-if-absent :cwd project-root)
50+
(dap--put-if-absent :name "Julia Debug")
51+
(dap--put-if-absent :debugServer port)
52+
(dap--put-if-absent :host "localhost")
53+
(dap--put-if-absent :type "Julia")
54+
(dap--put-if-absent :program (buffer-file-name))
55+
(dap--put-if-absent :program-to-start command))))
56+
57+
(dap-register-debug-provider "Julia" #'dap-julia--populate-start-file-args)
58+
59+
60+
(dap-register-debug-template "Julia Run Configuration"
61+
(list :type "Julia"
62+
:cwd nil
63+
:request "launch"
64+
:name "Julia Debug"
65+
:sourceMaps t))
66+
67+
(provide 'dap-julia)
68+
;;; dap-julia.el ends here

docs/page/configuration.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,4 +696,23 @@ Core Attach (Console)" from `dap-debug` menu.
696696
697697
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.
698698
Note that this debugger _only_ works with bytecode compiled OCaml programs.
699-
699+
700+
701+
## Julia
702+
703+
[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).
704+
705+
To setup, first install `DebugAdapter.jl`:
706+
707+
```
708+
$ julia -e 'import Pkg; Pkg.add("DebugAdapter")'
709+
```
710+
711+
Then add the following to your configuration:
712+
713+
714+
``` elisp
715+
(require 'dap-julia)
716+
```
717+
718+
To launch a debug session, call `dap-debug` with the `Julia Run Configuration` template.

0 commit comments

Comments
 (0)