-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clangd] Implement simple folding for preprocessor branches #140959
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -220,6 +220,24 @@ getFoldingRanges(const std::string &Code, bool LineFoldingOnly) { | |
auto EndPosition = [&](const Token &T) { | ||
return offsetToPosition(Code, EndOffset(T)); | ||
}; | ||
|
||
// Preprocessor directives | ||
auto PPRanges = pairDirectiveRanges(DirectiveStructure, OrigStream); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add a testcase that has a nested conditional in both branches of an outer conditional, and checks that both nested conditionals get a folding range? (It would be easy to get this wrong by passing |
||
for (const auto &R : PPRanges) { | ||
auto BTok = OrigStream.tokens()[R.Begin]; | ||
auto ETok = OrigStream.tokens()[R.End]; | ||
if (ETok.Kind == tok::eof) | ||
continue; | ||
if (BTok.Line >= ETok.Line) | ||
continue; | ||
|
||
Position Start = EndPosition(BTok); | ||
Position End = StartPosition(ETok); | ||
if (LineFoldingOnly) | ||
End.line--; | ||
AddFoldingRange(Start, End, FoldingRange::REGION_KIND); | ||
} | ||
|
||
auto Tokens = ParseableStream.tokens(); | ||
// Brackets. | ||
for (const auto &Tok : Tokens) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of minor points here:
Preprocessed
orParseableStream
, while the code blocks for producing the other kinds of regions do, I think it would make sense for code organization to move this block above the declarations of those variables.// FIXME( usaxena95): Collect PP conditional regions, includes and other code regions ... "
to// FIXME( usaxena95): Collect includes and other code regions ...