如何在Doom Emacs中启用Go支持?

huangapple go评论76阅读模式
英文:

How to enable go support in doom emacs

问题

我是你的中文翻译助手,以下是翻译的内容:

我对Emacs还不熟悉。我创建了一个Go文件,但是没有语法高亮、自动完成等功能。

我在init.el中取消了":lang go"的注释,但是没有任何效果。我尝试运行"lang: go",但在init.el中没有LSP选项。

英文:

I am new to emacs.I created a go file but there were no syntax highlighting,auto completion etc.

I uncommented :lang go in init.el but it didnt do anything.I tried running lang: go.There was no option of lsp in init.el .

答案1

得分: 2

简单的方法

你可以简单地将go-mode包添加到你的init.el中,这样你就会有代码高亮

(use-package go-mode
  :ensure t)

较困难的方法

如果你想要进行自动补全重构等操作,你将需要使用LSP

  • 首先,将以下代码添加到你的init.el中,以使用所需的Go支持的go-mode包,并设置一个钩子来启用LSP
(use-package go-mode
  :ensure t
  :hook (go-mode . lsp-deferred))
  • 然后,通过将lsp-mode包添加到你的init.el中,启用LSP的基础设施:
(use-package lsp-mode
  :ensure t
  :commands lsp)
  • 最后,添加LSP的用户界面:
(use-package lsp-ui
  :ensure t
  :commands lsp-ui-mode)
英文:

Simple Way

You can simply add the go-mode package to your init.el and you'll have the code highlight :

(use-package go-mode
  :ensure t)

Harder Way

If you want to do things like auto-completion or refactoring, you'll need the LSP.

  • At first, add the following code to your init.el to use the go-mode package required for Go support and setup a hook to enable the LSP for it :
(use-package go-mode
  :ensure t
  :hook (go-mode . lsp-deferred))
  • Then, enable the infrastructure of LSP by adding the lsp-mode package to your init.el :
(use-package lsp-mode
  :ensure t
  :commands lsp)
  • Finally, add the user interface for the LSP :
(use-package lsp-ui
  :ensure t
  :commands lsp-ui-mode)

huangapple
  • 本文由 发表于 2023年7月18日 21:11:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/76713149.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定