summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@opensourcerouting.org>2023-01-31 23:18:52 +0100
committerDavid Lamparter <equinox@opensourcerouting.org>2023-01-31 23:20:03 +0100
commit40e98aa8c80f9e0a7ae2fed254eece9f8d03ba70 (patch)
treec44b9d52ff36b5b7c30ea17ebbdfd48cc81e3ff5 /tools
parentMerge pull request #12667 from donaldsharp/zebra_rib_fixup (diff)
downloadfrr-40e98aa8c80f9e0a7ae2fed254eece9f8d03ba70.tar.xz
frr-40e98aa8c80f9e0a7ae2fed254eece9f8d03ba70.zip
tools: add GotoXref vim script
Let's make these unique IDs actually a bit useful. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Diffstat (limited to 'tools')
-rw-r--r--tools/frr.vim41
1 files changed, 41 insertions, 0 deletions
diff --git a/tools/frr.vim b/tools/frr.vim
index 86aa0c0e3..7cc248f4c 100644
--- a/tools/frr.vim
+++ b/tools/frr.vim
@@ -34,3 +34,44 @@ endfunction
" auto-apply the above based on path rules
"autocmd BufRead,BufNewFile /home/.../frr/*.[ch] call CStyleFRR()
+
+" only load xref file once, remember on script-scope
+let s:xrefjson = ""
+let s:xrefpath = ""
+
+" call directly to force reload with :call FRRLoadXrefJson()
+function! FRRLoadXrefJson() abort
+ let s:xrefpath = findfile("frr.xref", ".;")
+ if empty(s:xrefpath)
+ throw "frr.xref JSON file not found in current or parent directories"
+ endif
+ let xreflines = readfile(s:xrefpath)
+ let s:xrefjson = json_decode(join(xreflines, "\n"))
+endfunction
+
+function! FRRXrefJson() abort
+ if empty(s:xrefjson)
+ call FRRLoadXrefJson()
+ endif
+ return s:xrefjson
+endfunction
+
+function! FRRGotoXref(ident) abort
+ let refs = FRRXrefJson()["refs"]
+ if has_key(refs, a:ident)
+ " TODO: in rare cases, one ID may occur in multiple places.
+ " Add some UI for that. (This happens if the exact same
+ " format string is logged in multiple places in the same
+ " file.)
+ let loc = refs[a:ident][0]
+ let basepath = fnamemodify(s:xrefpath, ":p:h")
+ let path = fnamemodify(basepath . "/" . loc["file"], ":.")
+ execute "e ".fnameescape(path)
+ execute ":".loc["line"]
+ else
+ echoerr printf("cannot find xref with ID %s", a:ident)
+ endif
+endfunction
+
+" invoke as :GotoXref 23456-ABCDE
+command! -bang -nargs=1 GotoXref :call FRRGotoXref(<q-args>)