diff options
Diffstat (limited to 'plugin')
| -rw-r--r-- | plugin/haredoc.vim | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/plugin/haredoc.vim b/plugin/haredoc.vim index 33a6eff..6cbd507 100644 --- a/plugin/haredoc.vim +++ b/plugin/haredoc.vim @@ -7,14 +7,34 @@ command -nargs=? Haredoc :call Haredoc(<q-args>) function Haredoc(symbol) let symbol = a:symbol - let popup = symbol == '.' ? 1 : 0 + let popup = symbol == '.' + if (symbol == '.' || symbol == ',') let oldiskeyword = &iskeyword setlocal iskeyword+=: let symbol = expand('<cword>') let &iskeyword = oldiskeyword + + " resolve possibly partial symbols (chrono::moment) + if match(symbol, "::") != -1 + let [parent, base] = split(symbol, "::")[-2:-1] + + " try joining symbol with a use statement. + " example: 'use time::chrono' -> 'time::chrono::moment' + let resolvecmd =<< trim eval CMD + awk '/use [a-zA-Z:]*{parent};/ {{ + gsub("(use *|;.*)", ""); + print $1 "::" "{base}" + }}' {expand("%")} 2>&- + CMD + let joined_symbol = system(join(resolvecmd)) + if len(joined_symbol) != 0 + let symbol = joined_symbol + endif + endif endif - if popup == 1 && has('popupwin') && has('terminal') + + if popup && has('popupwin') && has('terminal') let minheight = 1 + system( \ "haredoc -Ftty '"..symbol.."' 2>&1 | wc -l" \ ) |
