opencode icon indicating copy to clipboard operation
opencode copied to clipboard

feat(formater): restrict formatting to only the changed range of a file.

Open micuintus opened this issue 1 month ago • 15 comments

Restrict formatting only to the edited line range for clang-format When using the Edit tool, clang-format now only formats the specific lines that were changed, rather than reformatting the entire file. This prevents unrelated formatting changes from cluttering the diff.

Closes #4603

micuintus avatar Nov 21 '25 18:11 micuintus

@rekram1-node What is the state on this? Are you considering these suggestions?

micuintus avatar Nov 23 '25 21:11 micuintus

Yeah I see what you are trying to solve there. I would need some time to look into it more to review but I will say this looks very vibe coded so I won't just auto merge without a throughout review

rekram1-node avatar Nov 24 '25 02:11 rekram1-node

@rekram1-node

I would need some time to look into it more to review but I will say this looks very vibe coded so I won't just auto merge without a throughout review

Yes, I did use opencode for this PR ;). I am obviously new to this codebase and not a particular TypeScript expert. I had opencode run through several iterations with several models (Sonnet 4.5, GLM 4.6, Gemini 3, CODEX) though, letting the models review and discuss their results; asked them to asses the solution and the code quality, find bugs, make suggestions for simplification and improvement etc.

But yeah, this code needs to be reviewed, of course :)

I started with the line-number-based range API of clang-format and actually left it as a separate commit (the rest is squashed into the subsequent commit). Then I checked which interface Qt Creator uses: char/byte range API for subfile formatting --- and as it enables us to apply the same logic with Prettier I thought this makes sense as a "source of truth" format.

Aside from my use case (legacy code bases with humongous unformatted areas): Auto-formatting only the affected part of the file that opencode had touched makes a lot of sense to me; formatting the rest of the file should be a different task / step anyways IMO.

Having such a system in place would not only be very beneficial for my workflow, I believe it would make opencode a better tool for everyone.

Feel feel to request changes or I'd also be happy to hand this branch over.

micuintus avatar Nov 24 '25 10:11 micuintus

@rekram1-node Is there any way I can increase your confidence with that topic?

micuintus avatar Nov 26 '25 07:11 micuintus

@rekram1-node Is there any way I can increase your confidence with that topic?

@rekram1-node bump :)

micuintus avatar Dec 02 '25 09:12 micuintus

this is good we're gonna merge it, aiden will follow up

thdxr avatar Dec 03 '25 16:12 thdxr

@micuintus can you update your code to follow some of our style guidelines a bit better? https://github.com/sst/opencode/blob/dev/STYLE_GUIDE.md

Ex: change changedRanges to just ranges, stuff like that

rekram1-node avatar Dec 03 '25 16:12 rekram1-node

@micuintus can you update your code to follow some of our style guidelines a bit better? https://github.com/sst/opencode/blob/dev/STYLE_GUIDE.md

Ex: change changedRanges to just ranges, stuff like that

@rekram1-node Sorry for the delay, I only just saw this. -> Done: 2d4778310978089f6001b303832cd29b377ebd12

Anything else?

micuintus avatar Dec 05 '25 08:12 micuintus

/review

rekram1-node avatar Dec 05 '25 21:12 rekram1-node

lgtm

github-actions[bot] avatar Dec 05 '25 21:12 github-actions[bot]

u can ignore that fail its whatever, ill merge tonight

rekram1-node avatar Dec 06 '25 01:12 rekram1-node

/review

micuintus avatar Dec 09 '25 20:12 micuintus

lol only i can trigger it

rekram1-node avatar Dec 09 '25 20:12 rekram1-node

@rekram1-node

lol only i can trigger it

LOL #FAIL :)

u can ignore that fail its whatever, ill merge tonight

Anything else I can do to help?

micuintus avatar Dec 10 '25 11:12 micuintus

Hm?

micuintus avatar Dec 16 '25 09:12 micuintus