refactor
This commit is contained in:
parent
aabb6bf2bc
commit
eedb67c18d
|
@ -1,10 +1,8 @@
|
|||
local M = {}
|
||||
|
||||
local pickers = require 'telescope.pickers'
|
||||
local finders = require 'telescope.finders'
|
||||
local conf = require('telescope.config').values
|
||||
|
||||
local function build_cmd(commands_dir)
|
||||
return {
|
||||
'neovim/nvim-lspconfig',
|
||||
ft = { 'c', 'cpp', 'objc', 'objcpp', 'cuda' },
|
||||
config = function()
|
||||
local function build_cmd(commands_dir)
|
||||
return {
|
||||
'clangd',
|
||||
'--background-index',
|
||||
|
@ -14,12 +12,11 @@ local function build_cmd(commands_dir)
|
|||
'--resource-dir=' .. vim.fn.trim(vim.fn.system 'clang++ --print-resource-dir'),
|
||||
'--compile-commands-dir=' .. commands_dir,
|
||||
}
|
||||
end
|
||||
|
||||
function M.reload_clangd(commands_dir)
|
||||
local lspconfig = require 'lspconfig'
|
||||
end
|
||||
|
||||
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),
|
||||
|
@ -29,9 +26,12 @@ function M.reload_clangd(commands_dir)
|
|||
}
|
||||
|
||||
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
|
||||
.new({}, {
|
||||
prompt_title = 'Choose compile_commands.json location',
|
||||
|
@ -42,19 +42,16 @@ 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,
|
||||
})
|
||||
:find()
|
||||
end
|
||||
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,
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue