hitags signature update
This commit is contained in:
parent
a2d4623980
commit
8c1aff5ffb
1
.gitignore
vendored
1
.gitignore
vendored
@ -4,3 +4,4 @@ vim/.vim/.netrwhist
|
|||||||
cache.db
|
cache.db
|
||||||
.cache/*
|
.cache/*
|
||||||
tags.vim
|
tags.vim
|
||||||
|
sigs.vim
|
||||||
|
@ -9,27 +9,31 @@ input_filename = ''
|
|||||||
preprocessor='clang -fdirectives-only -E {input_} -o {output}'
|
preprocessor='clang -fdirectives-only -E {input_} -o {output}'
|
||||||
tags_filename = 'vim.tags'
|
tags_filename = 'vim.tags'
|
||||||
polution_directory = './'
|
polution_directory = './'
|
||||||
|
action = 'hi'
|
||||||
|
|
||||||
def print2(s):
|
def print2(s):
|
||||||
print(s, file=sys.stderr)
|
print(s, file=sys.stderr)
|
||||||
|
|
||||||
def usage(name, x):
|
def usage(name, x):
|
||||||
print2("Usage: {0} <options>".format(name))
|
print2("Usage: {0} <options> <verb>".format(name))
|
||||||
print2("\t-h")
|
print2("\t-h")
|
||||||
print2("\t-i <file>")
|
print2("\t-i <file> : input")
|
||||||
print2("\t-p <cmd>")
|
print2("\t-p <cmd> : preprocessor (e.g.: 'clang -fdirectives-only -E {input_} -o {output}')")
|
||||||
print2("\t-t <path>")
|
print2("\t-t <path> : polution directory")
|
||||||
|
print2("\t---")
|
||||||
|
print2("\thi")
|
||||||
|
print2("\tsig")
|
||||||
exit(x)
|
exit(x)
|
||||||
|
|
||||||
def opts(args):
|
def opts(args):
|
||||||
global input_filename, preprocessor, polution_directory
|
global input_filename, preprocessor, polution_directory, action
|
||||||
|
|
||||||
try:
|
try:
|
||||||
i = args.index("--help") if "--help" in args else -1
|
i = args.index("--help") if "--help" in args else -1
|
||||||
if i != -1:
|
if i != -1:
|
||||||
usage(args[0], 1)
|
usage(args[0], 1)
|
||||||
else:
|
else:
|
||||||
for idx, arg in enumerate(args[1:]):
|
for idx, arg in enumerate(args[1:]): # this is terrible
|
||||||
if arg in ("-h", "--help"):
|
if arg in ("-h", "--help"):
|
||||||
usage(args[0], 0)
|
usage(args[0], 0)
|
||||||
elif arg == "-i":
|
elif arg == "-i":
|
||||||
@ -38,6 +42,10 @@ def opts(args):
|
|||||||
preprocessor = args[idx + 2]
|
preprocessor = args[idx + 2]
|
||||||
elif arg == "-t":
|
elif arg == "-t":
|
||||||
polution_directory = args[idx + 2]
|
polution_directory = args[idx + 2]
|
||||||
|
elif arg == "hi":
|
||||||
|
action = "hi"
|
||||||
|
elif arg == "sig":
|
||||||
|
action = "sig"
|
||||||
except IndexError:
|
except IndexError:
|
||||||
usage(args[0], 1)
|
usage(args[0], 1)
|
||||||
if input_filename == '':
|
if input_filename == '':
|
||||||
@ -79,7 +87,7 @@ targets = [
|
|||||||
'type': 'u',
|
'type': 'u',
|
||||||
'out': hi('Type')
|
'out': hi('Type')
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'type': 'g',
|
'type': 'g',
|
||||||
'out': hi('Type')
|
'out': hi('Type')
|
||||||
},
|
},
|
||||||
@ -92,15 +100,16 @@ targets = [
|
|||||||
'out': hi('Identifier')
|
'out': hi('Identifier')
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
PATTERN_INDEX = 1 - 1
|
NAME_INDEX = (1) - 1
|
||||||
TYPE_INDEX = 4 - 1
|
PATTERN_INDEX = (3) - 1
|
||||||
|
TYPE_INDEX = (4) - 1
|
||||||
|
|
||||||
def do_ignore(row):
|
def do_ignore(row):
|
||||||
IGNORE_IF_BEGINS_WITH = '!_'
|
IGNORE_IF_BEGINS_WITH = '!_'
|
||||||
for i in IGNORE_IF_BEGINS_WITH:
|
for i in IGNORE_IF_BEGINS_WITH:
|
||||||
if row[0][0] == i:
|
if row[0][0] == i:
|
||||||
return True
|
return True
|
||||||
if row[PATTERN_INDEX].find('operator') != -1:
|
if row[NAME_INDEX].find('operator') != -1:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -131,7 +140,7 @@ def file2tags(filename, flags):
|
|||||||
|
|
||||||
def tags2hi(filename):
|
def tags2hi(filename):
|
||||||
output = set()
|
output = set()
|
||||||
print2(filename)
|
#print2(filename)
|
||||||
try:
|
try:
|
||||||
with open(filename) as f:
|
with open(filename) as f:
|
||||||
csv_reader = csv.reader(f, delimiter='\t')
|
csv_reader = csv.reader(f, delimiter='\t')
|
||||||
@ -141,14 +150,41 @@ def tags2hi(filename):
|
|||||||
for t in targets:
|
for t in targets:
|
||||||
try:
|
try:
|
||||||
if t['type'] == row[TYPE_INDEX]:
|
if t['type'] == row[TYPE_INDEX]:
|
||||||
output.add(render(t, re.escape(row[PATTERN_INDEX])))
|
output.add(render(t, re.escape(row[NAME_INDEX])))
|
||||||
except:
|
except:
|
||||||
print2(row)
|
#print2(row)
|
||||||
|
pass
|
||||||
except FileNotFoundError as e:
|
except FileNotFoundError as e:
|
||||||
print2(sys.argv[0] + ": No such file or directory '{0}'.".format(filename))
|
print2(sys.argv[0] + ": No such file or directory '{0}'.".format(filename))
|
||||||
exit(1)
|
exit(1)
|
||||||
return output
|
return output
|
||||||
|
|
||||||
|
def pattern2signature(name, pattern):
|
||||||
|
start = pattern.find(name)
|
||||||
|
if pattern.find(')') != -1:
|
||||||
|
end = pattern.find(')') + 1
|
||||||
|
else:
|
||||||
|
end = pattern.find('$')
|
||||||
|
return pattern[start : end]
|
||||||
|
|
||||||
|
has_signature = ['f', 'p']
|
||||||
|
|
||||||
|
def tags2sigs(filename):
|
||||||
|
output = dict()
|
||||||
|
#print2(filename)
|
||||||
|
with open(filename) as f:
|
||||||
|
csv_reader = csv.reader(f, delimiter='\t')
|
||||||
|
for row in csv_reader:
|
||||||
|
if do_ignore(row):
|
||||||
|
continue
|
||||||
|
if row[TYPE_INDEX] in has_signature:
|
||||||
|
signature = pattern2signature(row[NAME_INDEX], row[PATTERN_INDEX])
|
||||||
|
if row[NAME_INDEX] in output:
|
||||||
|
output[row[NAME_INDEX]].append(signature)
|
||||||
|
else:
|
||||||
|
output[row[NAME_INDEX]] = [signature]
|
||||||
|
return output
|
||||||
|
|
||||||
def main(argv):
|
def main(argv):
|
||||||
global input_filename
|
global input_filename
|
||||||
opts(argv)
|
opts(argv)
|
||||||
@ -162,9 +198,12 @@ def main(argv):
|
|||||||
if language != '':
|
if language != '':
|
||||||
input_filename = preprocessfile(input_filename)
|
input_filename = preprocessfile(input_filename)
|
||||||
flags += ' --language-force={0} '.format(language)
|
flags += ' --language-force={0} '.format(language)
|
||||||
output = tags2hi(file2tags(input_filename, flags))
|
if action == 'hi':
|
||||||
output = sorted(output)
|
output = tags2hi(file2tags(input_filename, flags))
|
||||||
output = '\n'.join(output)
|
output = sorted(output)
|
||||||
|
output = '\n'.join(output)
|
||||||
|
elif action == 'sig':
|
||||||
|
output = "let signatures = " + str(tags2sigs(file2tags(input_filename, flags)))
|
||||||
print(output)
|
print(output)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -11,28 +11,83 @@
|
|||||||
" otherwise you are responsible for creating your own
|
" otherwise you are responsible for creating your own
|
||||||
let s:polution_directory = expand('~/.vim/plugin/HiTags/')
|
let s:polution_directory = expand('~/.vim/plugin/HiTags/')
|
||||||
|
|
||||||
" Compiler to use for preprocessing C/C++, so headers are respected
|
" Compiler_Collection_based_Preprocessing:
|
||||||
" Either use "clang" or "gcc" or something compatible,
|
if 0
|
||||||
" alternatively you will have to edit s:preprocessor
|
" Compiler to use for preprocessing C/C++, so headers are respected
|
||||||
let s:preprocessor_executable = "clang"
|
" Either use "clang" or "gcc" or something compatible,
|
||||||
|
" alternatively you will have to edit s:preprocessor
|
||||||
|
let s:preprocessor_executable = "clang"
|
||||||
|
"let s:preprocessor_executable = "gcc"
|
||||||
|
let s:preprocessor = s:preprocessor_executable . ' -fdirectives-only -E {input_} -o {output}'
|
||||||
|
endif
|
||||||
|
|
||||||
|
" Stand_alone_preprocessor:
|
||||||
|
" The only implementation i know is fcpp (https://github.com/bagder/fcpp.git)
|
||||||
|
" However, it has the major advantage that it will only warn on missing
|
||||||
|
" headers and not error. Meaning a tool chain using '-I' doesn't break
|
||||||
|
" everything.
|
||||||
|
let s:preprocessor = "fcpp -LL {input_} {output}"
|
||||||
|
|
||||||
" --- --------------------------- ---
|
" --- --------------------------- ---
|
||||||
" --- Don't Touch ---
|
" --- Don't Touch ---
|
||||||
" --- Unless ---
|
" --- Unless ---
|
||||||
" --- You know What You Are Doing ---
|
" --- You know What You Are Doing ---
|
||||||
" --- --------------------------- ---
|
" --- --------------------------- ---
|
||||||
let s:preprocessor = s:preprocessor_executable . ' -fdirectives-only -E {input_} -o {output}'
|
|
||||||
let s:tags_filename = 'tags'
|
let s:tags_filename = 'tags'
|
||||||
let s:tags_file = expand(s:polution_directory) . s:tags_filename
|
let s:tags_file = expand(s:polution_directory) . s:tags_filename
|
||||||
let s:tags_scriptname = 'tags.vim'
|
let s:tags_scriptname = 'tags.vim'
|
||||||
let s:tags_script = expand(s:polution_directory) . 'tags.vim'
|
let s:tags_script = expand(s:polution_directory) . 'tags.vim'
|
||||||
|
let s:sigs_script = expand(s:polution_directory) . 'sigs.vim'
|
||||||
"
|
"
|
||||||
let s:generator_script = expand('~/.vim/plugin/HiTags/hitags.py')
|
let s:generator_script = expand('~/.vim/plugin/HiTags/hitags.py')
|
||||||
let s:generation_command = 'python ' . s:generator_script .
|
let s:generation_command =
|
||||||
|
\ 'python ' . s:generator_script .
|
||||||
\ ' -i ' . '"' . expand('%:p') . '"' .
|
\ ' -i ' . '"' . expand('%:p') . '"' .
|
||||||
\ ' -p ' . '"' . s:preprocessor . '"' .
|
\ ' -p ' . '"' . s:preprocessor . '"' .
|
||||||
\ ' -t ' . '"' . s:polution_directory . '"' .
|
\ ' -t ' . '"' . s:polution_directory . '"' .
|
||||||
\ ' > ' . '"' . s:tags_script . '"'
|
\ ' hi ' .
|
||||||
|
\ ' > ' . '"' . s:tags_script . '"' .
|
||||||
|
\ ';' .
|
||||||
|
\ 'python ' . s:generator_script .
|
||||||
|
\ ' -i ' . '"' . expand('%:p') . '"' .
|
||||||
|
\ ' -p ' . '"' . s:preprocessor . '"' .
|
||||||
|
\ ' -t ' . '"' . s:polution_directory . '"' .
|
||||||
|
\ ' sig ' .
|
||||||
|
\ ' > ' . '"' . s:sigs_script . '"'
|
||||||
|
|
||||||
|
" --- Signature stuff ---
|
||||||
|
function! SigDebug()
|
||||||
|
echo s:generation_command
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
|
function! SigInit()
|
||||||
|
let g:signatures = {}
|
||||||
|
|
||||||
|
autocmd TextChangedI * call SigPopup()
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
call SigInit()
|
||||||
|
|
||||||
|
function! SigPopup()
|
||||||
|
let key = matchstr(getline('.')[:col('.')-2], '\k\+$')
|
||||||
|
if has_key(g:signatures, key)
|
||||||
|
call popup_atcursor(g:signatures[key], #{} )
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! Sig()
|
||||||
|
execute 'source ' . s:sigs_script
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
if exists('g:sigs_events')
|
||||||
|
for e in g:sigs_events
|
||||||
|
execute "autocmd " . e . " * Sig"
|
||||||
|
endfor
|
||||||
|
endif
|
||||||
|
|
||||||
|
command! Sig :call Sig()
|
||||||
|
" --- --- ---
|
||||||
|
|
||||||
function! HiTagsUpdate()
|
function! HiTagsUpdate()
|
||||||
let pid = system(s:generation_command)
|
let pid = system(s:generation_command)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user