Search code examples
goemacs

How to enable go support in doom emacs


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 .


Solution

  • 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)