cleanup
This commit is contained in:
parent
75f6ecf3cf
commit
0ffa41411b
|
@ -5,10 +5,14 @@ local lspconfig = require 'lspconfig'
|
||||||
|
|
||||||
local function find_compile_commands()
|
local function find_compile_commands()
|
||||||
local results = vim.fn.systemlist { 'fd', '-u', '-t', 'f', 'compile_commands.json' }
|
local results = vim.fn.systemlist { 'fd', '-u', '-t', 'f', 'compile_commands.json' }
|
||||||
|
if vim.tbl_isempty(results) then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
table.sort(results, function(a, b)
|
table.sort(results, function(a, b)
|
||||||
return a:match 'debug' and not b:match 'debug'
|
return a:match 'debug' and not b:match 'debug'
|
||||||
end)
|
end)
|
||||||
return vim.fn.fnamemodify(results[1] or '', ':h')
|
return vim.fn.fnamemodify(results[1], ':h')
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.stop_clangd()
|
function M.stop_clangd()
|
||||||
|
@ -31,14 +35,14 @@ function M.start_clangd(dir)
|
||||||
'--clang-tidy',
|
'--clang-tidy',
|
||||||
'--header-insertion=never',
|
'--header-insertion=never',
|
||||||
'--query-driver=' .. vim.fn.exepath 'clang++',
|
'--query-driver=' .. vim.fn.exepath 'clang++',
|
||||||
'--resource-dir=' .. vim.fn.systemlist({ 'clang++', '--print-resource-dir' })[1] or '',
|
'--resource-dir=' .. vim.fn.systemlist({ 'clang++', '--print-resource-dir' })[1],
|
||||||
}
|
}
|
||||||
if dir and dir ~= '' then
|
if dir and dir ~= '' then
|
||||||
vim.notify('[clangd] Setting up with: ' .. dir)
|
vim.notify('[clangd] Setting up with: ' .. dir)
|
||||||
table.insert(cmd, '--compile-commands-dir=' .. dir)
|
table.insert(cmd, '--compile-commands-dir=' .. dir)
|
||||||
M.watch_compile_commands(dir)
|
M.watch_compile_commands(dir)
|
||||||
else
|
else
|
||||||
vim.notify '[clangd] Empty or nil --compile-commands-dir'
|
vim.notify '[clangd] Could not find compile_commands.json.\nUse <leader>lc to manually set location when available.'
|
||||||
end
|
end
|
||||||
|
|
||||||
lspconfig.clangd.setup {
|
lspconfig.clangd.setup {
|
||||||
|
@ -70,13 +74,6 @@ function M.watch_compile_commands(dir)
|
||||||
debounce_timer = nil
|
debounce_timer = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
local dir = dir or vim.fn.getcwd()
|
|
||||||
local file = dir .. '/compile_commands.json'
|
|
||||||
|
|
||||||
if not vim.fn.filereadable(file) then
|
|
||||||
vim.notify '[clangd] No compile_commands.json found.\nUse <leader>cc to manually set location when available.'
|
|
||||||
end
|
|
||||||
|
|
||||||
watcher = uv.new_fs_event()
|
watcher = uv.new_fs_event()
|
||||||
watcher:start(
|
watcher:start(
|
||||||
dir,
|
dir,
|
||||||
|
|
Loading…
Reference in New Issue