ต้องใช้ NeoVim 0.7+
ติดตั้งปลั๊กอินนี้โดยใช้ปลั๊กอิน/แพ็คเกจตัวจัดการหรือดู :h packages
ตั้งค่า clangd ผ่าน lspconfig/vim.lsp.start ตามปกติ คุณไม่จำเป็นต้องโทร 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() ของคุณ 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ตัวอย่างเช่นหากคุณมีผู้บังคับบัญชาที่เกี่ยวข้องกับคำแนะนำการฝังกฎระเบียบคุณอาจต้องการปิดการใช้งาน/เปิดใช้งานเมื่อสลับการฝังคำแนะนำ:
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 และเพื่อน - หน้าต่าง 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
☑คำขอข้อมูลสัญลักษณ์
☑พิมพ์ลำดับชั้น
☑การฝังคำแนะนำ
☑สลับระหว่างแหล่งที่มา/ส่วนหัว
☑สถานะไฟล์ (ดู lsp-status.nvim)
☑คำสั่งการรวบรวม (สามารถระบุได้ใน vim.lsp.start() /lspconfig init_options และ settings )
☑คะแนนการสมบูรณ์ของรหัส
⬜การสร้างการวินิจฉัยแรง (ไม่แน่ใจ)
SIMRAT39 - รหัสสำหรับคำแนะนำการฝังนั้นถูกนำมาจาก Rust -tools.nvim ที่มีการเปลี่ยนแปลงเล็กน้อยมาก