Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit a6b83b6
Author: Andy Stewart <[email protected]>
Date:   Wed Oct 11 20:03:54 2023 +0800

    Fix issue #727, add new option lsp-bridge-find-def-select-in-open-windows

commit 5115963
Author: Andy Stewart <[email protected]>
Date:   Wed Oct 11 19:00:33 2023 +0800

    Try to fix issue #732 , use python.exe if python3.exe not found.
  • Loading branch information
werhner committed Oct 11, 2023
1 parent a46d8cc commit b276352
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 11 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
47 changes: 36 additions & 11 deletions lsp-bridge.el
Original file line number Diff line number Diff line change
Expand Up @@ -320,12 +320,18 @@ Setting this to nil or 0 will turn off the indicator."
:type 'string)

(defcustom lsp-bridge-python-command (cond ((memq system-type '(cygwin windows-nt ms-dos))
(if (executable-find "pypy3.exe")
"pypy3.exe"
"python3.exe"))
(t (if (executable-find "pypy3")
"pypy3"
"python3")))
(cond ((executable-find "pypy3.exe")
"pypy3.exe")
((executable-find "python3.exe")
"python3.exe")
((executable-find "python.exe")
"python.exe")))
(t (cond ((executable-find "pypy3")
"pypy3")
((executable-find "python3")
"python3")
((executable-find "python")
"python"))))
"The Python interpreter used to run lsp_bridge.py."
:type 'string)

Expand Down Expand Up @@ -1521,6 +1527,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 @@ -1686,18 +1700,29 @@ 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 (or (string-equal filehost "") lsp-bridge-enable-with-tramp)
(progn
(setq filename (concat (cdr (assoc filehost lsp-bridge-tramp-alias-alist) filename)))
;; 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 b276352

Please sign in to comment.