diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c598556..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 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 )