Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(lsp): support ddc_source_lsp server capabilities #505

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 26 additions & 4 deletions lua/rustaceanvim/config/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
)
Expand Down