我具有emacs次要模式来进行笑话覆盖率突出显示,并且当我更改覆盖率(更新测试)并运行此功能时,突出显示不会更新。
(defun jc/mark-buffer ()
(interactive)
(let* ((dir (jc/root-git-repo))
(json-object-type 'hash-table)
(json-array-type 'list)
(json-key-type 'string)
(json (json-read-file (concat dir "/coverage/coverage-final.json")))
(filename (buffer-file-name (current-buffer)))
(coverage (gethash filename json))
(statments (gethash "statementMap" coverage)))
(save-excursion
(let ((coverage-list (gethash "s" coverage))
(covered 0)
(not-covered 0))
(maphash (lambda (key value)
(if (not (and jc/statements (= (gethash key jc/statements) value)))
(let* ((statment (gethash key statments))
(start (gethash "start" statment))
(end (gethash "end" statment))
(start-line-pos (jc/line-pos-at-line (gethash "line" start)))
(start-pos (+ start-line-pos (gethash "column" start)))
(end-line-pos (jc/line-pos-at-line (gethash "line" start)))
(end-pos (+ end-line-pos (gethash "column" end)))
(face (if (= value 0)
'jc/not-covered
'jc/covered)))
(hlt-highlight-region start-pos end-pos face)))
(if (= value 0)
(setq not-covered (+ 1 not-covered))
(setq covered (+ 1 covered))))
coverage-list)
(message "%3.2f%% coverage" (* (/ (float covered) (+ covered not-covered)) 100))
(setq jc/statements coverage-list)))))
我不知道问题出在我的emacs代码中还是在关于笑话覆盖json文件的假设中。
该文件具有文件名作为键,并且具有包含语句位置的键statementMap:
"statementMap":{"0":{"start":{"line":186,"column":0},"end":{"line":7951,"column":3}},"1":{"start":{"line":187,"column":15},"end":{"line":187,"column":62}},...}
和“ s”键如下所示:
"s":{"0":1,"1":1,"2":0,"3":1,"4":1,"5":1472, ....}
我假设0表示未覆盖,1表示未覆盖,但是我不知道其他数字的含义,因此我假设随后被覆盖,因为显示覆盖状态的消息具有正确的值(与笑话输出相同)。 s中的键是对statementMap中键的引用。
如果我在缓冲区干净时运行该函数,则按预期的行显示为红色和绿色。当我添加应该覆盖另一行的测试,然后在突出显示的内容没有发生变化的情况下运行该函数,但是当我清除缓冲区时,以前未被覆盖的红线被标记为绿色。
需要检查代码覆盖率是否发生变化,因为该功能在大文件上运行非常慢,并且会冻结Emacs。