@@ -391,18 +391,25 @@ impl RunSession {
391391 . ok ( ) ;
392392 }
393393
394- /// Re-registers the actions binding of a context whose language server
395- /// just became ready, so the host collects the actions of the open
396- /// documents again.
397- ///
398- /// The host collects once when a binding is registered and then only on
399- /// edits. The first registration runs right after `initialize`, while JDT
400- /// LS is still starting, so that collection answers no actions; without
401- /// this the gutter stays empty until the user edits the file.
394+ /// Refreshes open-document actions after readiness or a JDT project-model
395+ /// change. Progressive imports can finish additional modules after
396+ /// ServiceReady, so readiness alone is not the last collection boundary.
402397 pub fn did_receive_notification ( & self , params : & Value , report : & dyn Fn ( & str , u64 ) ) {
403- let Some ( context_id) = service_ready_context ( params) else {
398+ let Some ( context_id) = action_refresh_context ( params) else {
399+ return ;
400+ } ;
401+ let Ok ( reference) = WorkspaceContext :: from_value ( & params[ "context" ] ) else {
402+ return ;
403+ } ;
404+ let Some ( generation) = params. get ( "generation" ) . and_then ( Value :: as_u64) else {
404405 return ;
405406 } ;
407+ if !self
408+ . settings
409+ . accepts_server_notification ( & reference, generation)
410+ {
411+ return ;
412+ }
406413 if let Some ( stale) = lock ( & self . registrations ) . remove ( & context_id) {
407414 let _ = stale. subscription . dispose ( ) ;
408415 }
@@ -1111,17 +1118,27 @@ fn failure(code: &'static str, message: impl Into<String>) -> FunctionError {
11111118 PluginError :: new ( code, message) . into ( )
11121119}
11131120
1114- /// The context ID of a forwarded `language/status` `ServiceReady` of the
1115- /// `java` server, `None` for every other notification.
1116- fn service_ready_context ( params : & Value ) -> Option < String > {
1117- if params. get ( "serverID" ) . and_then ( Value :: as_str) != Some ( SERVER_ID )
1118- || params. get ( "method" ) . and_then ( Value :: as_str) != Some ( LANGUAGE_STATUS_METHOD )
1119- || params
1120- . get ( "params" )
1121- . and_then ( |status| status. get ( "type" ) )
1122- . and_then ( Value :: as_str)
1123- != Some ( SERVICE_READY_TYPE )
1124- {
1121+ /// The context of a JDT readiness or project/classpath change. Other semantic
1122+ /// notifications do not invalidate run markers. Accept both upstream enum
1123+ /// names and their published numeric values without inspecting project data.
1124+ fn action_refresh_context ( params : & Value ) -> Option < String > {
1125+ if params. get ( "serverID" ) . and_then ( Value :: as_str) != Some ( SERVER_ID ) {
1126+ return None ;
1127+ }
1128+ let refresh = match params. get ( "method" ) . and_then ( Value :: as_str) {
1129+ Some ( LANGUAGE_STATUS_METHOD ) => {
1130+ params. pointer ( "/params/type" ) . and_then ( Value :: as_str) == Some ( SERVICE_READY_TYPE )
1131+ }
1132+ Some ( "language/eventNotification" ) => {
1133+ let event = & params[ "params" ] [ "eventType" ] ;
1134+ matches ! (
1135+ event. as_str( ) ,
1136+ Some ( "ClasspathUpdated" | "ProjectsImported" | "ProjectsDeleted" )
1137+ ) || matches ! ( event. as_u64( ) , Some ( 100 | 200 | 210 ) )
1138+ }
1139+ _ => false ,
1140+ } ;
1141+ if !refresh {
11251142 return None ;
11261143 }
11271144 WorkspaceContext :: from_value ( & params[ "context" ] )
@@ -1146,15 +1163,15 @@ mod tests {
11461163 }
11471164
11481165 #[ test]
1149- fn only_a_service_ready_status_of_the_java_server_names_its_context ( ) {
1166+ fn a_service_ready_status_of_the_java_server_names_its_context ( ) {
11501167 let ready = json ! ( {
11511168 "context" : { "contextID" : "ctx-1" , "generation" : 3 } ,
11521169 "serverID" : SERVER_ID ,
11531170 "generation" : 2 ,
11541171 "method" : LANGUAGE_STATUS_METHOD ,
11551172 "params" : { "type" : SERVICE_READY_TYPE , "message" : "ServiceReady" } ,
11561173 } ) ;
1157- assert_eq ! ( service_ready_context ( & ready) . as_deref( ) , Some ( "ctx-1" ) ) ;
1174+ assert_eq ! ( action_refresh_context ( & ready) . as_deref( ) , Some ( "ctx-1" ) ) ;
11581175 let mut other_server = ready. clone ( ) ;
11591176 other_server[ "serverID" ] = json ! ( "kotlin" ) ;
11601177 let mut other_method = ready. clone ( ) ;
@@ -1166,7 +1183,30 @@ mod tests {
11661183 let mut no_context = ready. clone ( ) ;
11671184 no_context. as_object_mut ( ) . unwrap ( ) . remove ( "context" ) ;
11681185 for value in [ other_server, other_method, starting, no_params, no_context] {
1169- assert_eq ! ( service_ready_context( & value) , None , "{value}" ) ;
1186+ assert_eq ! ( action_refresh_context( & value) , None , "{value}" ) ;
1187+ }
1188+ }
1189+
1190+ #[ test]
1191+ fn progressive_import_and_classpath_changes_refresh_actions ( ) {
1192+ for event in [
1193+ json ! ( "ProjectsImported" ) ,
1194+ json ! ( "ClasspathUpdated" ) ,
1195+ json ! ( "ProjectsDeleted" ) ,
1196+ json ! ( 100 ) ,
1197+ json ! ( 200 ) ,
1198+ json ! ( 210 ) ,
1199+ ] {
1200+ let notification = json ! ( {
1201+ "context" : { "contextID" : "ctx-1" , "generation" : 1 } ,
1202+ "serverID" : SERVER_ID , "generation" : 1 ,
1203+ "method" : "language/eventNotification" , "params" : { "eventType" : event, "data" : [ ] } ,
1204+ } ) ;
1205+ assert_eq ! (
1206+ action_refresh_context( & notification) . as_deref( ) ,
1207+ Some ( "ctx-1" ) ,
1208+ "{event}"
1209+ ) ;
11701210 }
11711211 }
11721212
0 commit comments