commit 8fccb8b954ab1f831b58ed7ff9cc3f55655927c0
parent 13dc4de3fc6e91c91ab92711ad7b40c2770aafcb
Author: Byron Torres <b@torresjrjr.com>
Date: Tue, 23 May 2023 12:08:42 +0000
resolve partial symbols with use statements
Diffstat:
1 file changed, 22 insertions(+), 2 deletions(-)
diff --git 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"
\ )