Skip to content

Commit 269bd9d

Browse files
committed
Display tool names instead of their IDs
Previously only tool IDs were returned from the API (compiler-explorer/compiler-explorer#8399). * compiler-explorer.el (ce--tool-name): New helper function. (ce-add-tool): (ce-remove-tool): (ce--header-line-format-tool, ce--define-menu): Display tool name by using `ce--tool-name'. * compiler-explorer-test.el (ce-tools): (ce-restoring-killed-session): Update tests.
1 parent 6d07c9b commit 269bd9d

File tree

2 files changed

+39
-18
lines changed

2 files changed

+39
-18
lines changed

compiler-explorer-test.el

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -307,29 +307,34 @@ int foo( std::string a) { return 1 ; }")
307307
(ce-set-tool-input "clangquerytrunk" "m functionDecl().bind(\"x\")")
308308

309309
(ce-test--wait)
310-
(with-current-buffer (format ce--tool-buffer-format "clangformattrunk")
310+
(with-current-buffer
311+
(format ce--tool-buffer-format (ce--tool-name "clangformattrunk"))
311312
(should (string= "#include <map>
312313
#include <string>
313314
314315
int foo(std::string a) { return 1; }
315316
"
316317
(buffer-string))))
317-
(with-current-buffer (format ce--tool-buffer-format "iwyu")
318+
(with-current-buffer
319+
(format ce--tool-buffer-format (ce--tool-name "iwyu"))
318320
(goto-char (point-min))
319321
(should (search-forward "should remove these lines:\n- #include <map> "))
320322
(should (search-forward "The full include-list for <source>:
321323
#include <string> // for string\n---\n")))
322324
(with-current-buffer
323-
(format ce--tool-buffer-format "clangtidytrunk")
325+
326+
(format ce--tool-buffer-format (ce--tool-name "clangtidytrunk"))
324327
(goto-char (point-min))
325328
(should
326329
(search-forward "USAGE: clang-tidy [options]")))
327330
(with-current-buffer
328-
(format ce--tool-buffer-format "clangquerytrunk")
331+
332+
(format ce--tool-buffer-format (ce--tool-name "clangquerytrunk"))
329333
(goto-char (point-min))
330334
(should (search-forward "Match #4:"))
331335
(should (re-search-forward "note:.* binds here")))
332-
(with-current-buffer (format ce--tool-buffer-format "llvm-covtrunk")
336+
(with-current-buffer
337+
(format ce--tool-buffer-format (ce--tool-name "llvm-covtrunk"))
333338
(goto-char (point-min))
334339
;; Only supported in clang compilers
335340
(should (re-search-forward
@@ -431,7 +436,7 @@ int main(int argc, char** argv) {
431436
(should-not (buffer-live-p (get-buffer ce--output-buffer)))
432437
(should-not (buffer-live-p (get-buffer ce--exe-output-buffer)))
433438
(should-not (buffer-live-p
434-
(get-buffer "*compiler-explorer tool clangtidytrunk*")))
439+
(get-buffer (format ce--tool-buffer-format "Clang-Tidy"))))
435440
(should-not ce--language-data)
436441
(should-not ce--compiler-data)
437442
(should-not ce--selected-libraries)
@@ -451,7 +456,8 @@ int main(int argc, char** argv) {
451456
(should (string= "boost" (caar ce--selected-libraries)))
452457
(should (string= "174" (cadar ce--selected-libraries)))
453458
(should (buffer-live-p
454-
(get-buffer "*compiler-explorer tool clangtidytrunk*")))))
459+
(get-buffer (format ce--tool-buffer-format
460+
(ce--tool-name "clangtidytrunk")))))))
455461

456462
(ert-deftest ce-session-ring ()
457463
(let ((ce--session-ring nil)

compiler-explorer.el

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -929,7 +929,7 @@ output buffer."
929929
(:eval (ce--header-line-format-common))
930930
" | "
931931
,(propertize
932-
(format "Tool: %s" (ce--tool-id))
932+
(format "Tool: %s" (ce--tool-name (ce--tool-id)))
933933
'mouse-face 'header-line-highlight
934934
'keymap (let ((map (make-keymap))
935935
(id (ce--tool-id)))
@@ -1063,7 +1063,7 @@ output buffer."
10631063
(not (seq-empty-p (ce--tools (plist-get ce--language-data :id))))
10641064
,@(mapcar
10651065
(pcase-lambda (`(,id . ,_))
1066-
(vector id
1066+
(vector (ce--tool-name id)
10671067
(lambda ()
10681068
(interactive)
10691069
(ce-add-tool id))
@@ -1074,14 +1074,15 @@ output buffer."
10741074
:enable (not (null ce--selected-tools))
10751075
,@(mapcar
10761076
(lambda (id)
1077-
(vector id (lambda () (interactive) (ce-remove-tool id))))
1077+
(vector (ce--tool-name id)
1078+
(lambda () (interactive) (ce-remove-tool id))))
10781079
(mapcar #'car ce--selected-tools)))
10791080
("Set tool arguments"
10801081
:enable (not (null ce--selected-tools))
10811082
,@(mapcar
10821083
(lambda (id)
10831084
(vector
1084-
id
1085+
(ce--tool-name id)
10851086
(lambda ()
10861087
(interactive)
10871088
(let ((ce--tool-context id))
@@ -1090,7 +1091,7 @@ output buffer."
10901091
("Set tool input"
10911092
:enable (not (null ce--selected-tools))
10921093
,@(mapcar
1093-
(lambda (id) (vector id
1094+
(lambda (id) (vector (ce--tool-name id)
10941095
(lambda ()
10951096
(interactive)
10961097
(let ((ce--tool-context id))
@@ -1140,6 +1141,14 @@ output buffer."
11401141
"Get the ID of the tool in the current buffer, or return nil."
11411142
(car (cl-find (current-buffer) ce--selected-tools :key #'cadr)))
11421143

1144+
(defun ce--tool-name (id)
1145+
"Return the name of a tool with given ID."
1146+
(let* ((lang (or (and (ce-active-p)
1147+
(plist-get ce--language-data :id))
1148+
(error "Not in a `compiler-explorer' session")))
1149+
(tool-data (map-elt (ce--tools lang) id)))
1150+
(or (plist-get tool-data :name) id)))
1151+
11431152
(defun ce--window-layout (&optional window)
11441153
"Get the window layout of WINDOW, suitable for `compiler-explorer-layout'.
11451154
WINDOW if nil defaults to the frame's root window."
@@ -1957,12 +1966,15 @@ The tool's buffer is active when this hook runs.")
19571966
(let* ((lang (or (and (ce-active-p)
19581967
(plist-get ce--language-data :id))
19591968
(user-error "Not in a `compiler-explorer' session")))
1960-
(candidates (mapcar #'car (ce--tools lang)))
1969+
(candidates (mapcar
1970+
(lambda (id) (cons (ce--tool-name id) id))
1971+
(mapcar #'car (ce--tools lang))))
19611972
(res (completing-read
19621973
"Add tool: " candidates
19631974
;; Ignore tools that are already added.
19641975
(lambda (id) (null (assoc id ce--selected-tools)))
1965-
t)))
1976+
t))
1977+
(res (map-elt candidates res)))
19661978
(list res)))
19671979
(unless (ce-active-p)
19681980
(error "Not in a `compiler-explorer' session"))
@@ -1971,7 +1983,7 @@ The tool's buffer is active when this hook runs.")
19711983
(error "Tool %s already added" id))
19721984

19731985
(let ((buf (generate-new-buffer
1974-
(format ce--tool-buffer-format id)))
1986+
(format ce--tool-buffer-format (ce--tool-name id))))
19751987
window)
19761988
(push (list id buf "" "") ce--selected-tools)
19771989
(unless noninteractive
@@ -1999,9 +2011,12 @@ Each function is called with one argument, the tool id.")
19992011
"Remove tool ID from the current compilation."
20002012
(interactive
20012013
(if (ce-active-p)
2002-
(let ((tools (mapcar #'car ce--selected-tools)))
2003-
(list (completing-read "Remove tool: " tools nil t nil nil
2004-
(ce--tool-id))))
2014+
(let* ((candidates (mapcar
2015+
(lambda (id) (cons (ce--tool-name id) id))
2016+
(mapcar #'car ce--selected-tools)))
2017+
(res (completing-read "Remove tool: " candidates nil t))
2018+
(res (map-elt candidates res)))
2019+
(list res))
20052020
(user-error "Not in a `compiler-explorer' session")))
20062021
(unless (ce-active-p)
20072022
(error "Not in a `compiler-explorer' session"))

0 commit comments

Comments
 (0)