[clang-tools-extra] r297010 - Do not display highlights for clang-include-fixer-at-point
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 6 06:49:27 PST 2017
Author: hokein
Date: Mon Mar 6 08:49:26 2017
New Revision: 297010
URL: http://llvm.org/viewvc/llvm-project?rev=297010&view=rev
Log:
Do not display highlights for clang-include-fixer-at-point
Summary: When invoking clang-include-fixer-at-point, the QuerySymbolInfos point to offset 0, length 0. Rather than showing a hidden overlay, do not show any overlay at all for zero-length symbols.
Patch by Torsten Marek!
Reviewers: hokein, klimek
Reviewed By: hokein
Differential Revision: https://reviews.llvm.org/D30577
Modified:
clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer-test.el
clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.el
Modified: clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer-test.el
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer-test.el?rev=297010&r1=297009&r2=297010&view=diff
==============================================================================
--- clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer-test.el (original)
+++ clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer-test.el Mon Mar 6 08:49:26 2017
@@ -51,4 +51,15 @@
(goto-char (point-max))
(should (equal (clang-include-fixer--symbol-at-point) "bbb::cc"))))
+(ert-deftest clang-include-fixer--highlight ()
+ (with-temp-buffer
+ (insert "util::Status foo;\n")
+ (setq buffer-file-coding-system 'utf-8-unix)
+ (should (equal nil (clang-include-fixer--highlight
+ '((Range . ((Offset . 0) (Length . 0)))))))
+ (let ((overlay (clang-include-fixer--highlight
+ '((Range . ((Offset . 1) (Length . 12)))))))
+ (should (equal 2 (overlay-start overlay)))
+ (should (equal 14 (overlay-end overlay))))))
+
;;; clang-include-fixer-test.el ends here
Modified: clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.el
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.el?rev=297010&r1=297009&r2=297010&view=diff
==============================================================================
--- clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.el (original)
+++ clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.el Mon Mar 6 08:49:26 2017
@@ -299,12 +299,14 @@ They are replaced by the single element
(let ((symbol (clang-include-fixer--symbol-name .QuerySymbolInfos))
;; Add temporary highlighting so that the user knows which
;; symbols the current session is about.
- (overlays (mapcar #'clang-include-fixer--highlight .QuerySymbolInfos)))
+ (overlays (remove nil
+ (mapcar #'clang-include-fixer--highlight .QuerySymbolInfos))))
(unwind-protect
(save-excursion
;; While prompting, go to the closest overlay so that the user sees
;; some context.
- (goto-char (clang-include-fixer--closest-overlay overlays))
+ (when overlays
+ (goto-char (clang-include-fixer--closest-overlay overlays)))
(cl-flet ((header (info) (let-alist info .Header)))
;; The header-infos is already sorted by include-fixer.
(let* ((header (completing-read
@@ -330,16 +332,17 @@ Raise a signal if the symbol name is not
(car symbols)))
(defun clang-include-fixer--highlight (symbol-info)
- "Add an overlay to highlight SYMBOL-INFO.
-Return the overlay object."
- (let ((overlay (let-alist symbol-info
- (make-overlay
- (clang-include-fixer--filepos-to-bufferpos
- .Range.Offset 'approximate)
- (clang-include-fixer--filepos-to-bufferpos
- (+ .Range.Offset .Range.Length) 'approximate)))))
- (overlay-put overlay 'face 'clang-include-fixer-highlight)
- overlay))
+ "Add an overlay to highlight SYMBOL-INFO, if it points to a non-empty range.
+Return the overlay object, or nil."
+ (let-alist symbol-info
+ (unless (zerop .Range.Length)
+ (let ((overlay (make-overlay
+ (clang-include-fixer--filepos-to-bufferpos
+ .Range.Offset 'approximate)
+ (clang-include-fixer--filepos-to-bufferpos
+ (+ .Range.Offset .Range.Length) 'approximate))))
+ (overlay-put overlay 'face 'clang-include-fixer-highlight)
+ overlay))))
(defun clang-include-fixer--closest-overlay (overlays)
"Return the start of the overlay in OVERLAYS that is closest to point."
More information about the cfe-commits
mailing list