Skip to content

Autoindent guess incorrect for files with more than 32 lines of non-indented code #588

Closed
@esetnik

Description

@esetnik

https://github.com/sheerun/vim-polyglot/blob/master/ftdetect/polyglot.vim#L2609

Does this bug happen when you install plugin without vim-polyglot?
No

Describe the bug:
vim-polyglot autoindent only checks the first 32 lines of the file when guessing. In php files with a large number of include statements, there is typically no indentation information available in the first 32 lines. This means that the autoindent plugin will fail to produce the correct results for php files based solely on the number of includes in the file. For example, a file with a small number of includes ends up with shiftwidth=4, while another file ends up with shiftwidth=2 even though they are in the same project. I think the guess should traverse the entire file until it finds the first line with a leading space, instead of terminating early after only 32 lines. The number of lines to traverse when guessing could be configurable, if performance is a concern, but it should be quite fast to find the first line containing line[0] == " ".

To Reproduce:
Create any two php files, one of which has at least 32 lines of non-indented top-level statements.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions