Repository: carbon-language/carbon-lang
File: toolchain/check/import_cpp.cpp (C++)

Code before:

    std::string diagnostics_str = diagnostics_stream.TakeStr();

    switch (diag_level) {
      case clang::DiagnosticsEngine::Ignored:
      case clang::DiagnosticsEngine::Note:
      case clang::DiagnosticsEngine::Remark: {
        context_.TODO(
            loc_, llvm::formatv(
                      "Unsupported: C++ diagnostic level for diagnostic\n{0}",
                      diagnostics_str));
        return;
      }
      case clang::DiagnosticsEngine::Warning:
      case clang::DiagnosticsEngine::Error:
      case clang::DiagnosticsEngine::Fatal: {
        CARBON_DIAGNOSTIC(CppInteropParseWarning, Warning, "C++:\n{0}",
                          std::string);
        CARBON_DIAGNOSTIC(CppInteropParseError, Error, "C++:\n{0}",
                          std::string);
        CARBON_DIAGNOSTIC(InCppImport, Note, "in `Cpp` import");

        // TODO: Use a more specific location.
        context_.emitter()
            .Build(SemIR::LocId::None,
                   diag_level == clang::DiagnosticsEngine::Warning
                       ? CppInteropParseWarning
                       : CppInteropParseError,
                   diagnostics_str)
            .Note(loc_, InCppImport)
            .Emit();
        return;
      }
    }
  }

 private:
  // The type-checking context in which we're running Clang.
  Context& context_;

  // The location that triggered calling Clang.
  SemIRLoc loc_;
};

}  // namespace

// Returns an AST for the C++ imports and a bool that represents whether
// compilation errors where encountered or the generated AST is null due to an
// error.
// TODO: Consider to always have a (non-null) AST.
static auto GenerateAst(Context& context, llvm::StringRef importing_file_path,

Review comment (suggestion):
```suggestion
        // TODO: This should be part of the location, instead of added as a note here.
        CARBON_DIAGNOSTIC(InCppImport, Note, "in `Cpp` import");
```

Code after:
        diag_level, message, info.getRanges(), info.getFixItHints());

    std::string diagnostics_str = diagnostics_stream.TakeStr();

    switch (diag_level) {
      case clang::DiagnosticsEngine::Ignored:
      case clang::DiagnosticsEngine::Note:
      case clang::DiagnosticsEngine::Remark: {
        context_->TODO(
            loc_, llvm::formatv(
                      "Unsupported: C++ diagnostic level for diagnostic\n{0}",
                      diagnostics_str));
        return;
      }
      case clang::DiagnosticsEngine::Warning:
      case clang::DiagnosticsEngine::Error:
      case clang::DiagnosticsEngine::Fatal: {
        // TODO: Adjust diagnostics to drop the Carbon file here, and then
        // remove the "C++:\n" prefix.
        CARBON_DIAGNOSTIC(CppInteropParseWarning, Warning, "C++:\n{0}",
                          std::string);
        CARBON_DIAGNOSTIC(CppInteropParseError, Error, "C++:\n{0}",
                          std::string);
        // TODO: This should be part of the location, instead of added as a note
        // here.
        CARBON_DIAGNOSTIC(InCppImport, Note, "in `Cpp` import");

        // TODO: Use a more specific location.
        context_->emitter()
            .Build(SemIR::LocId::None,
                   diag_level == clang::DiagnosticsEngine::Warning
                       ? CppInteropParseWarning
                       : CppInteropParseError,
                   diagnostics_str)
            .Note(loc_, InCppImport)
            .Emit();
        return;
      }
    }
  }

 private:
  // The type-checking context in which we're running Clang.
  Context* context_;

  // The location that triggered calling Clang.
  SemIRLoc loc_;
};

}  // namespace