This commit is contained in:
dlond 2025-05-29 22:56:44 +12:00
parent aabb6bf2bc
commit eedb67c18d
1 changed files with 51 additions and 54 deletions

View File

@ -1,9 +1,7 @@
local M = {}
local pickers = require 'telescope.pickers'
local finders = require 'telescope.finders'
local conf = require('telescope.config').values
return {
'neovim/nvim-lspconfig',
ft = { 'c', 'cpp', 'objc', 'objcpp', 'cuda' },
config = function()
local function build_cmd(commands_dir)
return {
'clangd',
@ -16,10 +14,9 @@ local function build_cmd(commands_dir)
}
end
function M.reload_clangd(commands_dir)
local lspconfig = require 'lspconfig'
local function reload_clangd(commands_dir)
commands_dir = commands_dir or './build/debug'
local lspconfig = require 'lspconfig'
lspconfig.clangd.setup {
cmd = build_cmd(commands_dir),
@ -31,7 +28,10 @@ function M.reload_clangd(commands_dir)
vim.cmd.edit()
end
function M.pick_commands_dir()
local function pick_commands_dir()
local pickers = require 'telescope.pickers'
local finders = require 'telescope.finders'
local conf = require('telescope.config').values
pickers
.new({}, {
prompt_title = 'Choose compile_commands.json location',
@ -42,7 +42,7 @@ function M.pick_commands_dir()
local entry = require('telescope.actions.state').get_selected_entry()
local commands_dir = entry[1]
require('telescope.actions').close(prompt_bufnr)
M.reload_clangd(commands_dir)
reload_clangd(commands_dir)
end)
return true
end,
@ -50,11 +50,8 @@ function M.pick_commands_dir()
:find()
end
return {
'neovim/nvim-lspconfig',
ft = { 'c', 'cpp', 'objc', 'objcpp', 'cuda' },
config = function()
M.reload_clangd()
vim.keymap.set('n', '<leader>cc', M.pick_commands_dir, { desc = 'Pick location of compile_commands.json for clangd' })
reload_clangd()
vim.keymap.set('n', '<leader>cc', pick_commands_dir, { desc = 'Pick location of compile_commands.json for clangd' })
end,
}