preservim / tagbar

Vim plugin that displays tags in a window, ordered by scope
https://preservim.github.io/tagbar
Other
6.13k stars 487 forks source link

Add linenr protection into getPrototype #707

Closed raven42 closed 3 years ago

raven42 commented 3 years ago

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)

raven42 commented 3 years ago

This issue is a side effect of #698 for #680.

Fixing this issue may cause the 'auto' datatype calculation for kinds which ctags does not report the tag datatype to also include any declaration information.

The intent of the let line = substitute(line, '\s*=.*', '', '') line in normaltag.vim was to handle cases where a tag was defined like this (example in Java):

public class some_class {
    public status final String SOME_STRING = "some string value";
}

At this time, universal ctags does not interpret the --fields=-t option for java files and does not provide the datatype. So there is an attempt by tagbar to figure out what the datatype is. This line was included to strip off the declaration from the prototype as well in an effort to clean it up. However this now causes a bug for python files which can include a declaration of optional variables inside of the prototype. Hence we have to remove this line until something else can be figured out.

This will have the downside of any files which ctags does not know how to provide the datatype field for, they will get the full datatype including any declarations of the tag variable.