From d5417b6014dc5f3c570324b0f14ec8c6fcf1e25d Mon Sep 17 00:00:00 2001 From: Max Schillinger Date: Fri, 24 Nov 2023 21:32:47 +0100 Subject: [PATCH] Search only single-token identifiers in current function --- plugin/harejump.vim | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/plugin/harejump.vim b/plugin/harejump.vim index 4f590cf..d3211aa 100644 --- a/plugin/harejump.vim +++ b/plugin/harejump.vim @@ -19,15 +19,17 @@ function! harejump#JumpToDefinition(identifier = '') end " check if identifier is a variable/constant in the current function - let fndefinitionline = s:InFunction() - if fndefinitionline - if s:SearchAndJumpInFile('\(let\|const\|def\) \(([^)]*\)\?' .. tokens[-1] .. '\>', 'bW', fndefinitionline) - return 1 - endif - " try to jump to function argument - " TODO: This might also jump to a cast of the symbol. - if s:SearchAndJumpInFile(tokens[-1] .. ': ', 'bW', fndefinitionline) - return 1 + if len(tokens) == 1 + let fndefinitionline = s:InFunction() + if fndefinitionline + if s:SearchAndJumpInFile('\(let\|const\|def\) \(([^)]*\)\?' .. tokens[-1] .. '\>', 'bW', fndefinitionline) + return 1 + endif + " try to jump to function argument + " TODO: This might also jump to a cast of the symbol. + if s:SearchAndJumpInFile(tokens[-1] .. ': ', 'bW', fndefinitionline) + return 1 + endif endif endif -- 2.45.2