Skip to content

fix side-comments, add tabs or spaces functionality#197

Open
fdncred wants to merge 6 commits into
mainfrom
fdncred/plan-issues-195-196
Open

fix side-comments, add tabs or spaces functionality#197
fdncred wants to merge 6 commits into
mainfrom
fdncred/plan-issues-195-196

Conversation

@fdncred
Copy link
Copy Markdown
Contributor

@fdncred fdncred commented May 19, 2026

Description of changes

Add the ability to have tabs or spaces in formatting.

  • Added indent_char config support with values "space" (default) and "tab".

Fix the side-comments bug

  • Fixed multiline list formatting so side/inline comments are preserved.
  • Lists containing comments are now kept multiline, comments before items are emitted correctly, inline comments after list items are retained, and list flag/value pairing is skipped when comments would be affected.

Relevant Issues

closes #195
closes #196

@Juhan280
Copy link
Copy Markdown

There should be only one \t character per indent level. The indent config option should only configure its virtual size (i.e. treat one \t char as 4 space when indent: 4 and not insert four \t per indentation). That virtual size would be used for line wrapping and other calculations

@fdncred
Copy link
Copy Markdown
Contributor Author

fdncred commented May 20, 2026

oops, can you try again?

@Juhan280
Copy link
Copy Markdown

Yes, now only one tab char is inserted per indentation level. But layout calculation doesn't respect the indent config value at all. Looking into it further, it seems like it doesn't even account for the indentation char when calculating layout.

# The `echo` line becomes 80 characters long and still doesn't wrap, even though max is specified to be 40 in the config 
# I assume this is because the length of the line after trimming whitespace is exactly 40
# If we add one more char to that line, it makes it wrap again.
def test [] {
	{
		echo abv def fef faei feal afea abcdefgh
	}
}

Config:

{
	indent_char: space
	indent: 20
	line_length: 40
}

@fdncred
Copy link
Copy Markdown
Contributor Author

fdncred commented May 20, 2026

i'll see what i can do. it's not the same issue but related.

…stments and add tests for indentation behavior
@fdncred
Copy link
Copy Markdown
Contributor Author

fdncred commented May 20, 2026

ok @Juhan280 try this one. crossing my fingers it's right now.

@Juhan280
Copy link
Copy Markdown

It seems to be working correctly from my limited testing

Comment thread src/formatting/mod.rs
Comment on lines +137 to +146
IndentChar::Space => {
for _ in 0..(self.config.indent * self.indent_level) {
self.output.push(b' ');
}
}
IndentChar::Tab => {
for _ in 0..self.indent_level {
self.output.push(b'\t');
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we call self.output.reserve before starting the loop?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ya, probably so. thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow setting indent char to tab nufmt eats the side comments

2 participants