@@ -26,17 +26,15 @@ pub struct DiagnosticsMapConfig {
26
26
27
27
pub ( crate ) type DiagnosticsGeneration = usize ;
28
28
29
- #[ derive( Debug , Clone ) ]
29
+ #[ derive( Debug , Clone , Default ) ]
30
30
pub ( crate ) struct WorkspaceFlycheckDiagnostic {
31
- pub ( crate ) generation : DiagnosticsGeneration ,
32
- pub ( crate ) per_package :
33
- FxHashMap < Option < Arc < PackageId > > , FxHashMap < FileId , Vec < lsp_types:: Diagnostic > > > ,
31
+ pub ( crate ) per_package : FxHashMap < Option < Arc < PackageId > > , PackageFlycheckDiagnostic > ,
34
32
}
35
33
36
- impl WorkspaceFlycheckDiagnostic {
37
- fn new ( generation : DiagnosticsGeneration ) -> Self {
38
- WorkspaceFlycheckDiagnostic { generation, per_package : Default :: default ( ) }
39
- }
34
+ # [ derive ( Debug , Clone ) ]
35
+ pub ( crate ) struct PackageFlycheckDiagnostic {
36
+ generation : DiagnosticsGeneration ,
37
+ per_file : FxHashMap < FileId , Vec < lsp_types :: Diagnostic > > ,
40
38
}
41
39
42
40
#[ derive( Debug , Default , Clone ) ]
@@ -68,7 +66,7 @@ impl DiagnosticCollection {
68
66
let Some ( check) = self . check . get_mut ( flycheck_id) else {
69
67
return ;
70
68
} ;
71
- self . changes . extend ( check. per_package . drain ( ) . flat_map ( |( _, v) | v. into_keys ( ) ) ) ;
69
+ self . changes . extend ( check. per_package . drain ( ) . flat_map ( |( _, v) | v. per_file . into_keys ( ) ) ) ;
72
70
if let Some ( fixes) = Arc :: make_mut ( & mut self . check_fixes ) . get_mut ( flycheck_id) {
73
71
fixes. clear ( ) ;
74
72
}
@@ -79,7 +77,7 @@ impl DiagnosticCollection {
79
77
self . changes . extend (
80
78
self . check
81
79
. iter_mut ( )
82
- . flat_map ( |it| it. per_package . drain ( ) . flat_map ( |( _, v) | v. into_keys ( ) ) ) ,
80
+ . flat_map ( |it| it. per_package . drain ( ) . flat_map ( |( _, v) | v. per_file . into_keys ( ) ) ) ,
83
81
)
84
82
}
85
83
@@ -93,7 +91,7 @@ impl DiagnosticCollection {
93
91
} ;
94
92
let package_id = Some ( package_id) ;
95
93
if let Some ( checks) = check. per_package . remove ( & package_id) {
96
- self . changes . extend ( checks. into_keys ( ) ) ;
94
+ self . changes . extend ( checks. per_file . into_keys ( ) ) ;
97
95
}
98
96
if let Some ( fixes) = Arc :: make_mut ( & mut self . check_fixes ) . get_mut ( flycheck_id) {
99
97
fixes. remove ( & package_id) ;
@@ -105,8 +103,20 @@ impl DiagnosticCollection {
105
103
flycheck_id : usize ,
106
104
generation : DiagnosticsGeneration ,
107
105
) {
108
- if self . check . get ( flycheck_id) . is_some_and ( |it| it. generation < generation) {
109
- self . clear_check ( flycheck_id) ;
106
+ if let Some ( flycheck) = self . check . get_mut ( flycheck_id) {
107
+ let mut packages = vec ! [ ] ;
108
+ self . changes . extend (
109
+ flycheck
110
+ . per_package
111
+ . extract_if ( |_, v| v. generation < generation)
112
+ . inspect ( |( package_id, _) | packages. push ( package_id. clone ( ) ) )
113
+ . flat_map ( |( _, v) | v. per_file . into_keys ( ) ) ,
114
+ ) ;
115
+ if let Some ( fixes) = Arc :: make_mut ( & mut self . check_fixes ) . get_mut ( flycheck_id) {
116
+ for package in packages {
117
+ fixes. remove ( & package) ;
118
+ }
119
+ }
110
120
}
111
121
}
112
122
@@ -126,21 +136,19 @@ impl DiagnosticCollection {
126
136
fix : Option < Box < Fix > > ,
127
137
) {
128
138
if self . check . len ( ) <= flycheck_id {
129
- self . check
130
- . resize_with ( flycheck_id + 1 , || WorkspaceFlycheckDiagnostic :: new ( generation) ) ;
139
+ self . check . resize_with ( flycheck_id + 1 , WorkspaceFlycheckDiagnostic :: default) ;
131
140
}
132
141
142
+ let check = & mut self . check [ flycheck_id] ;
143
+ let package = check. per_package . entry ( package_id. clone ( ) ) . or_insert_with ( || {
144
+ PackageFlycheckDiagnostic { generation, per_file : FxHashMap :: default ( ) }
145
+ } ) ;
133
146
// Getting message from old generation. Might happen in restarting checks.
134
- if self . check [ flycheck_id ] . generation > generation {
147
+ if package . generation > generation {
135
148
return ;
136
149
}
137
- self . check [ flycheck_id] . generation = generation;
138
- let diagnostics = self . check [ flycheck_id]
139
- . per_package
140
- . entry ( package_id. clone ( ) )
141
- . or_default ( )
142
- . entry ( file_id)
143
- . or_default ( ) ;
150
+ package. generation = generation;
151
+ let diagnostics = package. per_file . entry ( file_id) . or_default ( ) ;
144
152
for existing_diagnostic in diagnostics. iter ( ) {
145
153
if are_diagnostics_equal ( existing_diagnostic, & diagnostic) {
146
154
return ;
@@ -210,7 +218,7 @@ impl DiagnosticCollection {
210
218
. check
211
219
. iter ( )
212
220
. flat_map ( |it| it. per_package . values ( ) )
213
- . filter_map ( move |it| it. get ( & file_id) )
221
+ . filter_map ( move |it| it. per_file . get ( & file_id) )
214
222
. flatten ( ) ;
215
223
native_syntax. chain ( native_semantic) . chain ( check)
216
224
}
0 commit comments