Skip to content

Commit

Permalink
Fix issue #727, add new option lsp-bridge-find-def-select-in-open-win…
Browse files Browse the repository at this point in the history
…dows
  • Loading branch information
manateelazycat committed Oct 11, 2023
1 parent 5115963 commit a6b83b6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ lsp-bridge first looks for the content of the first *.pub file in the `~/.ssh` d
- `lsp-bridge-org-babel-lang-list`: list of language to support org-mode code block completion, nil enable all languages, default is nil
- `lsp-bridge-find-def-fallback-function`: When LSP cannot find a definition, you can customize this function for candidate jumping, such as binding the citre or dumb-jump definition jump function
- `lsp-bridge-find-ref-fallback-function`: When LSP cannot find a reference, you can customize this function for candidate jumping, such as binding the citre or dumb-jump definition jump function
- `lsp-bridge-find-def-select-in-open-windows`: If this option is turned on, when searching for function definitions, already open windows will be selected instead of switching buffers. disable by default
- `lsp-bridge-enable-completion-in-string`: Enable completion pop-up within strings, default is off
- `lsp-bridge-enable-completion-in-minibuffer`: Enable pop-completion up in Minibuffer, disabled by default
- `lsp-bridge-enable-diagnostics`: code diagnostic, enable by default
Expand Down
1 change: 1 addition & 0 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ lsp-bridge 优先从`~/.ssh`目录下找第一个 *.pub 文件的内容作为远
- `lsp-bridge-org-babel-lang-list`: 支持 org-mode 代码块补全的语言列表, 默认 nil 对于所有语言使用
- `lsp-bridge-find-def-fallback-function`: 当 LSP 没有找到定义时, 可以通过定制这个函数来进行候选跳转, 比如绑定 citre 或者 dumb-jump 定义跳转函数
- `lsp-bridge-find-ref-fallback-function`: 当 LSP 没有找到引用时, 可以通过定制这个函数来进行候选跳转, 比如绑定 citre 或者 dumb-jump 定义跳转函数
- `lsp-bridge-find-def-select-in-open-windows`: 当打开这个选项时, 查找定义命令会尽量选择已经打开窗口去跳转定义, 而不是在当前窗口切换 Buffer, 默认关闭
- `lsp-bridge-enable-completion-in-string`: 支持在字符串中弹出补全, 默认关闭
- `lsp-bridge-enable-completion-in-minibuffer`: 支持在 Minibuffer 中弹出补全, 默认关闭
- `lsp-bridge-enable-diagnostics`: 代码诊断, 默认打开
Expand Down
29 changes: 24 additions & 5 deletions lsp-bridge.el
Original file line number Diff line number Diff line change
Expand Up @@ -1515,6 +1515,14 @@ So we build this macro to restore postion after code format."
:type 'function
:group 'lsp-bridge)

(defcustom lsp-bridge-find-def-select-in-open-windows nil
"If this option is turned on, when searching for function definitions,
already open windows will be selected instead of switching buffers.
Off by default."
:type 'boolean
:group 'lsp-bridge)

(defvar-local lsp-bridge-jump-to-def-in-other-window nil)

(defun lsp-bridge-find-def ()
Expand Down Expand Up @@ -1680,17 +1688,28 @@ So we build this macro to restore postion after code format."
(setq position-before-jump (copy-marker marker)))
(setq mark-ring lsp-bridge-mark-ring))

(defun lsp-bridge-find-window-match-filename (filename)
(dolist (window (window-list))
(when (string-equal filename (buffer-file-name (window-buffer window)))
(return window))))

(defun lsp-bridge-define--jump (filename filehost position)
(let (position-before-jump)
(lsp-bridge-define--jump-record-postion)

(if (string-equal filehost "")
(progn
;; Jump to define.
;; Show define in other window if `lsp-bridge-jump-to-def-in-other-window' is non-nil.
(if lsp-bridge-jump-to-def-in-other-window
(find-file-other-window filename)
(find-file filename))
(let ((match-window (lsp-bridge-find-window-match-filename filename)))
(if (and lsp-bridge-find-def-select-in-open-windows
match-window)
;; Try select to window if `lsp-bridge-find-def-select-in-open-windows' is non-nil.
(select-window match-window)
;; Jump to define.
;; Show define in other window if `lsp-bridge-jump-to-def-in-other-window' is non-nil.
(if lsp-bridge-jump-to-def-in-other-window
(find-file-other-window filename)
(find-file filename))
))

;; Init jump history in new buffer.
(setq-local lsp-bridge-mark-ring (append (list position-before-jump) mark-ring))
Expand Down

0 comments on commit a6b83b6

Please sign in to comment.