brownts / gpr-ts-mode

GNAT Project major mode using tree-sitter for Emacs
GNU General Public License v3.0
0 stars 1 forks source link

Indentation points #1

Open simonjwright opened 1 week ago

simonjwright commented 1 week ago

gpr-mode indented like these:

   for Source_Dirs use Common.Paths &
     (
      "adainclude",
      "rp2350_svd",
      FreeRTOS.Source,
      FreeRTOS.Portable_Base & "RISC-V"
     );

   for Switches ("s-traceb.adb") use ALL_ADAFLAGS & ("-g")
      & NO_SIBLING_ADAFLAGS & ("-fno-inline-functions-called-once");

but gpr-ts-mode like these:

   for Source_Dirs use Common.Paths &
                         (
                          "adainclude",
                          "rp2350_svd",
                          FreeRTOS.Source,
                          FreeRTOS.Portable_Base & "RISC-V"
                         );

   for Switches ("s-traceb.adb") use ALL_ADAFLAGS & ("-g")
                                       & NO_SIBLING_ADAFLAGS & ("-fno-inline-functions-called-once");

It looks as though gpr-mode treats for-use statements rather like expressions, whereas gpr-ts-mode indents to the first token after use.

I don’t say there’s anything wrong, just something I’ll need to get used to .. well worth the effort, thank you!

Looking at the second example, does gpr-ts-mode have a line length (like the 79 in ada-mode) that it’ll automatically fold long lines to, or does it require the user to insert newlines where they want the folds?

brownts commented 1 week ago

It looks as though gpr-mode treats for-use statements rather like expressions, whereas gpr-ts-mode indents to the first token after use.

Currently, gpr-ts-mode will try to keep the indentation of an expression together, that's why it aligns that way. I think I was trying to be clever, because it seemed to make sense to me that you'd want to keep the expression together, but the more I have thought about it, I wondered if that was really what people were expecting. I'd like the indentation to do what people think it should do. If you put the first part of the expression on the next line, it will align to that.

   for Source_Dirs use
     Common.Paths &
       (
        "adainclude",
        "rp2350_svd",
        FreeRTOS.Source,
        FreeRTOS.Portable_Base & "RISC-V"
       );

   for Switches ("s-traceb.adb") use
     ALL_ADAFLAGS & ("-g")
       & NO_SIBLING_ADAFLAGS & ("-fno-inline-functions-called-once");

I also have an additional indentation parameter (above what gpr-mode has), gpr-ts-mode-indent-exp-item-offset, which is used to indent subexpressions within a larger expression. You can see that behavior in the above based on how the parenthesis are indented relative to the start of the expression. I've recently thought that is probably not what people are expecting so I was planning to default this value to 0. If, so this ends up looking like this:

   for Source_Dirs use
     Common.Paths &
     (
      "adainclude",
      "rp2350_svd",
      FreeRTOS.Source,
      FreeRTOS.Portable_Base & "RISC-V"
     );

   for Switches ("s-traceb.adb") use
     ALL_ADAFLAGS & ("-g")
     & NO_SIBLING_ADAFLAGS & ("-fno-inline-functions-called-once");

I don’t say there’s anything wrong, just something I’ll need to get used to

I'm open to opinions on how you think this should behave. I'm working on indentation support for ada-ts-mode as well, and these types of decisions would flow into that too. I thought I was making an improvement over what was provided in gpr-mode, but if it's not what people expect, it might not be an improvement.

.. well worth the effort, thank you!

Thanks, I'm glad you find it useful!

Looking at the second example, does gpr-ts-mode have a line length (like the 79 in ada-mode) that it’ll automatically fold long lines to, or does it require the user to insert newlines where they want the folds?

Currently, there is nothing in the mode to support folding lines. I could look into that, but it hadn't crossed my mind.

simonjwright commented 1 week ago

I think I’d keep gpr-ts-mode-indent-exp-item-offset, set to 2. It’s one of those things where sometimes, even within the same file, some cases feel better one way, some the other. The operative word being "feel".

Currently, there is nothing in the mode to support folding lines. I could look into that, but it hadn't crossed my mind.

Sometimes, with ada-mode, you’d type the final newline of a section and the whole section would re-format itself, folding included!

And, automatically choosing where the folds go feels rather overbearing. So I wouldn’t worry.

brownts commented 6 days ago

Thanks for the input, I'll keep the default for gpr-ts-mode-indent-exp-item-offset.

While it doesn't address folding, I did release a new version of gpr-ts-mode yesterday that supports declaration-based indentation (now the new default). This will attempt to re-indent an entire declaration, if there are no syntax errors in the declaration. In the presence of syntax errors, it will fallback to the normal line-based indentation. The intention of this is to recover from previously incorrect indentation due to the presence of syntax errors. You can go back to the previous indentation strategy by changing gpr-ts-mode-indent-strategy to line.

I'm hoping this will be an improvement over the previous line-based indentation which would leave the buffer needing to be reformatted when multi-line constructs (i.e., case construction , package declaration, project declarations, etc.) were not syntactically correct when indentation was performed.

If you don't mind me asking, how did you enable/configure folding? I poked around at the gpr-mode code, but didn't see anything to configure, nor did I find documentation on it, but maybe I just wasn't looking in the correct location.