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