Logo

dev-resources.site

for different kinds of informations.

Go LSP in Sublime Text

Published at
1/1/2021
Categories
go
sublimetext
lsp
editor
Author
vuong
Categories
4 categories in total
go
open
sublimetext
open
lsp
open
editor
open
Author
5 person written this
vuong
open
Go LSP in Sublime Text

Here is how to configure LSP (language server protocol) for Go development in Sublime Text.

Prerequisites

  • go
  • gopls
  • gotools (gofmt, goimports...)

Packages

  • sublimelsp/LSP

LSP settings

Open LSP Settings, then paste the below one

// for MacOS

{
    "clients":
    {
        "gopls":
        {
            "command": [
                "<path_to>/go/bin/gopls",
                "-v",
                "-rpc.trace",
                "-logfile=<path_to>/gopls.log"
            ],
            "enabled": true,
            "env": {
                "PATH": "<echo $PATH in terminal then paste its value here>"
            },
            "scopes":["source.go"],
            "syntaxes": ["Packages/Go/Go.sublime-syntax"],
            "settings": {
                "gopls.usePlaceholders": true,
                "gopls.completeUnimported": true,
            },
            "languageId": "go"

        }
    }
}
Enter fullscreen mode Exit fullscreen mode

// for Windows

{
    "clients":
    {
        "gopls":
        {
            "command": [
                "<path_to>\\bin\\gopls.EXE",
                "-v",
                "-rpc.trace",
                "-logfile=<path_to>\\gopls.log"
            ],
            "enabled": true,
            "scopes":["source.go"],
            "syntaxes": ["Packages/Go/Go.sublime-syntax"],
            "settings": {
                "gopls.usePlaceholders": true,
                "gopls.completeUnimported": true,
            },
            "languageId": "go"
        },
    }
}
Enter fullscreen mode Exit fullscreen mode

LSP Key Binding

Search LSP Key Binding then paste the below value into the field

[
    // Go To Definition
    {
        "command": "lsp_symbol_definition",
        "args": {
            "side_by_side": false
        },
        "keys": [
            "ctrl+d"
        ],
        "context": [
            {
                "key": "lsp.session_with_capability",
                "operator": "equal",
                "operand": "definitionProvider"
            },
            {
                "key": "auto_complete_visible",
                "operator": "equal",
                "operand": false
            }
        ]
    },
]

Enter fullscreen mode Exit fullscreen mode

Known Issues

  • Auto-format on macOS doesn't work but works well on Windows

=====

Updated: This package is now working well with simple set up. https://packagecontrol.io/packages/LSP-gopls

Gofumpt for auto-format also works: https://github.com/mvdan/gofumpt#sublime-text

lsp Article's
30 articles in total
Favicon
How to Setup Vim for Kotlin Development
Favicon
Managing LSPs in Neovim: Enable/Disable for the Entire Session
Favicon
Integrating the ruff language server
Favicon
Series Belajar Solid Principle - Liskov Substitution Principle (LSP)
Favicon
Avoid conflicts between denols and tsserver in Neovim
Favicon
Avoid conflicts between denols and tsserver in Neovim
Favicon
Implementing Payment Gateways with the Liskov Substitution Principle
Favicon
SOLID Principles: Liskov Substitution Principle (LSP)
Favicon
Configure Helix to use ElixirLS
Favicon
The Power of Liskov Substitution Principle in Improving Software Design
Favicon
Neovim config from scratch (Part II)
Favicon
Neovim config from scratch (Part I)
Favicon
Integrating a Language Server (LSP) in a VS Code Extension
Favicon
My Neovim setup for React, TypeScript, Tailwind CSS, etc
Favicon
How i setup neovim for speed up React, Js, Ts, etc
Favicon
Solve nvim lsp denols vs tsserver clash
Favicon
Perl Navigator - Language Server for Perl
Favicon
Neovim LSP Setup + Code Completion Engine
Favicon
NeoVim: init.lua, built in LSP e mais
Favicon
How to fix [deno-ts 2339] in the code for Deno Deploy
Favicon
SOLID e o princípio do 6 por meia dúzia
Favicon
Java LSP in Sublime Text
Favicon
Neovim: Migrando do coc.vim para nvim-lsp
Favicon
Integrating Scala Metals with Doom Emacs using LSP on Pop!_OS/Ubuntu 20.04 LTS
Favicon
Builtin Solidity Language Server
Favicon
Liskov Substitution Principle
Favicon
Emacs as SQL client with LSP
Favicon
Vim Configuration from Minimal to Complete
Favicon
LSP and ISP: The LI of SOLID
Favicon
Go LSP in Sublime Text

Featured ones: