Closed mehalter closed 3 months ago
If this is a common task, it might be useful to provide this maybe as a utility so formatters can easily calculate it on demand or we could even put this as part of the formatter context that is passed to the args
and prepend_args
functions
Mainly just the part that does the logic for calculating the correct indentation size. Something like expandtab
is not necessary. But how the tab key is converted to some number of spaces is not based just on tabstop
Nice QOL improvement for people writing formatters. Thanks for the well reasoned PR!
This adds the automatic setting of
-i
so thatshfmt
follows the current indentation settings of neovim. Whether it is manually set by the user or set through external factors such as.editorconfig
I also checked to see if this is done elsewhere for other formatters and found a couple others which I was able to improve the "correctness" of their indentation size calculations
EDIT: I was thinking about this and it seems like having the effective
shiftwidth
value is quite nice. And because this seems to be "contextual information" it seemed natural to put it in theconform.Context
type since it is virtually free to calculate performance wise. Let me know if you disagree. Another approach would be to make some sort of utility module that is imported by formatters on an as needed basis that calculates this. This is basically the same asvim.fn.shiftwidth
(:h shiftwidth()
) with the only difference being that it calculates it specifically for the buffer in the context rather than the "current buffer". This allowed for a very nice refactor across the formatters that utilize this field and is available for future formatters. Also nice to make sure we have a common method for calculating indentation size.Also
shiftwidth
andtabstop
are always integers according to the neovim docs so no need to have default fallbacks or check fornil