aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorByron Torres <b@torresjrjr.com>2023-05-23 12:08:42 +0000
committerByron Torres <b@torresjrjr.com>2023-05-23 12:16:27 +0000
commit8fccb8b954ab1f831b58ed7ff9cc3f55655927c0 (patch)
treefe30f3208293cc06831bae3be3c43a118281eac2
parentfix less invocation and terminal output (diff)
downloadvim-haredoc-8fccb8b954ab1f831b58ed7ff9cc3f55655927c0.tar.gz
resolve partial symbols with use statements
-rw-r--r--plugin/haredoc.vim24
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"
\ )