Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
This actually works, but still far from landing.
Notable problems:
- this adds a dependency on TokenBuffer, so we need to land it first.
- this change is too big, planning to split into multiple changes: (1) collecting tokens when building the AST for clangd, (2) add helpers into TokenBuffer
- it currently tries to replace any "mapping", not just preprocessor expansions. E.g. will attempt to replace #define FOO ... with an empty string.
- needs more tests.
Will get back to it after TokenBuffer lands.
clang-tools-extra/clangd/refactor/tweaks/ExpandMacro.cpp | ||
---|---|---|
57 ↗ | (On Diff #206388) | it's pretty weird for a function whose return type is spelled "Token*" to use Spelled.end() rather than nullptr as a sentinel |
125 ↗ | (On Diff #206388) | include macro name? |
clang-tools-extra/clangd/unittests/TweakTests.cpp | ||
288 ↗ | (On Diff #206388) | Can you verify we don't trigger here? FOO[[ ]]BAR The zero-width range in FOO^ BAR is indeed interpreted as pointing at FOO by SelectionTree, but that's a whitespace-sensitive heuristic. Given int x(int); #define B x int y = B^(42); The ^ points at the (. (Maybe we should lift this logic into Tweak::Selection) |
- Replace bsearch with partition_point.
- Include macro name in the title.
- Added a FIXME for empty selection case.
- Return null when no token is found.
clang-tools-extra/clangd/refactor/tweaks/ExpandMacro.cpp | ||
---|---|---|
57 ↗ | (On Diff #206388) | Yeah, especially given that the function below uses nullptr as a sentinel... |
clang-tools-extra/clangd/unittests/TweakTests.cpp | ||
288 ↗ | (On Diff #206388) | It does trigger, unfortunately. There is no way to unbreak this, as we don't have a way to get the selection range in inputs of the tweak. Note that we don't use selection tree, as it's AST-based and we need token-level information for that tweak (that's pretty unique, I expect most tweaks are not like that) |