如何toggle lsp-ui-doc-mode

想给lsp-ui-doc-mode绑定个快捷键, (global-set-key (kbd "s-j") #'lsp-ui-doc-mode), 但是发现如果在有lsp-ui-doc frame 的情况下,toggle掉的时候frame并不会消失。 求教如何正确的toggle掉。

15 动画里一开始disable就是调用了快捷键toggle off lsp-ui-doc-mode

直接M-x lsp-ui-doc-mode的话是会直接消失的。

提供个思路:

(defun toggle-lsp-ui-doc ()
  "Toggle `lsp-ui-doc-mode`."
  (interactive)
  (if lsp-ui-doc-mode
      (setq lsp-ui-doc-mode nil)
    (setq lsp-ui-doc-mode t)))

(global-set-key (kbd "s-j") #'toggle-lsp-ui-doc)

没有细究过lsp-ui-doc-mode, 不过这个函数应该可以用的

试了下并不行。

我刚刚理解错了,我觉得你的表述也不对,你想要的并不是toggle lsp-ui-doc-mode, 而是去掉lsp-ui-doc-mode 产生的frame,所以无论是你 M-x lsp-ui-doc-mode 还是我的函数,都已经将lsp-ui-doc-mode 关掉了,但是都不会将frame 去掉的

M-x 调用lsp-ui-doc-mode是会去掉的,试一下就知道了。

Peek 2018-06-09 12-48

如图,我刚刚试了一下,你的绑定方法是没错的,用快捷键的确是可以 toggle lsp-ui-doc-mode(注意留意minibuffer 的提示).如果快捷键都可以toggle lsp-ui-doc-mode,那么为什么却不能去掉frame 呢?因为当你用快捷键toggle lsp-ui-doc-mode的时候,光标的焦点是停留在需要提示doc 的内容上面,而当你用M-x lsp-ui-doc-mode 关掉 lsp-ui-doc-mode, 而frame 会消失的原因在于光标的焦点已经不在需要提示doc的内容上面了,而是在minibuffer 上了,所以你调用M-x lsp-ui-doc-mode, frame 自然会消失.

1 个赞

原来如此,那么有没有什么函数可以刷新下,或者清除下chilidframe的

childframe 不大了解呢 :zipper_mouth_face:

进源码 或者 describe-function搜一下就好了

(defun lsp-ui-doc--delete-frame ()
  "Delete the child frame if it exists."
  (-when-let (frame (lsp-ui-doc--get-frame))
    (delete-frame frame)
    (lsp-ui-doc--set-frame nil)))

弄好了,谢谢啦。默认启动disable了lsp-ui-doc-modelsp-ui-doc-mode参数竟然不支持t, nil,只能是1, -1。

(defun toggle-lsp-ui-doc ()
  (interactive)
  (if lsp-ui-doc-mode
      (progn
        (lsp-ui-doc-mode -1)
        (lsp-ui-doc--delete-frame))
    (progn
      (lsp-ui-doc-mode 1)
      (lsp-ui-doc--make-request))))

(defun my-lsp-mode-hook ()
  ;; delete-lsp-ui-doc frame is exists, and disable lsp-ui-doc by default
  (lsp-ui-doc--delete-frame)
  (lsp-ui-doc-mode -1)

  ;; overwrite s-j key for toggle-lsp-ui-doc
  (global-set-key (kbd "s-j") #'toggle-lsp-ui-doc))
(add-hook 'lsp-mode-hook #'my-lsp-mode-hook)
2 个赞

现在还是有一些小问题。

  1. 如果是从disable的状态到enable,只有没有send request过的单词才能马上显示lsp-ui-doc,send过的就不行了,得要移动到其他单词再移回去才行。也就是说只有第一次调用toggle-lsp-ui-doc去enable才有效,而disable的话是都没有问题的。

  2. 在启动了lsp-ui-mode的layout调用toggle-lsp-ui,然后移动到其他layout,就会出现没有清理掉的buffer。

改用lsp-ui-doc–hide-frame试试?

layout的话感觉比较复杂。。可以试试看能不能把这类buffer加到ignore list里。。

2 个赞

用hide frame两个问题都解决了。。。

(defun toggle-lsp-ui-doc ()
  (interactive)
  (if lsp-ui-doc-mode
      (progn
        (lsp-ui-doc-mode -1)
        (lsp-ui-doc--hide-frame))
    (lsp-ui-doc-mode 1)))
(defun my-lsp-mode-hook ()
  ;; delete-lsp-ui-doc frame is exists, and disable lsp-ui-doc by default
  (lsp-ui-doc--hide-frame)
  (lsp-ui-doc-mode -1)

  ;; overwrite s-j key for toggle-lsp-ui-doc
  (global-set-key (kbd "C-j") #'toggle-lsp-ui-doc))
(add-hook 'lsp-mode-hook #'my-lsp-mode-hook)

看来它确实是记录了之前请求过的关键字,直接delete了frame的话得重新访问才行。

4 个赞

foo-mode的参数好像大部分都是1 -1这样的,t nil不行我好像也碰到过,后来看大家都用1 -1就心领神会了

请问注释部分是什么字体