emacs-csharp / csharp-mode

A major-mode for editing C# in emacs
GNU General Public License v3.0
154 stars 47 forks source link

csharp-tree-sitter-mode indent wrongly when press new line #239

Closed kiennq closed 1 year ago

kiennq commented 3 years ago

When using csharp-tree-sitter-mode with tree-sitter-indent, when press Enter according to this code, the indent on new line is wrong.

class Program
{
    static void Main(string[] args)
    {
        test();
    | // <-- After press enter after ; in previous line, the cursor will be here
    }
}

Expectation:

class Program
{
    static void Main(string[] args)
    {
        test();
        | // <-- After press enter after ; in previous line, the cursor should be here.
    }
}

This is working okay if disable tree-sitter-indent-mode.

theothornhill commented 3 years ago

Hi and thanks for this report!

Yes, this is a known bug - there is no node to indent, so it aligns with the braces. The author of the tree-sitter-indent-mode does not think this is a bug - see https://codeberg.org/FelipeLema/tree-sitter-indent.el/issues/8.

I have not had time yet to sort this out properly. In general the indentation still needs work. This should be fixed first over at codeberg, then this mode should follow suit.

If you have time and energy, I would be happy to test and help out with prs :)

theothornhill commented 3 years ago

Oh and one more thing. If you start typing then indent now, it should indent, right?

kiennq commented 3 years ago

Oh and one more thing. If you start typing then indent now, it should indent, right?

Yeah, that's true.

kirill-gerasimenko-da commented 2 years ago

Do we have any hope? :slightly_smiling_face:

razzmatazz commented 2 years ago

Not sure if that is of any help but if you're using lsp-mode you can turn M-x lsp-toggle-on-type-formatting which ask the LSP server to do the formatting.

theothornhill commented 2 years ago

@kirill-gerasimenko-da no, I don't think so. I am waiting for the native emacs tree-sitter implementation, which AFAICT supports the missing node as a child. If you really want this feature, either use aggressive indent mode or make a pr to the tree-sitter-indent package.

@razzmatazz IIUC is is not formatting that is missing, but rather the absent node after opening a scope. It aligns with the parent node, not as a child until a child is made.

Elenfeathalion commented 2 years ago

Is this ticket still in limbo waiting for a native emacs tree-sitter? I find this bug extremely frustrating, but I'm not even sure what to ask of the tree-sitter-indent folks if I wanted to open a ticket there?

theothornhill commented 2 years ago

Yes, sorry. You can use M-i to indent manually one stop.

Things are happening with tree-sitter, albeit slowly:)

Elenfeathalion commented 1 year ago

Do you think this is going to be fixed in emacs 29, since that has tree-sitter?

theothornhill commented 1 year ago

Yes, i believe it is fixed already. If not, feel free to open a bug at the Emacs tracker 👍

josteink commented 1 year ago

csharp-mode is now developed as part of core emacs.

If you still have any issues, file a bug-report with the GNU Emacs bug-tracker :)