Skip to content

Commit 6c74027

Browse files
Fix byte compiler and native compiler warnings (#848)
* Fix compiler warning: fix defcustom type * Instead of the 'list :type, the '(repeat string) :type does not generate the warning and provide a set of lines to enter/edit each string separately, providing buttons to add/delete entries. * Fix compiler warnings on potentially undefined functions * Both dap-launch and dap-tasks are required by dap-mode and cannot require dap-utils outside of functions because that would cause recursive loading. However, the state of Emacs compiler AFAIK is not yet able to determine that the functions are present and generate a function "not known to be defined" warning in the byte compilation and native compilation, which is annoying. The work around is to add a check that the required functions are bound. They should always be bound, but just in case, the added code raises and error if they are not bound (instead of silently failing). * Fix compiler warnings on potentially undefined functions - better * Instead of checking that the functions are loaded, use the declare-function form, a better way that does not incur any overhead.
1 parent c81014c commit 6c74027

File tree

3 files changed

+42
-36
lines changed

3 files changed

+42
-36
lines changed

dap-launch.el

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -34,45 +34,47 @@ Yields nil if it cannot be found or there is no project."
3434
(require 'dap-variables)
3535
(dap-variables-find-vscode-config "launch.json" root)))
3636

37+
38+
(declare-function dap-utils-sanitize-json "dap-utils")
3739
(defun dap-launch-get-launch-json ()
3840
"Parse the project's launch.json as json data and return the result."
3941
(require 'dap-utils)
4042
(when-let ((launch-json (dap-launch-find-launch-json))
41-
(json-object-type 'plist)
42-
;; Use 'vector instead of 'list. With 'list for array type,
43-
;; json-encode-list interpreted a list with one plist element as
44-
;; an alist. Using 'list, it turned the following value of
45-
;; pathMappings:
46-
;;
47-
;; "pathMappings": [
48-
;; {
49-
;; "localRoot": "${workspaceFolder}",
50-
;; "remoteRoot": "."
51-
;; }
52-
;; ]
53-
;;
54-
;; into:
55-
;;
56-
;; ((:localRoot "${workspaceFolder}" :remoteRoot "."))
57-
;;
58-
;; and then into:
59-
;;
60-
;; "pathMappings": {
61-
;; "localRoot": [
62-
;; "${workspaceFolder}",
63-
;; "remoteRoot",
64-
;; "."
65-
;; ]
66-
;; }
67-
(json-array-type 'vector))
68-
(with-temp-buffer
69-
;; NOTE: insert-file-contents does not move point
70-
(insert-file-contents launch-json)
71-
(dap-utils-sanitize-json)
72-
;; dap-launch-remove-comments does move point
73-
(goto-char (point-min))
74-
75-
(json-read))))
43+
(json-object-type 'plist)
44+
;; Use 'vector instead of 'list. With 'list for array type,
45+
;; json-encode-list interpreted a list with one plist element as
46+
;; an alist. Using 'list, it turned the following value of
47+
;; pathMappings:
48+
;;
49+
;; "pathMappings": [
50+
;; {
51+
;; "localRoot": "${workspaceFolder}",
52+
;; "remoteRoot": "."
53+
;; }
54+
;; ]
55+
;;
56+
;; into:
57+
;;
58+
;; ((:localRoot "${workspaceFolder}" :remoteRoot "."))
59+
;;
60+
;; and then into:
61+
;;
62+
;; "pathMappings": {
63+
;; "localRoot": [
64+
;; "${workspaceFolder}",
65+
;; "remoteRoot",
66+
;; "."
67+
;; ]
68+
;; }
69+
(json-array-type 'vector))
70+
(with-temp-buffer
71+
;; NOTE: insert-file-contents does not move point
72+
(insert-file-contents launch-json)
73+
(dap-utils-sanitize-json)
74+
;; dap-launch-remove-comments does move point
75+
(goto-char (point-min))
76+
77+
(json-read))))
7678

7779
(defun dap-launch-configuration-get-name (conf)
7880
"Return the name of launch configuration CONF."

dap-mode.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ also `dap--make-terminal-buffer'."
120120
(defcustom dap-output-buffer-filter '("stdout" "stderr")
121121
"If non-nil, a list of output types to display in the debug output buffer."
122122
:group 'dap-mode
123-
:type 'list)
123+
:type '(repeat string))
124124

125125
(defcustom dap-label-output-buffer-category nil
126126
"If non-nil, content that is printed to the output buffer will be labelled

dap-tasks.el

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ Yields nil if it cannot be found or there is no project."
3434
(require 'dap-variables)
3535
(dap-variables-find-vscode-config "tasks.json" root)))
3636

37+
38+
(declare-function dap-utils-sanitize-json "dap-utils")
3739
(defun dap-tasks-get-tasks-json ()
3840
"Parse the project's launch.json as json data and return the result."
3941
(when-let ((tasks-json (dap-tasks-find-tasks-json))
@@ -74,6 +76,8 @@ Yields nil if it cannot be found or there is no project."
7476

7577
(json-read))))
7678

79+
(declare-function dap-utils-string-to-keyword "dap-utils")
80+
(declare-function dap-utils-get-os-key "dap-utils")
7781
(defun dap-tasks--get-key (key conf)
7882
"Given a KEY, attempt to get a value from a debug CONF.
7983
The order of presedence within vscode is:

0 commit comments

Comments
 (0)