Skip to content

Commit

Permalink
cache tags-xx as JSON file for speed
Browse files Browse the repository at this point in the history
  • Loading branch information
koron committed Dec 19, 2021
1 parent 2f1fbdb commit 566876b
Showing 1 changed file with 31 additions and 15 deletions.
46 changes: 31 additions & 15 deletions tools/makehtml.vim
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ function! MakeHtmlAll(...)
endif
endfunction

function! s:JsonName(lang)
return a:lang == "" ? "tags.json" : printf("tags-%s.json", a:lang)
endfunction

function! MakeTagsFile()
let files = split(glob('tags'), '\n')
let files += split(glob('tags-??'), '\n')
Expand All @@ -50,7 +54,7 @@ function! MakeTagsFile()
endif
silent new `=fname`
silent %delete _
let tags = s:GetTags(lang)
let tags = s:LoadTags(lang)
for tagname in sort(keys(tags))
if tagname == "help-tags"
continue
Expand All @@ -60,6 +64,8 @@ function! MakeTagsFile()
call append('$', ' vim:ft=help:')
silent 1delete _
silent wq!
" save JSON tag cache
call writefile([js_encode(tags)], s:JsonName(lang), "s")
endfor
endfunction

Expand Down Expand Up @@ -216,26 +222,36 @@ endfunction

function! s:GetTags(lang)
if !exists("s:tags_" . a:lang)
let &l:tags = (a:lang == "") ? "./tags" : "./tags-" . a:lang
let tags = {}
for item in taglist(".*")
let item["html"] = s:HtmlName(item["filename"])
let tags[item["name"]] = item
endfor
" for help-tags
let item = {}
let item["name"] = "help-tags"
if s:IsSingleMode()
let item["html"] = "tags.html"
" try to load JSON tag cache
let jsonname = s:JsonName(a:lang)
if filereadable(jsonname)
let s:tags_{a:lang} = js_decode(readfile(jsonname)[0])
else
let item["html"] = printf("tags%s.html", (a:lang == "") ? "" : "." . a:lang)
let s:tags_{a:lang} = s:LoadTags(a:lang)
endif
let tags[item["name"]] = item
let s:tags_{a:lang} = tags
endif
return s:tags_{a:lang}
endfunction

func s:LoadTags(lang)
let &l:tags = (a:lang == "") ? "./tags" : "./tags-" . a:lang
let tags = {}
for item in taglist(".*")
let item["html"] = s:HtmlName(item["filename"])
let tags[item["name"]] = item
endfor
" for help-tags
let item = {}
let item["name"] = "help-tags"
if s:IsSingleMode()
let item["html"] = "tags.html"
else
let item["html"] = printf("tags%s.html", (a:lang == "") ? "" : "." . a:lang)
endif
let tags[item["name"]] = item
return tags
endfunction

function! s:IsSingleMode()
" if there is one language files, do not append language identifier
" (use "help.html" instead of "help.ab.html").
Expand Down

0 comments on commit 566876b

Please sign in to comment.