Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Highlight the Symbol you want to see while peeking to find it. #695

Merged
merged 4 commits into from
Aug 1, 2023
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 29 additions & 19 deletions lsp-bridge-peek.el
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ to files where definitions and references are, the third item stores the
positions where definitions and references are in the file, the fourth item
is the index of the parent node of the symbol in the list, and the fifth
item is a list, storing the index of the node's child nodes in the list.
The sixth item stores which child node is selected next.")
The sixth item stores which child node is selected next. The seventh item
stores how many lines the file content was moved.")

(defvar lsp-bridge-peek-symbol-at-point nil
"A variable that stores the current symbol to be added.")
Expand Down Expand Up @@ -357,19 +358,24 @@ not affected by its surroundings."
(propertize "\n"
'face 'lsp-bridge-peek-border-face))

(defun lsp-bridge-peek--get-content (pos)
(defun lsp-bridge-peek--get-content (pos content-move)
(setq file-content nil)
(goto-char (acm-backend-lsp-position-to-point pos))
(let ((beg nil)
(end nil))
(setq beg (line-beginning-position))
(forward-line (1- lsp-bridge-peek-file-content-height))
(setq end (line-end-position))
(let* ((beg (save-excursion
(forward-line content-move)
(line-beginning-position)))
(end (save-excursion
(forward-line content-move)
(forward-line (1- lsp-bridge-peek-file-content-height))
(line-end-position)))
(highlight-begin (point))
(highlight-end (save-excursion
(forward-symbol 1)
(point))))
(font-lock-fontify-region beg end)
(setq file-content (concat (buffer-substring beg end) "\n")))
(lsp-bridge--add-face file-content
(list :background lsp-bridge-peek--bg
:extend t))
(put-text-property highlight-begin highlight-end 'face '(:background "#623d73" :foreground "white"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个highlight的face 定义一个单独face 可能会方便用户设置

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

改好了,还请大佬再过目一下

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

辛苦了 我这边没啥问题

(setq file-content (concat (buffer-substring beg end) "\n"))
(put-text-property highlight-begin highlight-end 'face '(:background (background-color-at-point))))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这块用remove-text-properties会不会更好一点

file-content)

(defun lsp-bridge--attach-ace-str (str sym-bounds bound-offset ace-seqs)
Expand Down Expand Up @@ -400,8 +406,10 @@ The beginnings of each symbol are replaced by ace strings with
(selected-symbol (nth lsp-bridge-peek-selected-symbol lsp-bridge-peek-symbol-tree))
(path-list (nth 1 selected-symbol))
(pos-list (nth 2 selected-symbol))
(content-move-list (nth 6 selected-symbol))
(file (nth n path-list))
(pos (nth n pos-list))
(content-move (nth n content-move-list))
(buf-name (format "*lsp-bridge-peek-%s*" file))
(file-content nil))
(if (not (member buf-name lsp-bridge-peek--temp-buffer-alist))
Expand All @@ -411,10 +419,10 @@ The beginnings of each symbol are replaced by ace strings with
(let ((buffer-file-name file))
(delay-mode-hooks
(set-auto-mode)))
(setq file-content (lsp-bridge-peek--get-content pos))
(setq file-content (lsp-bridge-peek--get-content pos content-move))
(add-to-list 'lsp-bridge-peek--temp-buffer-alist buf-name)))
(with-current-buffer buf-name
(setq file-content (lsp-bridge-peek--get-content pos))))
(setq file-content (lsp-bridge-peek--get-content pos content-move))))
(when (and lsp-bridge-peek--symbol-bounds lsp-bridge-peek--ace-seqs)
(setq file-content
(lsp-bridge--attach-ace-str file-content
Expand Down Expand Up @@ -502,6 +510,7 @@ The beginnings of each symbol are replaced by ace strings with
(defun lsp-bridge-peek-define--return (filename position)
(push filename (nth 1 lsp-bridge-peek-symbol-at-point))
(push position (nth 2 lsp-bridge-peek-symbol-at-point))
(push 0 (nth 6 lsp-bridge-peek-symbol-at-point))
(if (not (= (length lsp-bridge-peek-ace-list) 0))
(with-current-buffer (nth 3 lsp-bridge-peek-ace-list)
(goto-char (nth 4 lsp-bridge-peek-ace-list))
Expand Down Expand Up @@ -535,7 +544,8 @@ The beginnings of each symbol are replaced by ace strings with
(setq filename (buffer-substring beg end))
(setq pos (list :line (string-to-number line) :character (string-to-number char)))
(push filename (nth 1 lsp-bridge-peek-symbol-at-point))
(push pos (nth 2 lsp-bridge-peek-symbol-at-point)))))
(push pos (nth 2 lsp-bridge-peek-symbol-at-point))
(push 0 (nth 6 lsp-bridge-peek-symbol-at-point)))))
(setf (nth 1 lsp-bridge-peek-symbol-at-point)
(nreverse (nth 1 lsp-bridge-peek-symbol-at-point))
(nth 2 lsp-bridge-peek-symbol-at-point)
Expand Down Expand Up @@ -588,7 +598,7 @@ When FORCE if non-nil, the content of the peek window is recalculated."
(defun lsp-bridge-peek ()
"Peek the definition of the symbol at point."
(interactive)
(setq lsp-bridge-peek-symbol-at-point (make-list 6 nil))
(setq lsp-bridge-peek-symbol-at-point (make-list 7 nil))
(setf (nth 0 lsp-bridge-peek-symbol-at-point) (symbol-at-point))
(lsp-bridge-call-file-api "peek_find_definition" (lsp-bridge--position)))

Expand Down Expand Up @@ -631,10 +641,10 @@ When FORCE if non-nil, the content of the peek window is recalculated."
(defun lsp-bridge-peek-file-content-move (num)
(lsp-bridge-peek--error-if-not-peeking)
(cl-symbol-macrolet ((selected-id (nth 1 lsp-bridge-peek-chosen-displaying-list))
(selected-symbol (nth lsp-bridge-peek-selected-symbol lsp-bridge-peek-symbol-tree))
(pos-list (nth 2 selected-symbol))
(line (plist-get (nth selected-id pos-list) :line)))
(setf line (+ line num))
(selected-symbol (nth lsp-bridge-peek-selected-symbol lsp-bridge-peek-symbol-tree))
(content-move-list (nth 6 selected-symbol))
(content-move (nth selected-id content-move-list)))
(setf content-move (+ content-move num))
(setq lsp-bridge-peek--content-update t)))

(defun lsp-bridge-peek-file-content-next-line ()
Expand Down
Loading