Skip to content

Commit 432a2a7

Browse files
committed
fix: correctly load clangd
Signed-off-by: abzcoding <abzcoding@gmail.com>
1 parent 1cf6dab commit 432a2a7

4 files changed

Lines changed: 91 additions & 92 deletions

File tree

after/ftplugin/c.lua

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
local opts = {}
2+
if lvim.builtin.cpp_programming.active then
3+
local clangd_flags = {
4+
"--background-index",
5+
"--fallback-style=google",
6+
"-j=12",
7+
"--all-scopes-completion",
8+
"--pch-storage=memory",
9+
"--clang-tidy",
10+
"--log=error",
11+
"--completion-style=detailed",
12+
"--header-insertion=iwyu",
13+
"--header-insertion-decorators",
14+
"--enable-config",
15+
"--offset-encoding=utf-16",
16+
"--ranking-model=heuristics",
17+
}
18+
19+
local provider = "clangd"
20+
21+
local custom_on_attach = function(client, bufnr)
22+
require("lvim.lsp").common_on_attach(client, bufnr)
23+
require("clangd_extensions.inlay_hints").setup_autocmd()
24+
require("clangd_extensions.inlay_hints").set_inlay_hints()
25+
end
26+
27+
local status_ok, project_config = pcall(require, "rhel.clangd_wrl")
28+
if status_ok then
29+
clangd_flags = vim.tbl_deep_extend("keep", project_config, clangd_flags)
30+
end
31+
32+
local custom_on_init = function(client, bufnr)
33+
require("lvim.lsp").common_on_init(client, bufnr)
34+
require("clangd_extensions.config").setup {}
35+
require("clangd_extensions.ast").init()
36+
vim.cmd [[
37+
command ClangdToggleInlayHints lua require('clangd_extensions.inlay_hints').toggle_inlay_hints()
38+
command -range ClangdAST lua require('clangd_extensions.ast').display_ast(<line1>, <line2>)
39+
command ClangdTypeHierarchy lua require('clangd_extensions.type_hierarchy').show_hierarchy()
40+
command ClangdSymbolInfo lua require('clangd_extensions.symbol_info').show_symbol_info()
41+
command -nargs=? -complete=customlist,s:memuse_compl ClangdMemoryUsage lua require('clangd_extensions.memory_usage').show_memory_usage('<args>' == 'expand_preamble')
42+
]]
43+
end
44+
45+
opts = {
46+
cmd = { provider, unpack(clangd_flags) },
47+
on_attach = custom_on_attach,
48+
on_init = custom_on_init,
49+
}
50+
end
51+
52+
require("lvim.lsp.manager").setup("clangd", opts)

lua/user/builtin.lua

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
local M = {}
22
local kind = require "user.lsp_kind"
3+
local cmp_ok, cmp = pcall(require, "cmp")
4+
if not cmp_ok or cmp == nil then
5+
cmp = {
6+
mapping = function(...) end,
7+
setup = {
8+
filetype = function(...) end,
9+
cmdline = function(...) end,
10+
},
11+
config = {
12+
sources = function(...) end,
13+
},
14+
}
15+
end
316

417
M.default_diagnostic_config = {
518
signs = {
@@ -64,6 +77,32 @@ M.config = function()
6477

6578
-- CMP
6679
-- =========================================
80+
local comparators = {
81+
cmp.config.compare.offset,
82+
cmp.config.compare.exact,
83+
cmp.config.compare.score,
84+
cmp.config.compare.recently_used,
85+
cmp.config.compare.locality,
86+
cmp.config.compare.kind,
87+
cmp.config.compare.length,
88+
cmp.config.compare.order,
89+
}
90+
if lvim.builtin.cpp_programming.active then
91+
comparators = {
92+
cmp.config.compare.offset,
93+
cmp.config.compare.exact,
94+
cmp.config.compare.recently_used,
95+
require "clangd_extensions.cmp_scores",
96+
cmp.config.compare.locality,
97+
cmp.config.compare.kind,
98+
cmp.config.compare.length,
99+
cmp.config.compare.order,
100+
}
101+
end
102+
lvim.builtin.cmp.sorting = {
103+
priority_weight = 2,
104+
comparators = comparators,
105+
}
67106
lvim.builtin.cmp.sources = {
68107
{ name = "nvim_lsp" },
69108
{ name = "cmp_tabnine", max_item_count = 3 },
@@ -141,19 +180,6 @@ M.config = function()
141180
end,
142181
}
143182
end
144-
local cmp_ok, cmp = pcall(require, "cmp")
145-
if not cmp_ok or cmp == nil then
146-
cmp = {
147-
mapping = function(...) end,
148-
setup = {
149-
filetype = function(...) end,
150-
cmdline = function(...) end,
151-
},
152-
config = {
153-
sources = function(...) end,
154-
},
155-
}
156-
end
157183
if lvim.builtin.fancy_wild_menu.active then
158184
local cmdline_opts = {
159185
mapping = cmp.mapping.preset.cmdline {},
@@ -627,7 +653,6 @@ end
627653

628654
function M.tab(fallback)
629655
local methods = require("lvim.core.cmp").methods
630-
local cmp = require "cmp"
631656
local luasnip = require "luasnip"
632657
local copilot_keys = vim.fn["copilot#Accept"]()
633658
if cmp.visible() then
@@ -652,7 +677,6 @@ end
652677
function M.shift_tab(fallback)
653678
local methods = require("lvim.core.cmp").methods
654679
local luasnip = require "luasnip"
655-
local cmp = require "cmp"
656680
if cmp.visible() then
657681
cmp.select_prev_item()
658682
elseif vim.api.nvim_get_mode().mode == "c" then

lua/user/cle.lua

Lines changed: 0 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,5 @@
11
local M = {}
22

3-
M.config = function()
4-
local status_ok, clangd_extensions = pcall(require, "clangd_extensions")
5-
if not status_ok then
6-
return
7-
end
8-
9-
local capabilities = require("lvim.lsp").common_capabilities()
10-
capabilities.offsetEncoding = { "utf-16" }
11-
12-
local clangd_flags = {
13-
"--suggest-missing-includes",
14-
"--background-index",
15-
"--cross-file-rename",
16-
"--fallback-style=google",
17-
"-j=12",
18-
"--all-scopes-completion",
19-
"--pch-storage=disk",
20-
"--clang-tidy",
21-
"--log=error",
22-
"--completion-style=detailed",
23-
"--header-insertion=iwyu",
24-
"--header-insertion-decorators",
25-
"--enable-config",
26-
"--offset-encoding=utf-16",
27-
"--ranking-model=heuristics",
28-
"--folding-ranges",
29-
}
30-
clangd_extensions.setup {
31-
server = {
32-
-- options to pass to nvim-lspconfig
33-
-- i.e. the arguments to require("lspconfig").clangd.setup({})
34-
cmd = { "clangd", unpack(clangd_flags) },
35-
on_attach = require("lvim.lsp").common_on_attach,
36-
on_init = require("lvim.lsp").common_on_init,
37-
capabilities = capabilities,
38-
},
39-
extensions = {
40-
-- defaults:
41-
-- Automatically set inlay hints (type hints)
42-
autoSetHints = not lvim.builtin.inlay_hints.active,
43-
-- Whether to show hover actions inside the hover window
44-
-- These apply to the default ClangdSetInlayHints command
45-
inlay_hints = {
46-
-- Only show inlay hints for the current line
47-
only_current_line = false,
48-
-- Event which triggers a refersh of the inlay hints.
49-
-- You can make this "CursorMoved" or "CursorMoved,CursorMovedI" but
50-
-- not that this may cause higher CPU usage.
51-
-- This option is only respected when only_current_line and
52-
-- autoSetHints both are true.
53-
only_current_line_autocmd = "CursorHold",
54-
-- wheter to show parameter hints with the inlay hints or not
55-
show_parameter_hints = true,
56-
-- whether to show variable name before type hints with the inlay hints or not
57-
show_variable_name = false,
58-
-- prefix for parameter hints
59-
parameter_hints_prefix = "<- ",
60-
-- prefix for all the other hints (type, chaining)
61-
other_hints_prefix = "=> ",
62-
-- whether to align to the length of the longest line in the file
63-
max_len_align = false,
64-
-- padding from the left if max_len_align is true
65-
max_len_align_padding = 1,
66-
-- whether to align to the extreme right or not
67-
right_align = false,
68-
-- padding from the right if right_align is true
69-
right_align_padding = 7,
70-
-- The color of the hints
71-
highlight = "Comment",
72-
},
73-
},
74-
}
75-
end
76-
773
M.cmake_config = function()
784
local status_ok, cmake_tools = pcall(require, "cmake-tools")
795
if not status_ok then

lua/user/plugins.lua

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -539,9 +539,6 @@ M.config = function()
539539
},
540540
{
541541
"p00f/clangd_extensions.nvim",
542-
config = function()
543-
require("user.cle").config()
544-
end,
545542
ft = { "c", "cpp", "objc", "objcpp", "h", "hpp" },
546543
enabled = lvim.builtin.cpp_programming.active,
547544
},

0 commit comments

Comments
 (0)