Skip to content

Commit cf00bdf

Browse files
committed
fix: prioritize exact tempalte specializations matches
Signed-off-by: Guybrush <miguel.barro@live.com>
1 parent c427581 commit cf00bdf

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

start/cpptags/autoload/cpptags.vim

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,30 @@ function! cpptags#CppTagFunc(pattern, flags, info)
241241

242242
" filtering matchlist by specialization
243243
let result = result->filter(funcref("s:TemplateFilter"))
244+
245+
" specialization and exact matches
246+
function! s:TemplateSort(item1, item2, exact = 0) closure
247+
248+
let temp_pat = a:exact ? ('\<' .. param .. '\>') : param
249+
250+
let t1 = a:item1->has_key('specialization') && a:item1['specialization'] =~ temp_pat
251+
let t2 = a:item2->has_key('specialization') && a:item2['specialization'] =~ temp_pat
252+
253+
if t1 && t2
254+
" favour exact match if any
255+
return a:exact ? 0 : s:TemplateSort(a:item1, a:item2, 1)
256+
elseif !t1 && t2
257+
call s:Log("reorder " .. string(a:item1) .. " after " .. string(a:item2))
258+
return 1
259+
elseif t1 && !t2
260+
call s:Log("reorder " .. string(a:item2) .. " after " .. string(a:item1))
261+
return -1
262+
else
263+
return 0
264+
endif
265+
endfunction
266+
267+
let result = result->sort(funcref("s:TemplateSort"))
244268
endif
245269

246270
" filter by signature
@@ -283,6 +307,7 @@ function! cpptags#CppTagFunc(pattern, flags, info)
283307
call s:Log("reorder " .. string(a:item1) .. " after " .. string(a:item2))
284308
return 1
285309
elseif f1 && !f2
310+
call s:Log("reorder " .. string(a:item2) .. " after " .. string(a:item1))
286311
return -1
287312
else
288313
return 0

0 commit comments

Comments
 (0)