nushell / tree-sitter-nu

A tree-sitter grammar for nu-lang, the language of nushell
MIT License
121 stars 27 forks source link

Indent modifications #93

Closed CabalCrow closed 6 months ago

CabalCrow commented 6 months ago

Brief Description

Fixes indentation issues for function parameters & pipes stacking indentation. Also provides an alternative indentation to pipes.

Fix Details

Indentation for function parameters.

There was no indentation provided for function parameters within the [] block. Examples

Pipe stacking indentation.

Sometimes pipes nodes can stack on each other on double (triple & so on) the indentation. This generally happens in this pattern:

{
    cmd
} {
        cmd
    }

This would probably occur most commonly in this scenario:

if true {
    cmd
} else {
        cmd
    }

There isn't a straight forward fix to this, so it goes towards opinionated territory. What I've done is remove pipeline indentation alltogether. This fixes the issue & I've seen only 1 place where the behaviour changes. Normally if you do a command at the start of a line, if you go to the next line you will automatically indent. This is because even a command at the start is consider a pipeline. I view this as a positive effect. However it would also remove indentation for the next line in cases you have a pipe at the end of the line.

That being said I think the indentation provided by (pipeline) nodes overall does more damage than provide convenience, so I think the best course of action is to simply remove its indentation effect & try and replicate it via other methods(the method I attempted is provided below).

Proposed change

Adding @indent.immediate to "|" for pipeline indentation. This creates python line indentation if you have an open pipe "|" at the end of the line. This approach works well with 2 caveats:

In short, this approach gives you proper indent after naked pipes at the cost of breaking indentation within a pipeline if you use non-inline comments in the middle of a pipe.

Help required.

Someone should test the indentation file in helix. I personally wasn't able to get the indents.scm file to have any change in helix to properly test it.

CabalCrow commented 6 months ago

After further testing the alternative indent do not work all the time as well, so I removed it. Now this PR only fixes the indent of function parameters & removes the indent to pipes (to fix the issues created by it).

fdncred commented 6 months ago

thanks