Details
- Reviewers
ilya-biryukov
Diff Detail
- Repository
- rCTE Clang Tools Extra
- Build Status
Buildable 27741 Build 27740: arc lint + arc unit
Event Timeline
clangd/ClangdServer.cpp | ||
---|---|---|
367 | not sure the err-handling strategy here -- maybe if this is failed, we still apply replacements (without formatting), rather than stopping. |
clangd/ClangdServer.cpp | ||
---|---|---|
367 | You should use getFormatStyleForFile from SourceCode.h |
Could we move the code to the Tweak itself, so that all the callers would get the formatting? I.e.
class Tweak { Replacements apply() { // This is now non-virtual. auto Replacements = doApply(); return cleanupAndFormat(Replacements); } protected: virtual Replacements doApply() = 0; // inheritors should implement this now. Note: the name is terrible, suggestions are welcome. };
This would ensure the callers don't need to deal with the formatting on their own.
clangd/ClangdServer.cpp | ||
---|---|---|
364 | We can get the contents from InpAST.Inputs.Contents, no need to add an extra parameter. | |
504 | Could this function get a vfs::FileSystem as a parameter? | |
clangd/ClangdServer.h | ||
269 | NIT: could we swap the parameters for consistency with the other functions in this class (i.e. File goes first) | |
clangd/Format.h | ||
29 | NIT: add newline at the end of file. | |
unittests/clangd/TweakTests.cpp | ||
82 | NIT: remove the parameter, this should be the default. | |
110 | NIT: maybe prefer LLVM style? To avoid context-switching. |
clangd/ClangdServer.cpp | ||
---|---|---|
367 |
Returning an error seems fine, this probably shouldn't happen under normal conditions and failing early means we're more likely to find the root-cause of the problem. |
This seems introduce intrusive changes to the Tweak interface (Tweak will need to know the FormatStyle somehow), I think this might be done in another patch.
clangd/ClangdServer.cpp | ||
---|---|---|
367 |
Thanks for pointing it out! Didn't notice this method. I think we need to cache it somehow rather than calling this method every time.
I switched to use getFormatStyleForFile, it seems a reasonable API. | |
clangd/ClangdServer.h | ||
269 | removed, not needed any more. | |
unittests/clangd/TweakTests.cpp | ||
82 | I'm ok to make this change. I tempt to keep it because it would make writing test code easier -- if we always format the code, we might spend time on figuring out the format diff between Before and After, which is not worth. | |
110 | good catch. |
It's totally fine, since we have just a single tweak now and changing the interface costs nothing.
The important part is making it hard to misuse the interface and forcing formatting on all the users of the interface is a significant burden. E.g. other users of ClangdServer (tests, users of clangd C++ API) shouldn't worry about formatting on their own.
clangd/refactor/Tweak.h | ||
---|---|---|
81 ↗ | (On Diff #185529) | I think the current name is slightly better than doApply, I also have a few candidates in mind perform, invoke. |
clangd/refactor/Tweak.h | ||
---|---|---|
81 ↗ | (On Diff #185529) | execute() LGTM! |
clangd/refactor/Tweak.h | ||
---|---|---|
56 ↗ | (On Diff #185529) | SG, this also makes the format intention of apply more explicitly. |
LGTM! Also a few NITs.
clangd/ClangdServer.cpp | ||
---|---|---|
156 | NIT: put . to the end of the comment. | |
376–377 | This FIXME is stale now, remove? | |
clangd/Format.h | ||
20 | NIT: Maybe move to SourceCode.h? We have helpers to turn replacements into edits there, having this would be a good addition. The extra file does not seem to carry its weight. |
I agree with this concern, and don't think this is an appropriate layer to be aware of styling or failing on format errors. Can we consider moving the formatting to clangdserver as originally planned?
clang-format seems to be somewhat stable, do we actually expect that to be a large problem in practice?
On the other side, I can't imagine any clients that don't need formatting? E.g. it's nice when tests give the same results as one would see in the final clangd and tests don't go through ClangdServer.
It's not about stability or whether the functionality is desired, but layering.
Unit tests having narrow scope is a good thing - if we want system tests that check clangdserver's behavior, they should test clangdserver.
Clients that don't go through clangdserver probably want formatting, but an immediate cleanupAndFormat on each generated change isn't necessarily the right way to do that.
My argument is that it's better to provide formatting by default in the public interface for applying a single tweak.
I might be missing some use-cases, e.g. one that comes to mind is applying multiple tweaks in a row, in which case we'd want to format once and not for every tweak.
My concerns are code duplication and ease of use for the clients. Having both apply and applyAndFormat (the latter being a non-virtual or a free-standing utility function) in the public interface of the Tweak would totally do it for me.
However, I also think tests should format by default, not sure we agree on this.
WDYT?
If providing formatting was free, I'd be fine with this, but it leaks into the public interface in two places: a) it requires the caller to plumb through a formatting style, and b) it is another source of errors.
For this particular interface it's more important that it's conceptually clear and easy to implement than it is that it's easy to call - this is an extension point.
My concerns are code duplication and ease of use for the clients. Having both apply and applyAndFormat (the latter being a non-virtual or a free-standing utility function) in the public interface of the Tweak would totally do it for me.
I'd be happy with applyAndFormat as a free function - my main concern is that formatting not be part of the scope of the class.
However, I also think tests should format by default, not sure we agree on this.
WDYT?
I'd rather they didn't format, but I don't think it will matter much and I'm happy either way.
(Where it does matter, I'd rather have the differences between input/output be a result of the tweak replacements, not of different formatting triggered by a different token sequence.
I don't think there's much point in testing clang-format here, though we should have one test that verifies we're calling it at all.)
Given that clangdServer is the only client of Tweaks (if we don't do format in tests), I think it is fine to move out applyAndFormat functionality from Tweaks. I somehow agree that applyAndFormat is a standalone function.
However, I also think tests should format by default, not sure we agree on this.
WDYT?I'd rather they didn't format, but I don't think it will matter much and I'm happy either way.
(Where it does matter, I'd rather have the differences between input/output be a result of the tweak replacements, not of different formatting triggered by a different token sequence.
I don't think there's much point in testing clang-format here, though we should have one test that verifies we're calling it at all.)
Personally, I prefer not doing format in tests -- it would make writing testcases easier, it is annoying to spend time on figuring out format-only differences between actual code and expected code.
NIT: could we swap the parameters for consistency with the other functions in this class (i.e. File goes first)