yioneko / nvim-yati

Yet another tree-sitter powered indent plugin for Neovim.
MIT License
149 stars 3 forks source link

bug: [python] conditional `return` prematurely de-indents #19

Open YodaEmbedding opened 2 months ago

YodaEmbedding commented 2 months ago

Bug: If a return statement is the last child in a pre-order (or in-order) traversal, then the indent level resets to the level of the parent function.


Actual:

def conditional_return(x):
    if x:
        return True

MARKER

Expected:

def conditional_return(x):
    if x:
        return True

    MARKER
yioneko commented 2 months ago

I get this for your sample at https://github.com/nvim-treesitter/nvim-treesitter/commit/04401b5dd17c3419dae5141677bd256f52d54733:

def conditional_return(x):
    if x:
        return True

        MARKER

Could you check that the plugin is activated by :set indentexpr??

YodaEmbedding commented 2 months ago

Ah, you're right. I'd forgotten to set it up to not use treesitter's default (indentexpr=nvim_treesitter#indent()). I fixed it so it now loads correctly (indentexpr=v:lua.require'nvim-yati.indent'.indentexpr()).

The current behavior is fine, though it's different from the "expected", where the MARKER has only one indent.