@@ -2858,52 +2858,51 @@ class StoringDiagnosticConsumer : public swift::DiagnosticConsumer {
2858
2858
const DiagnosticSeverity severity = SeverityForKind (diagnostic.kind );
2859
2859
const DiagnosticOrigin origin = eDiagnosticOriginSwift;
2860
2860
2861
- if (first_line > 0 && bufferID != UINT32_MAX &&
2862
- diagnostic.bufferID == bufferID && !diagnostic.bufferName .empty ()) {
2863
- // Make sure the error line is in range.
2864
- if (diagnostic.line >= first_line && diagnostic.line <= last_line) {
2865
- // Need to remap the error/warning to a different line.
2866
- StreamString match;
2867
- match.Printf (" %s:%u:" , diagnostic.bufferName .str ().c_str (),
2868
- diagnostic.line );
2869
- const size_t match_len = match.GetString ().size ();
2870
- size_t match_pos =
2871
- diagnostic.description .find (match.GetString ().str ());
2872
- if (match_pos != std::string::npos) {
2873
- // We have some <file>:<line>:" instances that need to be updated.
2874
- StreamString fixed_description;
2875
- size_t start_pos = 0 ;
2876
- do {
2877
- if (match_pos > start_pos)
2878
- fixed_description.Printf (
2879
- " %s" , diagnostic.description .substr (start_pos, match_pos)
2880
- .c_str ());
2881
- fixed_description.Printf (
2882
- " %s:%u:" , diagnostic.bufferName .str ().c_str (),
2883
- diagnostic.line - first_line + 1 );
2884
- start_pos = match_pos + match_len;
2885
- match_pos = diagnostic.description .find (match.GetString ().str (),
2886
- start_pos);
2887
- } while (match_pos != std::string::npos);
2888
-
2889
- // Append any last remaining text.
2890
- if (start_pos < diagnostic.description .size ())
2861
+ if (first_line > 0 && bufferID != UINT32_MAX) {
2862
+ // Make sure the error line is in range or in another file.
2863
+ if (diagnostic.bufferID == bufferID && !diagnostic.bufferName .empty () &&
2864
+ (diagnostic.line < first_line || diagnostic.line > last_line))
2865
+ continue ;
2866
+ // Need to remap the error/warning to a different line.
2867
+ StreamString match;
2868
+ match.Printf (" %s:%u:" , diagnostic.bufferName .str ().c_str (),
2869
+ diagnostic.line );
2870
+ const size_t match_len = match.GetString ().size ();
2871
+ size_t match_pos = diagnostic.description .find (match.GetString ().str ());
2872
+ if (match_pos != std::string::npos) {
2873
+ // We have some <file>:<line>:" instances that need to be updated.
2874
+ StreamString fixed_description;
2875
+ size_t start_pos = 0 ;
2876
+ do {
2877
+ if (match_pos > start_pos)
2891
2878
fixed_description.Printf (
2892
- " %s" , diagnostic.description
2893
- .substr (start_pos,
2894
- diagnostic.description .size () - start_pos)
2895
- .c_str ());
2896
-
2897
- auto new_diagnostic = std::make_unique<SwiftDiagnostic>(
2898
- fixed_description.GetData (), severity, origin, bufferID);
2899
- for (auto fixit : diagnostic.fixits )
2900
- new_diagnostic->AddFixIt (fixit);
2901
-
2902
- diagnostic_manager.AddDiagnostic (std::move (new_diagnostic));
2879
+ " %s" ,
2880
+ diagnostic.description .substr (start_pos, match_pos).c_str ());
2881
+ fixed_description.Printf (
2882
+ " %s:%u:" , diagnostic.bufferName .str ().c_str (),
2883
+ diagnostic.line - first_line + 1 );
2884
+ start_pos = match_pos + match_len;
2885
+ match_pos =
2886
+ diagnostic.description .find (match.GetString ().str (), start_pos);
2887
+ } while (match_pos != std::string::npos);
2888
+
2889
+ // Append any last remaining text.
2890
+ if (start_pos < diagnostic.description .size ())
2891
+ fixed_description.Printf (
2892
+ " %s" , diagnostic.description
2893
+ .substr (start_pos,
2894
+ diagnostic.description .size () - start_pos)
2895
+ .c_str ());
2896
+
2897
+ auto new_diagnostic = std::make_unique<SwiftDiagnostic>(
2898
+ fixed_description.GetData (), severity, origin, bufferID);
2899
+ for (auto fixit : diagnostic.fixits )
2900
+ new_diagnostic->AddFixIt (fixit);
2901
+
2902
+ diagnostic_manager.AddDiagnostic (std::move (new_diagnostic));
2903
+ if (diagnostic.kind == swift::DiagnosticKind::Error)
2903
2904
added_one_diagnostic = true ;
2904
2905
2905
- continue ;
2906
- }
2907
2906
}
2908
2907
}
2909
2908
}
0 commit comments