From 9bdb154a9b7df8e0dc04f4e5dcc323b5d29062d3 Mon Sep 17 00:00:00 2001 From: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> Date: Fri, 21 Jun 2024 12:44:19 +0200 Subject: [PATCH] snippets: Read user settings for workspace configuration (#13356) Fixes #13334 Use `settings` field in `lsp` subsettings to fix up the settings as wish: ``` "lsp": { "snippet-completion-server": { "settings": { "max_completion_items": 20, "snippets_first": false, "feature_words": true, "feature_snippets": true, "feature_paths": true, "feature_unicode_input": false } } } ``` Release Notes: - N/A --- Cargo.lock | 2 +- extensions/snippets/Cargo.toml | 2 +- extensions/snippets/extension.toml | 6 ++--- extensions/snippets/src/snippets.rs | 40 ++++++++++++----------------- 4 files changed, 21 insertions(+), 29 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4d86283942..848752db02 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13587,7 +13587,7 @@ dependencies = [ [[package]] name = "zed_snippets" -version = "0.0.3" +version = "0.0.4" dependencies = [ "serde_json", "zed_extension_api 0.0.6", diff --git a/extensions/snippets/Cargo.toml b/extensions/snippets/Cargo.toml index 7a2e4419e8..5543b19359 100644 --- a/extensions/snippets/Cargo.toml +++ b/extensions/snippets/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "zed_snippets" -version = "0.0.3" +version = "0.0.4" edition = "2021" publish = false license = "Apache-2.0" diff --git a/extensions/snippets/extension.toml b/extensions/snippets/extension.toml index f9834783dd..fd0c25aa39 100644 --- a/extensions/snippets/extension.toml +++ b/extensions/snippets/extension.toml @@ -1,15 +1,15 @@ id = "snippets" name = "Snippets" description = "Support for language-agnostic snippets, provided by simple-completion-language-server" -version = "0.0.3" +version = "0.0.4" schema_version = 1 authors = [] repository = "https://github.com/zed-industries/zed" [language_servers.snippet-completion-server] name = "Snippet Completion Server" -languages = ["Astro", "Clojure", "C", "C++", "C#", "Dart", "Elixir", "Elm", "ERB", "Erlang", - "Gleam","GLSL", "Go", "Haskell", "HCL", "HEEX", "HTML", "JavaScript","JSDoc","Lua", +languages = ["Astro", "Clojure", "C", "C++", "C#", "Dart", "Dockerfile", "Elixir", "Elm", "ERB", "Erlang", + "Gleam","GLSL", "Go", "Haskell", "HCL", "HEEX", "HTML", "JavaScript","JSDoc", "JSON", "Lua", "Markdown","OCaml", "PHP", "Python", "Prisma", "PureScript", "Racket", "Ruby", "Rust", "Scheme", "Shell Script", "Svelte", "Terraform", "TOML", "TypeScript", "TSX", "Uiua", "Vue.js", "Zig"] language_ids = { TypeScript = "typescript", TSX = "typescriptreact", JavaScript = "javascript", "Vue.js" = "vue", Terraform = "terraform", "Terraform Vars" = "terraform-vars", PHP = "php", HTML = "html", CSS = "css" } diff --git a/extensions/snippets/src/snippets.rs b/extensions/snippets/src/snippets.rs index 8a169e7ccc..98ca37593a 100644 --- a/extensions/snippets/src/snippets.rs +++ b/extensions/snippets/src/snippets.rs @@ -1,7 +1,7 @@ use serde_json::json; use std::fs; use zed::LanguageServerId; -use zed_extension_api::{self as zed, Result}; +use zed_extension_api::{self as zed, settings::LspSettings, Result}; struct SnippetExtension { cached_binary_path: Option, @@ -106,32 +106,24 @@ impl zed::Extension for SnippetExtension { }) } - fn language_server_initialization_options( - &mut self, - _language_server_id: &LanguageServerId, - _worktree: &zed_extension_api::Worktree, - ) -> Result> { - Ok(Some(json!({ - "max_completion_items": 20, - "snippets_first": true, - "feature_words": false, - "feature_snippets": true, - "feature_paths": true - }))) - } - fn language_server_workspace_configuration( &mut self, - _language_server_id: &LanguageServerId, - _worktree: &zed_extension_api::Worktree, + server_id: &LanguageServerId, + worktree: &zed_extension_api::Worktree, ) -> Result> { - Ok(Some(json!({ - "max_completion_items": 20, - "snippets_first": true, - "feature_words": false, - "feature_snippets": true, - "feature_paths": true - }))) + let settings = LspSettings::for_worktree(server_id.as_ref(), worktree) + .ok() + .and_then(|lsp_settings| lsp_settings.settings.clone()) + .unwrap_or_else(|| { + json!({ + "max_completion_items": 20, + "snippets_first": true, + "feature_words": false, + "feature_snippets": true, + "feature_paths": true + }) + }); + Ok(Some(settings)) } }