LSP layer 如何使用啊?

刚刚看到 Spacemacs 在 develop分支上 添加了 lsp layer. 但是 README.org 上 的配置都是 引用 lsp-mode 和 lsp-ui的链接。 哪位大神 能给个傻瓜式的配置啊?多谢!

[spacemacs/layers/+tools/lsp at develop · syl20bnr/spacemacs · GitHub]

:face_with_raised_eyebrow:根本不需要什么配置,看文档做一遍就行了

现在 Spacemacs 只在 Python Layer 中能用 Lsp-mode。其他语言还没 Merge 到 Develop 分支。

Python Layer 的 README 写得很清楚了可以自己选择 Anaconda 或者 Lsp 作为后端。

(python :variables python-backend 'anaconda)

也可以在指定 Project 中使用 Lsp 作为后端。只要在 Project 的根目录下创建一个 .dir-locals.el。 ((python-mode (python-backend . lsp)))

dotspacemacs-configuration-layers

     lsp
     (python :variables python-backend 'lsp)
1 个赞

记得install一下pip install python-language-server

1 个赞

然后确保pyls在你的PATH目录里

1 个赞

多谢各位的指导,已经可以用了。

效果如何, 和之前的python layer比较?

有更多的提示,关于代码规范,还有接口描述,很棒!

1 个赞

速度怎样,卡顿吗?和 anaconda/jedi 相比呢?

我还在用25版本,感觉怪怪的,然后移到print关键字上会闪烁下。于是就先切回anaconda了。。

我感觉还可以啊

我都是这种错误,是什么情况:

Company: An error occurred in auto-begin 
Company: backend company-capf error "Nothing to complete" with args (prefix)
Company: An error occurred in auto-begin
Company: backend company-capf error "Nothing to complete" with args (prefix)

如果想要用lsp-ui的doc和sideline的话最好加一个自动开关的脚本。因为现在如果窗口比较窄的话doc会挡住窗口,sideline(可能)会导致排版混乱。

我现在是把这个moon/smart-toggle-lsp-ui加到window-configuration-change-hooklsp-ui-mode-hook里根据窗口宽度开关doc和sideline。

(defun moon/smart-toggle-lsp-ui ()
  "Decide if turn on lsp-ui-doc and sideline
depend on the width of the current window.
Should be added to window adjust hook and lsp-ui-mode hook"
  (let ((onoff (>= (window-width) 120)))
    (lsp-ui-sideline-enable onoff)
    (lsp-ui-doc-enable onoff)
    ))
1 个赞

能加强为如果手动开关过 lsp-ui-doc 或 lsp-ui-sidebar 就不要自动应用吗?

另外 lsp-ui-peek有时候会被 lsp-ui-doc childframe 挡住……

(defvar moon-smart-toggle-lsp-ui t
  "Whether to toggle lsp-ui doc and sideline automatically
depending on window width.")

(defvar moon-smart-toggle-threshold 120
  "If window width is above threshold, keep lsp-ui-doc/sideline on,
if under, turn them off.")

(defun moon/smart-toggle-lsp-ui ()
  "Decide if turn on lsp-ui-doc and sideline
depending on the width of the current window.
Should be added to window adjust hook and lsp-ui-mode hook.

If `moon-smart-toggle-lsp-ui' is nil, don't do anything.

If called interactively, `moon-smart-toggle-lsp-ui'
will be set to t."
  (interactive)
  (when (called-interactively-p 'any)
    (setq moon-smart-toggle-lsp-ui t))
  (when moon-smart-toggle-lsp-ui
    (let ((onoff (>= (window-width) moon-smart-toggle-threshold)))
      (lsp-ui-sideline-enable onoff)
      (lsp-ui-doc-enable onoff))))

(defun moon-force-lsp-ui (&rest rest)
  "Disable smart-toggle-lsp-ui."
  (interactive)
  (when (called-interactively-p 'any)
    (setq moon-smart-toggle-lsp-ui nil)))



;; 配置
  (add-hook 'window-configuration-change-hook
            #'moon/smart-toggle-lsp-ui)
  (add-hook 'lsp-ui-mode-hook
            #'moon/smart-toggle-lsp-ui)
  (advice-add 'lsp-ui-doc-mode :after #'moon-force-lsp-ui)
  (advice-add 'lsp-ui-sideline-mode :after #'moon-force-lsp-ui)

你看这样行不行?

我提了issue,lsp-ui的作者说在想办法改进。你可以帮我+1 :smile:

1 个赞

lsp (c-c++ :variables c-c+±backend 'lsp-ccls) dap ;; optionally