Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C++ indentation is wrong for access specifiers #7206

Closed
mostlymaxi opened this issue Jun 1, 2023 · 3 comments · Fixed by #8307
Closed

C++ indentation is wrong for access specifiers #7206

mostlymaxi opened this issue Jun 1, 2023 · 3 comments · Fixed by #8307
Labels
A-indent Area: Indentation A-language-support Area: Support for programming/text languages C-bug Category: This is a bug

Comments

@mostlymaxi
Copy link

Summary

Closing bracket of class methods in access specifiers is not indented properly.

class Foo {
  public:
    Foo() {
    
  } // missing an indent
}

Reproduction Steps

Create a method after an access specifier and let helix auto indent the closing bracket.

Expected closing bracket to be in-line with the method name.

Helix log

No response

Platform

Linux

Terminal Emulator

foot 1.14.0

Helix Version

helix 23.05 (3a8592a)

@mostlymaxi mostlymaxi added the C-bug Category: This is a bug label Jun 1, 2023
@kirawi kirawi added E-easy Call for participation: Experience needed to fix: Easy / not much E-good-first-issue Call for participation: Issues suitable for new contributors A-language-support Area: Support for programming/text languages labels Jun 1, 2023
@emadkhan713
Copy link

Wanted to say this is also the case on Windows 10 Pro v22H2 (build 19045.2965), running Helix from Command Prompt.

Also, it seems more like the editor is not indenting anything following the access specifier. Will investigate further.

@pascalkuthe pascalkuthe removed E-easy Call for participation: Experience needed to fix: Easy / not much E-good-first-issue Call for participation: Issues suitable for new contributors labels Jun 6, 2023
@pascalkuthe
Copy link
Member

CC @Triton171 Is this a simple oversight in the query or some limitetion of tgenindent code. In know there was some weirdness around c++ and I am not sure if it relates to this

@Triton171
Copy link
Contributor

This is a situation where people format their C++ code differently. The convention that helix supports (and that is also more common in my experience) is:

class Foo {
public:
  Foo() {
    
  }
}

Since there are no official code formatting guidelines for C++, this sort of thing tends to be common there (see also #6235). The current indentation system cannot really handle this (since indent queries don't adapt to the style in the current file). I have an idea how this could be improved which I'd like to implement at some point. There are definitely some tricky details to it but if we think about it carefully, it should essentially be possible to keep the advantages of tree-sitter based indentation while also never being significantly worse than the relative regex-based logic that most other editors use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-indent Area: Indentation A-language-support Area: Support for programming/text languages C-bug Category: This is a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants