Gopls: Sublime Text の使用
LSP パッケージを使用します。Package Control を使用してインストールした後、次の手順を実行します。
- コマンドパレットを開きます
- LSP: 言語サーバーをグローバルに有効にするコマンドを見つけて実行します
- gopls アイテムを選択します。似た名前の golsp を誤って選択しないように注意してください。
最後に、LSP パッケージの 設定 と キーバインディング に慣れておく必要があります。これらは、メニュー項目 Preferences > Package Settings > LSP の下にあります。
例
Sublime Text が認識する PATH に gopls と go が存在することを前提とした、最小限のグローバル LSP 設定
{
"clients": {
"gopls": {
"enabled": true,
}
}
}
gopls と go を見つけるための特定の PATH、および Sublime LSP 自体の設定を提供するグローバル LSP 設定
{
"clients": {
"gopls": {
"enabled": true,
"env": {
"PATH": "/path/to/your/go/bin",
}
}
},
// Recommended by https://agniva.me/gopls/2021/01/02/setting-up-gopls-sublime.html
// except log_stderr mentioned there is no longer recognized.
"show_references_in_quick_panel": true,
"log_debug": true,
// These two are recommended by LSP-json as replacement for deprecated only_show_lsp_completions
"inhibit_snippet_completions": true,
"inhibit_word_completions": true,
}
LSP と gopls の設定は、グローバル設定を上書きするためにプロジェクトごとに調整することもできます。
{
"folders": [
{
"path": "/path/to/a/folder/one"
},
{
// If you happen to be working on Go itself, this can be helpful; go-dev/bin should be on PATH.
"path": "/path/to/your/go-dev/src/cmd"
}
],
"settings": {
"LSP": {
"gopls": {
// To use a specific version of gopls with Sublime Text LSP (e.g., to try new features in development)
"command": [
"/path/to/your/go/bin/gopls"
],
"env": {
"PATH": "/path/to/your/go-dev/bin:/path/to/your/go/bin",
"GOPATH": "",
},
"settings": {
"experimentalWorkspaceModule": true
}
}
},
// This will apply for all languages in this project that have
// LSP servers, not just Go, however cannot enable just for Go.
"lsp_format_on_save": true,
}
}
通常、これらの設定への変更はプロジェクトファイルを保存すると認識されますが、サーバーを再起動する (Tools > LSP > Restart Servers) か、Sublime Text 自体を終了して再起動する必要がある場合があります。
このドキュメントのソースファイルは、golang.org/x/tools/gopls/doc の下にあります。