Skip to content

Commit

Permalink
Fixed not scrolling up to function heading when args contained C-styl…
Browse files Browse the repository at this point in the history
…e comments. Added test for this
  • Loading branch information
Rob authored and Rob committed Apr 26, 2020
1 parent 54b3b32 commit 027b205
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
29 changes: 23 additions & 6 deletions autoload/jumpmethod.vim
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,24 @@ endfunction

" Strip trailing comment
function! jumpmethod#StripTrailingComment(text)
return substitute(a:text, '\(//\|/\*\).*', '', '')
let text = a:text
let pos = match(text, '/\*.*\*/')
while (pos >= 0)
let endPos = matchend(text, '\*/', pos + 2)

" Remove the comment in such a way as to leave the string the same length
let newText = strpart(text, 0, pos)
let i = pos
while (i < endPos)
let newText = newText . ' '
let i = i + 1
endwhile
let text = newText . strpart(text, endPos)

" See if there's another comment to remove
let pos = match(text, '/\*.*\*/', endPos)
endwhile
return substitute(text, '\(//\|/\*\).*', '', '')
endfunction

" Skip back over comment lines and blank lines
Expand All @@ -32,7 +49,7 @@ function! jumpmethod#SkipBackOverComments(current_line)
if (pos >= 0)
" End of a C-style comment, jump to other end
call cursor(current_line, pos + 1)
keepjumps normal! %
keepjumps normal %
let current_line = line('.')
let text = getline(current_line)
endif
Expand Down Expand Up @@ -98,7 +115,7 @@ function! jumpmethod#jump(char, flags, mode, includeClassesAndProperties)

if char == '}'
" jump to the opening one to analyze the definition
keepjumps normal! %
keepjumps normal %
endif

" Remember where we are, with cursor on the '{'
Expand Down Expand Up @@ -133,7 +150,7 @@ function! jumpmethod#jump(char, flags, mode, includeClassesAndProperties)
" Found a closing ')', but function definition may span multiple lines,
" so find matching '(' at start.
call cursor(current_line, pos + 1)
keepjumps normal! %
keepjumps normal %
let current_line = line('.')

let text = getline(current_line)
Expand Down Expand Up @@ -193,7 +210,7 @@ function! jumpmethod#jump(char, flags, mode, includeClassesAndProperties)
call setpos('.', openingBracePos)
if char == '}'
" we need to go back to the closing bracket
keepjumps normal! %
keepjumps normal %
endif
endif

Expand All @@ -205,7 +222,7 @@ function! jumpmethod#jump(char, flags, mode, includeClassesAndProperties)
call setpos('.', openingBracePos)
if char == '}'
" Go back to the closing bracket
keepjumps normal! %
keepjumps normal %
endif
endwhile

Expand Down
16 changes: 16 additions & 0 deletions test/Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ float this[int index] // Stop here
blah;
}

bool FuncWithCommentsInArgs(const char *str, int numFrames,
float val /* = 0.0f */, Type blah /* = 0 */,
float val /* = 0.0f */, int quality /* = -1 */)
{ // Land here from far below should scroll up to show Func name
cmd;
}

void FuncWithNoGapBeforeNextFunc()
{
// The lack of a blank line between this function and the next
Expand Down Expand Up @@ -197,6 +204,15 @@ void Func6
*/
{
cmd;

// Leave lines here so we have room to scroll down,
// to test that [[ will scroll up to show function heading
//
//
//
//
//
// That should be enough.
}
}
}

0 comments on commit 027b205

Please sign in to comment.