-
Notifications
You must be signed in to change notification settings - Fork 183
/
dap-julia.el
68 lines (54 loc) · 2.76 KB
/
dap-julia.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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