From 0348f421ad873c8e83ee3b68f4ed02232af63da0 Mon Sep 17 00:00:00 2001 From: Porrith Suong Date: Sun, 15 Sep 2024 23:42:25 -0400 Subject: [PATCH 1/4] fear: loops through potential completion plugins + picks the first available one --- lua/rustaceanvim/config/server.lua | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/lua/rustaceanvim/config/server.lua b/lua/rustaceanvim/config/server.lua index 0b09cf44..56ec20bc 100644 --- a/lua/rustaceanvim/config/server.lua +++ b/lua/rustaceanvim/config/server.lua @@ -131,12 +131,34 @@ local function mk_capabilities_if_available(mod_name, callback) return {} end +---@param modules table +---@return lsp.ClientCapabilities +local function mk_capabilities_for_completion(modules) + for _, tuple in ipairs(modules) do + local available, mod = pcall(require, tuple.mod_name) + + if available and type(mod) == 'table' then + local ok, capabilities = pcall(tuple.callback) + if ok then + return capabilities + end + end + end + + return {} +end + ---@return lsp.ClientCapabilities function server.create_client_capabilities() local rs_capabilities = make_rustaceanvim_capabilities() - local cmp_capabilities = mk_capabilities_if_available('cmp_nvim_lsp', function(cmp_nvim_lsp) - return cmp_nvim_lsp.default_capabilities() - end) + + local modules = { + { name = 'cmp_nvim_lsp', callback = function (cmp_nvim_lsp) return cmp_nvim_lsp.default_capabilities() end }, + { name = 'ddc_source_lsp', callback = function (ddc_source_lsp) return ddc_source_lsp.make_client_capabilities() end } + } + + local capabilities = mk_capabilities_for_completion(modules) + local selection_range_capabilities = mk_capabilities_if_available('lsp-selection-range', function(lsp_selection_range) return lsp_selection_range.update_capabilities {} end) @@ -153,7 +175,7 @@ function server.create_client_capabilities() return vim.tbl_deep_extend( 'force', rs_capabilities, - cmp_capabilities, + capabilities, selection_range_capabilities, folding_range_capabilities ) From 62cf5eb20a4e48a592d653d9910dcc18c55484a2 Mon Sep 17 00:00:00 2001 From: Porrith Suong Date: Sun, 15 Sep 2024 23:51:21 -0400 Subject: [PATCH 2/4] feat: updates changelog with details of ddc_source_lsp --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2eb83f55..b63380eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Deprecate `rust-analyzer.json` in favour of `.vscode/settings.json` or `:h exrc`. +- Adds support for ddc_source_lsp client capabilities for auto import. ## [5.4.2] - 2024-09-12 From 9a89163658840e4499fa03b0c14bb54cb236c480 Mon Sep 17 00:00:00 2001 From: Porrith Suong Date: Sun, 15 Sep 2024 23:52:07 -0400 Subject: [PATCH 3/4] feat: adds 'Added' section to unreleased --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b63380eb..735d4aa0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Deprecate `rust-analyzer.json` in favour of `.vscode/settings.json` or `:h exrc`. + +### Added - Adds support for ddc_source_lsp client capabilities for auto import. ## [5.4.2] - 2024-09-12 From 6c2fdbd95cd3099ed8633bfbde6d63c7ee99ca64 Mon Sep 17 00:00:00 2001 From: Porrith Suong Date: Mon, 16 Sep 2024 17:09:00 -0400 Subject: [PATCH 4/4] feat: Amends the changelog for unreleased version. --- CHANGELOG.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c9d2fdd7..49f53cd0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased + +### Added +- Adds support for ddc_source_lsp client capabilities for auto import. + ## [5.5.0] - 2024-09-16 ### Changed @@ -13,9 +18,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Deprecate `rust-analyzer.json` in favour of `.vscode/settings.json` or `:h exrc`. -### Added -- Adds support for ddc_source_lsp client capabilities for auto import. - ## [5.4.2] - 2024-09-12 ### Fixed