From 10a4a9bc382e1ca1e62aa59ada0e9d8531dfd651 Mon Sep 17 00:00:00 2001 From: raven42 Date: Tue, 10 Nov 2020 07:49:36 -0600 Subject: [PATCH] Add linenr protection into getPrototype (#707) * Add linenr protection into getPrototype Closes #706 Add protection to not go beyond the last line in the file when calling the `s:getPrototype()` routine. This occurs when there is an `=` character in the tag prototype. For example in a python tag with a parameter line this: `some_function(arg1, optional_arg_2=False)` * Fix issue with python prototypes that can include `=` character in the argument list --- autoload/tagbar/prototypes/normaltag.vim | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/autoload/tagbar/prototypes/normaltag.vim b/autoload/tagbar/prototypes/normaltag.vim index ad69c4d..df21692 100644 --- a/autoload/tagbar/prototypes/normaltag.vim +++ b/autoload/tagbar/prototypes/normaltag.vim @@ -86,7 +86,10 @@ function! s:getPrototype(short) abort dict let line = getbufline(bufnr, self.fields.line)[0] " If prototype includes declaration, remove the '=' and anything after - let line = substitute(line, '\s*=.*', '', '') + " FIXME: Need to remove this code. This breaks python prototypes that + " can include a '=' in the function paramter list. + " ex: function(arg1, optional_arg2=False) + " let line = substitute(line, '\s*=.*', '', '') let list = split(line, '\zs') let start = index(list, '(') @@ -104,7 +107,7 @@ function! s:getPrototype(short) abort dict let prototype = line let curlinenr = self.fields.line + 1 - while balance > 0 + while balance > 0 && curlinenr < line('$') let curline = getbufline(bufnr, curlinenr)[0] let curlist = split(curline, '\zs') let balance += count(curlist, '(')