From b47aff4c144f6c96a2e4328447fdf050856c6b85 Mon Sep 17 00:00:00 2001 From: Thorsten Ball Date: Wed, 14 Feb 2024 18:29:42 +0100 Subject: [PATCH] go: enable completions with placeholders by default (#7780) This fixes #7523 by enabling completions with placeholders by default. This setting controls whether gopls sends back snippets with placeholders. According to the documentation (https://github.com/golang/tools/blob/master/gopls/doc/settings.md#useplaceholders-bool) this only controls whether "placeholders for function parameters or struct fields" are sent in completion responses. In practice, though, this seems to also control whether any snippets with *any* placeholders are being sent back. Example: for the given Go code err := myFunction() i^ With the cursor being at `^`, this setting controls whether `gopls` sends back statement snippets such as `if err != nil { return ... }` with the `...` being dynamically matched to the return value of the function. So I think this setting controls far more than just function params and struct fields. And since we *do* support placeholders in snippets, I think this provides a better default experience. Release Notes: - Improved default Go experience by enabling snippets-with-placeholders when initializing `gopls`. ([#7523](https://github.com/zed-industries/zed/issues/7523)). --- crates/zed/src/languages/go.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/crates/zed/src/languages/go.rs b/crates/zed/src/languages/go.rs index 0c2843c03fd9694c057d34b333920fbfaed0bad9..cb171d5bd30fe22f7844d9d69be2e36895258ab6 100644 --- a/crates/zed/src/languages/go.rs +++ b/crates/zed/src/languages/go.rs @@ -6,6 +6,7 @@ pub use language::*; use lazy_static::lazy_static; use lsp::LanguageServerBinary; use regex::Regex; +use serde_json::json; use smol::{fs, process}; use std::{ any::Any, @@ -170,6 +171,12 @@ impl super::LspAdapter for GoLspAdapter { }) } + fn initialization_options(&self) -> Option { + Some(json!({ + "usePlaceholders": true, + })) + } + async fn label_for_completion( &self, completion: &lsp::CompletionItem,