Skip to content

Commit

Permalink
Use acm-frame instead posframe.
Browse files Browse the repository at this point in the history
  • Loading branch information
manateelazycat committed Jun 9, 2023
1 parent 36cb36e commit 46ff169
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 96 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ Using Python multithreading techniques, lsp-bridge builds a high-speed cache bet
`pip3 install epc orjson sexpdata six paramiko` (orjson is optional, orjson is based on Rust, providing faster JSON parsing performance)
3. Install Elisp dependencies:

- [posframe](https://github.com/tumashu/posframe)
- [markdown-mode](https://github.com/jrblevin/markdown-mode)
- [yasnippet](https://github.com/joaotavora/yasnippet)

Expand Down Expand Up @@ -153,9 +152,9 @@ lsp-bridge first looks for the content of the first *.pub file in the `~/.ssh` d
- `lsp-bridge-enable-log`: enable LSP message log, disable by default, only enable this option for development purposes, usually do not turn on this option to avoid affecting performance
- `lsp-bridge-enable-debug`: enable program debugging, disable by default
- `lsp-bridge-disable-backup`: forbidden version manage of emacs, enable by default
- `lsp-bridge-code-action-enable-popup-menu`: enable code action posframe popup menu, enable by default
- `lsp-bridge-code-action-enable-popup-menu`: enable code action popup menu, enable by default
- `lsp-bridge-diagnostic-fetch-idle`: diagnostic delay, start pulling diagnostic information 0.5 second after stopping typing
- `lsp-bridge-signature-show-function`: The function used for displaying signature info, default show message in minibuffer, set `lsp-bridge-signature-posframe` to show signature info in frame
- `lsp-bridge-signature-show-function`: The function used for displaying signature info, default show message in minibuffer, set `lsp-bridge-signature-show-with-frame` to show signature info in frame
- `lsp-bridge-completion-popup-predicates`: the predicate function for completion menu, completion menu popup after all the functions pass
- `lsp-bridge-completion-stop-commands`: completion menu will not popup if these commands are executed
- `lsp-bridge-completion-hide-characters`: The default value is `‘(":" ";" "(" ")" "[" "]" "{" "}" ", " "\"")`, the completion menu does not pop up when the cursor is behind these characters. You can customize this option to remove this restriction, or call the `lsp-bridge-popup-complete-menu` command to force the menu to pop up
Expand All @@ -165,7 +164,6 @@ lsp-bridge first looks for the content of the first *.pub file in the `~/.ssh` d
- `lsp-bridge-enable-org-babel`: Use lsp completion in org babel, disable by default, if unable to complete, please make sure the string after begin_src exists in the `org-src-lang-modes` variable
- `acm-frame-background-dark-color`: Menu background color in dark theme
- `acm-frame-background-light-color`: Menu background color in light theme
- `acm-markdown-render-font-height`: The font height of function documentation, default is 130
- `acm-enable-doc`: Whether the complete menu display the help document
- `acm-enable-doc-markdown-render`: Richly render Markdown for completion popups, you can choose `’async`, `t` or `nil`. When set to `‘async`, styles are applied asynchronously, choose `t`, styles are applied synchronously and will slow down the completion speed, default is `async`
- `acm-enable-icon`: Whether the completion menu displays icons (Many macOS users have reported that emacs-plus28 cannot display icons properly, showing colored squares instead. There are two ways to solve this: install Emacs Mac Port or add the `--with-rsvg` option to the brew command when compiling Emacs yourself)
Expand Down
6 changes: 2 additions & 4 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ lsp-bridge 使用 Python 多线程技术在 Emacs 和 LSP 服务器之间构建
`pip3 install epc orjson sexpdata six paramiko` (orjson 是可选的, orjson 基于 Rust, 提供更快的 JSON 解析性能)
3. 安装 Elisp 依赖:

- [posframe](https://github.com/tumashu/posframe)
- [markdown-mode](https://github.com/jrblevin/markdown-mode)
- [yasnippet](https://github.com/joaotavora/yasnippet)

Expand Down Expand Up @@ -152,9 +151,9 @@ lsp-bridge 优先从`~/.ssh`目录下找第一个 *.pub 文件的内容作为远
- `lsp-bridge-enable-log`: 启用 LSP 消息日志, 默认关闭, 除非开发目的, 平常请勿打开此选项以避免影响性能
- `lsp-bridge-enable-debug`: 启用程序调试, 默认关闭
- `lsp-bridge-disable-backup`: 禁止 emacs 对文件做版本管理, 默认打开
- `lsp-bridge-code-action-enable-popup-menu`: 启用 code action posframe 菜单, 默认打开
- `lsp-bridge-code-action-enable-popup-menu`: 启用 code action 菜单, 默认打开
- `lsp-bridge-diagnostic-fetch-idle`: 诊断延迟, 默认是停止敲键盘后 0.5 秒开始拉取诊断信息
- `lsp-bridge-signature-show-function`: 用于显示签名信息的函数, 默认是在 minibuffer 显示, 设置成 `lsp-bridge-signature-posframe` 后可以用 frame 来显示函数的签名信息
- `lsp-bridge-signature-show-function`: 用于显示签名信息的函数, 默认是在 minibuffer 显示, 设置成 `lsp-bridge-signature-show-with-frame` 后可以用 frame 来显示函数的签名信息
- `lsp-bridge-completion-popup-predicates`: 补全菜单显示的检查函数, 这个选项包括的所有函数都检查过以后, 补全菜单才能显示
- `lsp-bridge-completion-stop-commands`: 这些命令执行以后, 不再弹出补全菜单
- `lsp-bridge-completion-hide-characters`: 默认值为 `'(":" ";" "(" ")" "[" "]" "{" "}" ", " "\"")` , 光标在这些字符的后面时不弹出补全菜单, 你可以定制这个选项以解除这个限制, 或者调用 `lsp-bridge-popup-complete-menu` 命令强制弹出菜单
Expand All @@ -164,7 +163,6 @@ lsp-bridge 优先从`~/.ssh`目录下找第一个 *.pub 文件的内容作为远
- `lsp-bridge-enable-org-babel`: 在 Org Babel 里使用 LSP 补全, 默认关闭, 如果没法补全, 请确保 begin_src 后面的字符串存在于 `org-src-lang-modes` 变量中
- `acm-frame-background-dark-color`: 暗色主题下的菜单背景颜色
- `acm-frame-background-light-color`: 亮色主题下的菜单背景颜色
- `acm-markdown-render-font-height`: 弹出文档的字体高度, 默认是 130
- `acm-enable-doc`: 补全菜单是否显示帮助文档
- `acm-enable-icon`: 补全菜单是否显示图标 (有很多 macOS 用户反馈 emacs-plus28 无法正常显示图标, 显示的是彩色方块, 有两种方法可以解决, 安装 Emacs Mac Port 或者自己编译 Emacs 的时候给 brew 命令增加选项 `--with-rsvg` )
, 重新编译了之后好像也没有用, 后来重新装了 emacs mac port
Expand Down
7 changes: 1 addition & 6 deletions acm/acm.el
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,6 @@
:type 'integer
:group 'acm)

(defcustom acm-markdown-render-font-height 130
"Font size for hover tooltip."
:type 'integer
:group 'acm)

(defcustom acm-frame-background-dark-color "#191a1b"
"The frame background color for dark theme."
:type 'string
Expand Down Expand Up @@ -1093,7 +1088,7 @@ The key of candidate will change between two LSP results."

;; Then remapping background and height of `markdown-code-face' to same as acm doc buffer.
(face-remap-add-relative 'markdown-code-face :background (face-attribute 'default :background acm-menu-frame))
(face-remap-add-relative 'markdown-code-face :height acm-markdown-render-font-height)))
))

(read-only-mode 0)

Expand Down
5 changes: 4 additions & 1 deletion lsp-bridge-code-action.el
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,10 @@ Please read https://microsoft.github.io/language-server-protocol/specifications/
(action
(lsp-bridge-code-action--fix-do action))
;; Popup menu if `lsp-bridge-code-action-enable-popup-menu' option is non-nil.
((and lsp-bridge-code-action-enable-popup-menu (posframe-workable-p))
((and lsp-bridge-code-action-enable-popup-menu
(not (or noninteractive
emacs-basic-display
(not (display-graphic-p)))))
(lsp-bridge-code-action-popup-menu menu-items default-action))
(t
;; Choose action from minibuffer.
Expand Down
97 changes: 54 additions & 43 deletions lsp-bridge-diagnostic.el
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
"Face hint diagnostic."
:group 'lsp-bridge)

(defcustom lsp-bridge-diagnostic-tooltip " *lsp-bridge-diagnostic*"
(defcustom lsp-bridge-diagnostic-buffer " *lsp-bridge-diagnostic*"
"Buffer for display diagnostic information."
:type 'string
:group 'lsp-bridge)
Expand Down Expand Up @@ -158,7 +158,7 @@ You can set this value with `(2 3 4) if you just need render error diagnostic."
(autoload 'lsp-bridge--with-file-buffer "lsp-bridge")

(defun lsp-bridge-diagnostic-hide-tooltip ()
(posframe-hide lsp-bridge-diagnostic-tooltip))
(acm-frame-hide-frame lsp-bridge-diagnostic-frame))

(defun lsp-bridge-diagnostic-hide-overlays ()
(when lsp-bridge-diagnostic-overlays
Expand All @@ -169,36 +169,38 @@ You can set this value with `(2 3 4) if you just need render error diagnostic."

(defun lsp-bridge-diagnostic--render (filepath filehost diagnostics)
(lsp-bridge--with-file-buffer filepath filehost
(lsp-bridge-diagnostic-hide-overlays)
(lsp-bridge-diagnostic-hide-overlays)

(let ((diagnostic-index 0)
(diagnostic-number (length diagnostics)))
(dolist (diagnostic diagnostics)
(let ((severity (plist-get diagnostic :severity)))
(unless (member severity lsp-bridge-diagnostic-hide-severities)
(let* ((diagnostic-start (acm-backend-lsp-position-to-point (plist-get (plist-get diagnostic :range) :start)))
(diagnostic-end (acm-backend-lsp-position-to-point (plist-get (plist-get diagnostic :range) :end)))
(overlay (if (eq diagnostic-start diagnostic-end)
;; Adjust diagnostic end position if start and end is same position.
(make-overlay diagnostic-start (1+ diagnostic-start))
(make-overlay diagnostic-start diagnostic-end)))
(message (plist-get diagnostic :message))
(overlay-face (cl-case severity
(1 'lsp-bridge-diagnostics-error-face)
(2 'lsp-bridge-diagnostics-warning-face)
(3 'lsp-bridge-diagnostics-info-face)
(4 'lsp-bridge-diagnostics-hint-face))))
(overlay-put overlay 'face overlay-face)
(overlay-put overlay 'message message)
(overlay-put overlay
'display-message
(if (> diagnostic-number 1)
(format "[%s:%s] %s" (1+ diagnostic-index) diagnostic-number message)
message))
(push overlay lsp-bridge-diagnostic-overlays))))

(setq diagnostic-index (1+ diagnostic-index))))
(setq-local lsp-bridge-diagnostic-overlays (reverse lsp-bridge-diagnostic-overlays))))

(let ((diagnostic-index 0)
(diagnostic-number (length diagnostics)))
(dolist (diagnostic diagnostics)
(let ((severity (plist-get diagnostic :severity)))
(unless (member severity lsp-bridge-diagnostic-hide-severities)
(let* ((diagnostic-start (acm-backend-lsp-position-to-point (plist-get (plist-get diagnostic :range) :start)))
(diagnostic-end (acm-backend-lsp-position-to-point (plist-get (plist-get diagnostic :range) :end)))
(overlay (if (eq diagnostic-start diagnostic-end)
;; Adjust diagnostic end position if start and end is same position.
(make-overlay diagnostic-start (1+ diagnostic-start))
(make-overlay diagnostic-start diagnostic-end)))
(message (plist-get diagnostic :message))
(overlay-face (cl-case severity
(1 'lsp-bridge-diagnostics-error-face)
(2 'lsp-bridge-diagnostics-warning-face)
(3 'lsp-bridge-diagnostics-info-face)
(4 'lsp-bridge-diagnostics-hint-face))))
(overlay-put overlay 'face overlay-face)
(overlay-put overlay 'message message)
(overlay-put overlay
'display-message
(if (> diagnostic-number 1)
(format "[%s:%s] %s" (1+ diagnostic-index) diagnostic-number message)
message))
(push overlay lsp-bridge-diagnostic-overlays))))

(setq diagnostic-index (1+ diagnostic-index))))
(setq-local lsp-bridge-diagnostic-overlays (reverse lsp-bridge-diagnostic-overlays))))
(defvar lsp-bridge-diagnostic-frame nil)

(defun lsp-bridge-diagnostic-show-tooltip (diagnostic-overlay &optional goto-beginning)
(let* ((diagnostic-display-message (overlay-get diagnostic-overlay 'display-message))
Expand All @@ -208,23 +210,32 @@ You can set this value with `(2 3 4) if you just need render error diagnostic."
(when goto-beginning
(goto-char (overlay-start diagnostic-overlay)))

(with-current-buffer (get-buffer-create lsp-bridge-diagnostic-tooltip)
(with-current-buffer (get-buffer-create lsp-bridge-diagnostic-buffer)
(erase-buffer)
(insert diagnostic-display-message)
(setq-local lsp-bridge-diagnostic-message diagnostic-message))

(cond
((posframe-workable-p) ;; Perform redisplay make sure posframe can poup to
;; Perform redisplay make sure posframe can poup to
(redisplay 'force)
(sleep-for 0.01)
(setq lsp-bridge-diagnostic-frame
(posframe-show lsp-bridge-diagnostic-tooltip
:position (point)
:internal-border-width lsp-bridge-diagnostic-tooltip-border-width
:background-color (acm-frame-background-color)
:foreground-color foreground-color
)))
((not (or noninteractive
emacs-basic-display
(not (display-graphic-p))))

(when (and (frame-live-p lsp-bridge-diagnostic-frame)
(not (eq (frame-parent lsp-bridge-diagnostic-frame) (selected-frame))))
(acm-frame-delete-frame lsp-bridge-diagnostic-frame))

(acm-frame-create-frame-if-not-exist lsp-bridge-diagnostic-frame
lsp-bridge-diagnostic-buffer
"lsp bridge diagnostic frame"
1
t)

(acm-frame-set-frame-max-size lsp-bridge-diagnostic-frame nil nil)

(let ((pos (acm-frame-get-popup-position (point) 1)))
(acm-frame-set-frame-position lsp-bridge-diagnostic-frame (car pos) (cdr pos)))

(acm-frame-adjust-frame-pos lsp-bridge-diagnostic-frame))
(t (message diagnostic-message)))))

(defun lsp-bridge-diagnostic-maybe-display-error-at-point ()
Expand Down
Loading

0 comments on commit 46ff169

Please sign in to comment.