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