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