[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/go-mode f4d2977 158/495: add go-coverage to display covera
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/go-mode f4d2977 158/495: add go-coverage to display coverage information |
Date: |
Sat, 7 Aug 2021 09:05:04 -0400 (EDT) |
branch: elpa/go-mode
commit f4d2977a82dab2be3865687f80599e113ee25225
Author: Dominik Honnef <dominikh@fork-bomb.org>
Commit: Dominik Honnef <dominikh@fork-bomb.org>
add go-coverage to display coverage information
---
go-mode.el | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 89 insertions(+)
diff --git a/go-mode.el b/go-mode.el
index 030bf52..33ab4ae 100644
--- a/go-mode.el
+++ b/go-mode.el
@@ -144,6 +144,10 @@
"Major mode for editing Go code"
:group 'languages)
+(defgroup go-cover nil
+ "Options specific to `cover`"
+ :group 'go)
+
(defcustom go-fontify-function-calls t
"Fontify function and method calls if this is non-nil."
:type 'boolean
@@ -154,6 +158,22 @@
:type 'hook
:group 'go)
+(defface go-coverage-untracked
+ '((t (:foreground "#505050")))
+ "Coverage color of untracked code."
+ :group 'go-cover)
+
+(defface go-coverage-covered
+ '((t (:foreground "#2cd495")))
+ "Coverage color of untracked code."
+ :group 'go-cover)
+
+(defface go-coverage-uncovered
+ '((t (:foreground "#c00000")))
+ "Coverage color of untracked code."
+ :group 'go-cover)
+
+
(defvar go-mode-syntax-table
(let ((st (make-syntax-table)))
(modify-syntax-entry ?+ "." st)
@@ -440,6 +460,7 @@ The following extra functions are defined:
- `go-play-buffer' and `go-play-region'
- `go-download-play'
- `godef-describe' and `godef-jump'
+- `go-coverage'
If you want to automatically run `gofmt' before saving a file,
add the following hook to your emacs configuration:
@@ -940,6 +961,74 @@ description at POINT."
(interactive "d")
(godef-jump point t))
+(defun go--goto-line (line)
+ (goto-char (point-min))
+ (forward-line (1- line)))
+
+(defun go--line-column-to-point (line column)
+ (go--goto-line line)
+ (forward-char (1- column))
+ (point))
+
+(defstruct go--covered
+ start-line start-column end-line end-column covered)
+
+(defun go-coverage (input)
+ "Open a clone of the current buffer and overlay it with
+coverage information gathered via go test -coverprofile=INPUT."
+ (interactive "f")
+ (let ((ranges '())
+ (file-name (file-name-nondirectory (buffer-file-name)))
+ (gocov-buffer-name (concat (buffer-name) "<gocov>")))
+
+ (with-temp-buffer
+ (insert-file-contents input)
+ (goto-char (point-min))
+ (forward-line) ;; Skip over mode
+ (while (not (eobp))
+ (let* ((parts (split-string (buffer-substring (point-at-bol)
(point-at-eol)) ":"))
+ (file (car parts))
+ (rest (split-string (nth 1 parts) "[., ]")))
+
+ (destructuring-bind
+ (start-line start-column end-line end-column num count)
+ (mapcar 'string-to-number rest)
+
+ (if (and (string= (file-name-nondirectory file) file-name))
+ (push
+ (make-go--covered
+ :start-line start-line
+ :start-column start-column
+ :end-line end-line
+ :end-column end-column
+ :covered (/= count 0))
+ ranges)))
+
+ (forward-line))))
+
+ (with-current-buffer (or
+ (get-buffer gocov-buffer-name)
+ (clone-indirect-buffer gocov-buffer-name nil))
+ (save-excursion
+ (overlay-put
+ (make-overlay
+ (point-min)
+ (point-max))
+ 'face 'go-coverage-untracked)
+
+ (dolist (range ranges)
+ (overlay-put
+ (make-overlay
+ (go--line-column-to-point
+ (go--covered-start-line range)
+ (go--covered-start-column range))
+ (go--line-column-to-point
+ (go--covered-end-line range)
+ (go--covered-end-column range)))
+ 'face (if (go--covered-covered range) 'go-coverage-covered
'go-coverage-uncovered))))
+
+ (display-buffer (current-buffer) 'display-buffer-reuse-window))))
+
(provide 'go-mode)
;;; go-mode.el ends here
- [nongnu] elpa/go-mode 0f0fe35 127/495: actually avoid using process-lines, (continued)
- [nongnu] elpa/go-mode 0f0fe35 127/495: actually avoid using process-lines, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 5c3a797 129/495: Handle indentation for multi-line function declarations correctly, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode f5c445c 130/495: improve godef related documentation, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 97f55b8 131/495: style changes, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode b97cfea 133/495: godef-jump: use push-mark., ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode a18b3f3 134/495: style change, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 55295da 128/495: formatting, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 50412f7 136/495: add gitignore, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode ec73086 157/495: remove unused code, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 5fd1c63 156/495: document go-goto-opening-parenthesis, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode f4d2977 158/495: add go-coverage to display coverage information,
ELPA Syncer <=
- [nongnu] elpa/go-mode a5d5039 161/495: use go--goto-line where applicable, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 7ef7e56 163/495: correct docstrings of go-coverage-covered and go-coverage-uncovered, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 042f08c 169/495: if go-coverage is called in a coverage buffer, update it by using stored variables, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode eea3ccf 170/495: move some coverage code into own functions, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode fdb2132 179/495: no free variables, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 9617f0c 176/495: move actual parsing of coverage file into own function, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 1949b57 184/495: match unused imports where path and package name differ, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode ff30ae1 190/495: use (function) for function symbols, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 50fb3b2 192/495: allow users to customize the gofmt command, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 49c885d 188/495: (foo)(bar) is not a function call when there's a letter directly preceding it, ELPA Syncer, 2021/08/07