refactor
This commit is contained in:
parent
aabb6bf2bc
commit
eedb67c18d
|
@ -1,10 +1,8 @@
|
||||||
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',
|
||||||
'--background-index',
|
'--background-index',
|
||||||
|
@ -14,12 +12,11 @@ local function build_cmd(commands_dir)
|
||||||
'--resource-dir=' .. vim.fn.trim(vim.fn.system 'clang++ --print-resource-dir'),
|
'--resource-dir=' .. vim.fn.trim(vim.fn.system 'clang++ --print-resource-dir'),
|
||||||
'--compile-commands-dir=' .. commands_dir,
|
'--compile-commands-dir=' .. commands_dir,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.reload_clangd(commands_dir)
|
|
||||||
local lspconfig = require 'lspconfig'
|
|
||||||
|
|
||||||
|
local function reload_clangd(commands_dir)
|
||||||
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),
|
||||||
|
@ -29,9 +26,12 @@ 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,19 +42,16 @@ 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,
|
||||||
})
|
})
|
||||||
: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,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue