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): preliminary support for vim.lsp.config #660

Merged
merged 1 commit into from
Jan 22, 2025
Merged
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
13 changes: 10 additions & 3 deletions doc/rustaceanvim.txt
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,16 @@ Notes:
rustaceanvim.Opts *rustaceanvim.Opts*

Fields: ~
{tools?} (rustaceanvim.tools.Opts) Plugin options
{server?} (rustaceanvim.lsp.ClientOpts) Language server client options
{dap?} (rustaceanvim.dap.Opts) Debug adapter options
{tools?} (rustaceanvim.tools.Opts)
Plugin options.
{server?} (rustaceanvim.lsp.ClientOpts)
Language server client options.
In Neovim >= 0.11 (nightly), these can also be set using |vim.lsp.config()| for "rust-analyzer".
If both the `server` table and a `vim.lsp.config["rust-analyzer"]` are defined,
the |vim.lsp.config()| settings are merged into the `server` table, taking precedence over
existing settings.
{dap?} (rustaceanvim.dap.Opts)
Debug adapter options


rustaceanvim.tools.Opts *rustaceanvim.tools.Opts*
Expand Down
16 changes: 13 additions & 3 deletions lua/rustaceanvim/config/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,19 @@ local config = {}
vim.g.rustaceanvim = vim.g.rustaceanvim

---@class rustaceanvim.Opts
---@field tools? rustaceanvim.tools.Opts Plugin options
---@field server? rustaceanvim.lsp.ClientOpts Language server client options
---@field dap? rustaceanvim.dap.Opts Debug adapter options
---
---Plugin options.
---@field tools? rustaceanvim.tools.Opts
---
---Language server client options.
---In Neovim >= 0.11 (nightly), these can also be set using |vim.lsp.config()| for "rust-analyzer".
---If both the `server` table and a `vim.lsp.config["rust-analyzer"]` are defined,
---the |vim.lsp.config()| settings are merged into the `server` table, taking precedence over
---existing settings.
---@field server? rustaceanvim.lsp.ClientOpts
---
---Debug adapter options
---@field dap? rustaceanvim.dap.Opts

---@class rustaceanvim.tools.Opts
---
Expand Down
7 changes: 5 additions & 2 deletions lua/rustaceanvim/lsp/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ local os = require('rustaceanvim.os')
local rustc = require('rustaceanvim.rustc')
local compat = require('rustaceanvim.compat')

local ra_client_name = 'rust-analyzer'

local function override_apply_text_edits()
local old_func = vim.lsp.util.apply_text_edits
---@diagnostic disable-next-line
Expand Down Expand Up @@ -162,7 +164,8 @@ end
M.start = function(bufnr)
bufnr = bufnr or vim.api.nvim_get_current_buf()
local bufname = vim.api.nvim_buf_get_name(bufnr)
local client_config = config.server
local ra_config = type(vim.lsp.config) == 'table' and vim.lsp.config[ra_client_name] or {}
local client_config = vim.tbl_deep_extend('force', config.server, ra_config)
---@type rustaceanvim.lsp.StartConfig
local lsp_start_config = vim.tbl_deep_extend('force', {}, client_config)
local root_dir = cargo.get_config_root_dir(client_config, bufname)
Expand Down Expand Up @@ -252,7 +255,7 @@ Starting rust-analyzer client in detached/standalone mode (with reduced function
end
---@cast rust_analyzer_cmd string[]
lsp_start_config.cmd = rust_analyzer_cmd
lsp_start_config.name = 'rust-analyzer'
lsp_start_config.name = ra_client_name
lsp_start_config.filetypes = { 'rust' }

local custom_handlers = {}
Expand Down
Loading