[clang] [clang-format] Improve BlockIndent at ColumnLimit (PR #93140)

Owen Pan via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 22 00:19:34 PDT 2024


================
@@ -803,6 +803,51 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
     return !Tok.Previous->isOneOf(TT_CastRParen, tok::kw_for, tok::kw_while,
                                   tok::kw_switch);
   };
+  auto IsLambdaParameterList = [](const FormatToken *Tok) {
+    // adapted from TokenAnnotator.cpp:isLambdaParameterList()
+    // Skip <...> if present.
+    if (Tok->Previous && Tok->Previous->is(tok::greater) &&
+        Tok->Previous->MatchingParen &&
+        Tok->Previous->MatchingParen->is(TT_TemplateOpener)) {
+      Tok = Tok->Previous->MatchingParen;
+    }
+
+    // Check for `[...]`.
+    return Tok->Previous && Tok->Previous->is(tok::r_square) &&
+           Tok->Previous->MatchingParen &&
+           Tok->Previous->MatchingParen->is(TT_LambdaLSquare);
+  };
+  auto IsFunctionCallParen = [&](const FormatToken &Tok) {
+    return Tok.is(tok::l_paren) && Tok.ParameterCount > 0 && Tok.Previous &&
+           Tok.Previous->is(tok::identifier);
+  };
+  const auto IsInTemplateString = [&](const FormatToken &Tok) {
+    if (!Style.isJavaScript())
+      return false;
+    for (const FormatToken *Prev = &Tok; Prev; Prev = Prev->Previous) {
----------------
owenca wrote:

```suggestion
    for (const auto *Prev = &Tok; Prev; Prev = Prev->Previous) {
```

https://github.com/llvm/llvm-project/pull/93140


More information about the cfe-commits mailing list