branch: elpa/go-mode
commit 6ac56695d16da5758d1d64d296454124b2e92e11
Author: Dominik Honnef <[email protected]>
Commit: Dominik Honnef <[email protected]>
cmd/guru: emacs: interpret byte offsets correctly
Change-Id: Id506c6c0b3f3c585781bfc38df1b665d507a7c33
Reviewed-on: https://go-review.googlesource.com/22019
Reviewed-by: Alan Donovan <[email protected]>
---
guru_import/cmd/guru/go-guru.el | 20 ++++++++++++--------
1 file changed, 12 insertions(+), 8 deletions(-)
diff --git a/guru_import/cmd/guru/go-guru.el b/guru_import/cmd/guru/go-guru.el
index b837de0..c4be257 100644
--- a/guru_import/cmd/guru/go-guru.el
+++ b/guru_import/cmd/guru/go-guru.el
@@ -262,10 +262,14 @@ If BUFFER, return the number of characters in that buffer
instead."
(string-bytes (buffer-substring (point-min)
(point-max)))))
-;; FIXME(dominikh): go-guru--goto-pos-no-file and go-guru--goto-pos
-;; assume that Guru is giving rune offsets in the columns field.
-;; However, it is giving us byte offsets, causing us to highlight
-;; wrong ranges as soon as there's any multi-byte runes in the line.
+(defun go-guru--goto-byte (offset)
+ "Go to the OFFSETth byte in the buffer."
+ (goto-char (byte-to-position offset)))
+
+(defun go-guru--goto-byte-column (offset)
+ "Go to the OFFSETth byte in the current line."
+ (goto-char (byte-to-position (+ (position-bytes (point-at-bol)) (1-
offset)))))
+
(defun go-guru--goto-pos (posn)
"Find the file containing the position POSN (of the form `file:line:col')
set the point to it, switching the current buffer."
@@ -273,7 +277,7 @@ set the point to it, switching the current buffer."
(find-file (car file-line-pos))
(goto-char (point-min))
(forward-line (1- (string-to-number (cadr file-line-pos))))
- (forward-char (1- (string-to-number (caddr file-line-pos))))))
+ (go-guru--goto-byte-column (string-to-number (caddr file-line-pos)))))
(defun go-guru--goto-pos-no-file (posn)
"Given `file:line:col', go to the line and column. The file
@@ -281,7 +285,7 @@ component will be ignored."
(let ((file-line-pos (split-string posn ":")))
(goto-char (point-min))
(forward-line (1- (string-to-number (cadr file-line-pos))))
- (forward-char (1- (string-to-number (caddr file-line-pos))))))
+ (go-guru--goto-byte-column (string-to-number (caddr file-line-pos)))))
;;;###autoload
(defun go-guru-callees ()
@@ -477,8 +481,8 @@ end point."
(go-guru--enclosing-unique)))
(block (if (> (length enclosing) 0) (elt enclosing 0))))
(when block
- (goto-char (1+ (cdr (assoc 'start block))))
- (set-mark (1+ (cdr (assoc 'end block))))
+ (go-guru--goto-byte (1+ (cdr (assoc 'start block))))
+ (set-mark (byte-to-position (1+ (cdr (assoc 'end block)))))
(setq go-guru--last-enclosing (subseq enclosing 1))
(message "Region: %s" (cdr (assoc 'desc block)))
(setq deactivate-mark nil))))