-
Notifications
You must be signed in to change notification settings - Fork 183
/
dap-swi-prolog.el
69 lines (54 loc) · 2.77 KB
/
dap-swi-prolog.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
69
;;; dap-swi-prolog.el --- Debug Adapter Protocol mode for SWI-Prolog -*- lexical-binding: t; -*-
;; Copyright (C) 2022 Eshel Yaron
;; Author: Eshel Yaron <[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://www.swi-prolog.org
;;; Code:
(require 'dap-mode)
(defcustom dap-swi-prolog-debug-program
'("swipl" "-g" "[library(debug_adapter/main)]" "-t" "halt")
"The path to the SWI-Prolog debug adapter."
:group 'dap-swi-prolog
:type '(repeat string))
(defun dap-swi-prolog--populate-start-file-args (conf)
"Populate CONF with the required arguments."
(let ((conf (-> conf
(dap--put-if-absent :dap-server-path dap-swi-prolog-debug-program)
(dap--put-if-absent :type "swi-prolog")
(dap--put-if-absent :cwd default-directory)
(dap--put-if-absent :module (buffer-file-name))
(dap--put-if-absent :goal (read-string "?- " nil nil "true"))
(dap--put-if-absent :name "SWI-Prolog Debug"))))
conf))
(dap-register-debug-provider "swi-prolog" #'dap-swi-prolog--populate-start-file-args)
(dap-register-debug-template "SWI-Prolog Run Configuration"
(list :type "swi-prolog"
:request "launch"
:name "SWI-Prolog::Run"))
(dap-register-debug-template "SWI-Prolog Start Terminal"
(list :type "swi-prolog"
:goal "$run_in_terminal"
:request "launch"
:name "SWI-Prolog::Terminal"))
(defun dap-swi-prolog--populate-start-tcp-args (conf)
"Populate CONF with the required arguments."
(let ((conf (-> conf
(dap--put-if-absent :host "localhost")
(dap--put-if-absent :debugServer 3443)
(dap--put-if-absent :request "attach")
(dap--put-if-absent :name "SWI-Prolog::Connected"))))
conf))
(dap-register-debug-provider "swi-prolog-tcp" #'dap-swi-prolog--populate-start-tcp-args)
(provide 'dap-swi-prolog)
;;; dap-swi-prolog.el ends here