golang 的 lsp-mode非常卡, 有什么解决办法吗

看代码还行, 跳转比较正常, 敲字就会遇到 “No Ast for file://blabla”, 然后卡住. language server 用的 gopls.

I think that the issue is caused by project not being under ~/go/src/PROJECT.

1 个赞

啊, 果然是…

想问下楼主你的lsp-mode是怎么配置的,我这里执行lsp的时候老是提示

LSP :: No LSP server for go-mode.

我的配置是

(use-package lsp-mode
  :hook (go-mode . lsp)
  :commands lsp)
(setq lsp-clients-go-command "/usr/local/go/bin/gopls")

(add-hook 'go-mode-hook #'lsp)

;; optional - provides fancier overlays
(use-package lsp-ui
  :commands lsp-ui-mode)

;; if you use company-mode for completion (otherwise, complete-at-point works out of the box):
(use-package company-lsp
  :commands company-lsp)

(use-package lsp-treemacs :commands lsp-treemacs-errors-list)

然后我也按照lsp-mode的说明通过命令安装了gopls

go get -u golang.org/x/tools/cmd/gopls

但是也一直没有正常

我是参考了这个, 需要用 lsp-register-client 注册 gopls:

好的,谢谢 顺便问一下你的emacs版本,我的是25.2.2,不知道有没有这个问题

GNU Emacs 25.2.2 (x86_64-pc-linux-gnu, GTK+ Version 3.22.21) of 2017-09-23, modified by Debian

我的 emacs version 是 26.2 .

发现用emacs读代码简直好极了, 可以随意用org mode做笔记, 搜索也非常直观.

好的,谢谢,我再试试

知道是什么原因了,我的lsp-mode版本是6.0,默认用的是go-langserver的后端

(lsp-register-client
 (make-lsp-client :new-connection (lsp-stdio-connection "go-langserver")
                  :major-modes '(go-mode)
                  :priority -2
                  :initialization-options 'lsp-clients-go--make-init-options
                  :server-id 'go-ls
                  :library-folders-fn (lambda (_workspace)
                                        lsp-clients-go-library-directories)))

再次感谢

Check the content of *lsp-log*. My guess is that gopls path is wrong.

是怎么个做笔记的方式?感觉能提升效率

就是简单的 org capture 啊,写 notes 或者 todo,集中到一个地方之后整理。

多谢。那可以的,用过几次,这个没太用熟练。以前在浏览器里装了个插件,抓取网页链接,保存不了。