lsp 模式,用于因“会话中没有视图”而出错

Bus*_*sch 3 emacs go language-server-protocol

我正在努力实现的目标

我想一起使用 go-mode/lsp-mode 。我一开始就很难让 lsp-mode 执行,最后通过附加路径 :facepalm: 让它工作。

问题 现在的问题是,当 lsp-mode 为工作 golang 目录启动时,我收到此错误:

LSP :: Error from the Language Server: no views in the session (Unknown error) [3 times]
Run Code Online (Sandbox Code Playgroud)

我在互联网上搜索答案,但尚未找到与我的问题相关的任何内容。我正在向社区寻求一些指导。

go-mode.el

LSP :: Error from the Language Server: no views in the session (Unknown error) [3 times]
Run Code Online (Sandbox Code Playgroud)

lsp模式.el

(defun custom-go-mode ()
  (display-line-numbers-mode 1))

(use-package go-mode
:defer t
:ensure t
:mode ("\\.go\\'" . go-mode)
:init
  (setq compile-command "echo Building... && go build -v && echo Testing... && go test -v && echo Linter... && golint")  
  (setq compilation-read-command nil)
  (add-hook 'go-mode-hook 'custom-go-mode)
:bind (("M-," . compile)
("M-." . godef-jump)))

(setq compilation-window-height 14)
(defun my-compilation-hook ()
  (when (not (get-buffer-window "*compilation*"))
    (save-selected-window
      (save-excursion
    (let* ((w (split-window-vertically))
           (h (window-height w)))
      (select-window w)
      (switch-to-buffer "*compilation*")
      (shrink-window (- h compilation-window-height)))))))
(add-hook 'compilation-mode-hook 'my-compilation-hook)

(global-set-key (kbd "C-c C-c") 'comment-or-uncomment-region)
(setq compilation-scroll-output t)
Run Code Online (Sandbox Code Playgroud)

kst*_*art 6

当 go 环境不正确时,我就遇到过这种情况。

作为诊断,请尝试从lsp-mode.el中注释掉go *并设置适当的环境变量(,如果您正在使用它),包括将和添加到。exec-pathsGOROOTGOPATHGO111MODULE$GOROOT/bin$GOPATH/binPATH

另外,如果仍然无法正常工作,请验证 emacs 中的环境变量设置是否正确。

当然,对于 Linux,您可以导出所有内容并从终端运行 emacs 进行测试。