需要Neovim 0.7+
使用任何插件/软件包管理器安装此插件,或者查看:h packages
像往常一样,通过lspconfig/vim.lsp.Start设置clangd。您不需要致电require("clangd_extensions").setup :
require ( " clangd_extensions " ). setup ({
inlay_hints = {
inline = vim . fn . has ( " nvim-0.10 " ) == 1 ,
-- Options other than `highlight' and `priority' only work
-- if `inline' is disabled
-- Only show inlay hints for the current line
only_current_line = false ,
-- Event which triggers a refresh of the inlay hints.
-- You can make this { "CursorMoved" } or { "CursorMoved,CursorMovedI" } but
-- note that this may cause higher CPU usage.
-- This option is only respected when only_current_line is true.
only_current_line_autocmd = { " CursorHold " },
-- whether to show parameter hints with the inlay hints or not
show_parameter_hints = true ,
-- prefix for parameter hints
parameter_hints_prefix = " <- " ,
-- prefix for all the other hints (type, chaining)
other_hints_prefix = " => " ,
-- whether to align to the length of the longest line in the file
max_len_align = false ,
-- padding from the left if max_len_align is true
max_len_align_padding = 1 ,
-- whether to align to the extreme right or not
right_align = false ,
-- padding from the right if right_align is true
right_align_padding = 7 ,
-- The color of the hints
highlight = " Comment " ,
-- The highlight group priority for extmark
priority = 100 ,
},
ast = {
-- These are unicode, should be available in any font
role_icons = {
type = " ? " ,
declaration = " ? " ,
expression = " ? " ,
statement = " ; " ,
specifier = " ? " ,
[ " template argument " ] = " ? " ,
},
kind_icons = {
Compound = " ? " ,
Recovery = " ? " ,
TranslationUnit = " ? " ,
PackExpansion = " ? " ,
TemplateTypeParm = " ? " ,
TemplateTemplateParm = " ? " ,
TemplateParamObject = " ? " ,
},
--[[ These require codicons (https://github.com/microsoft/vscode-codicons)
role_icons = {
type = "",
declaration = "",
expression = "",
specifier = "",
statement = "",
["template argument"] = "",
},
kind_icons = {
Compound = "",
Recovery = "",
TranslationUnit = "",
PackExpansion = "",
TemplateTypeParm = "",
TemplateTemplateParm = "",
TemplateParamObject = "",
}, ]]
highlights = {
detail = " Comment " ,
},
},
memory_usage = {
border = " none " ,
},
symbol_info = {
border = " none " ,
},
}):ClangdSwitchSourceHeader

将其添加到您的nvim-lspconfig / vim.lsp.start() 's on_attach :
require ( " clangd_extensions.inlay_hints " ). setup_autocmd ()
require ( " clangd_extensions.inlay_hints " ). set_inlay_hints ()您还可以使用ClangdSetInlayHints , ClangdDisableInlayHints和ClangdToggleInlayHints启用,禁用或切换提示。切换返回提示的当前状态,如果要在切换镶嵌提示时挂接回调,这很有用:
if require ( " clangd_extensions.inlay_hints " ). toggle_inlay_hints () then
-- Inlay hints are enabled
else
-- Inlay hints are disabled
end例如,如果您具有与clangd inlay提示有关的自动命令,则可能需要在切换镶嵌提示时禁用/启用它们:
on_attach = function ( _ , buf )
local group = vim . api . nvim_create_augroup ( " clangd_no_inlay_hints_in_insert " , { clear = true })
vim . keymap . set ( " n " , " <leader>lh " , function ()
if require ( " clangd_extensions.inlay_hints " ). toggle_inlay_hints () then
vim . api . nvim_create_autocmd ( " InsertEnter " , { group = group , buffer = buf ,
callback = require ( " clangd_extensions.inlay_hints " ). disable_inlay_hints
})
vim . api . nvim_create_autocmd ({ " TextChanged " , " InsertLeave " }, { group = group , buffer = buf ,
callback = require ( " clangd_extensions.inlay_hints " ). set_inlay_hints
})
else
vim . api . nvim_clear_autocmds ({ group = group , buffer = buf })
end
end , { buffer = buf , desc = " [l]sp [h]ints toggle " })
end ,
}
您可以使用zc和Friends折叠节点 - AST窗口的shiftwidth=2 ,而foldmethod=indent 。
:ClangdAST以当前行作为范围来查看AST, :'<,'>ClangdAST带有视觉选择,以使用选定的线作为范围查看AST。查看范围如何在https://clangd.llvm.org/extensions#ast上处理
用法:用于NVIM-CMP
local cmp = require " cmp "
cmp . setup {
-- ... rest of your cmp setup ...
sorting = {
comparators = {
cmp . config . compare . offset ,
cmp . config . compare . exact ,
cmp . config . compare . recently_used ,
require ( " clangd_extensions.cmp_scores " ),
cmp . config . compare . kind ,
cmp . config . compare . sort_text ,
cmp . config . compare . length ,
cmp . config . compare . order ,
},
},
}
:ClangdSymbolInfo ,带有光标处于所需符号。

:ClangdTypeHierarchy具有光标,上面是所需类型或该类型的符号。 gd带有光标窗口中的类型,以转到其定义。
您可以使用zc和朋友折叠项目 - 内存用法窗口的shiftwidth=2 ,而foldmethod=indent 。 
:ClangdMemoryUsage 。序言可能很大,因此默认情况下它会崩溃,以扩展其使用:ClangdMemoryUsage expand_preamble
☑️内存使用情况
☑️AST
☑️符号信息请求
☑️类型层次结构
☑️inlay提示
☑️在源/标头之间切换
☑️文件状态(请参阅lsp-status.nvim)
☑️汇编命令(可以在vim.lsp.start() /lspconfig init_options和settings中指定)
☑️代码完成分数
⬜力量诊断(不确定)
SIMRAT39-镶嵌提示的代码取自Rust -tools.nvim,其更改非常小。