66//! other plugins contribute. The plugin manifest declares it as the plugin's
77//! `backend`.
88//!
9- //! The Java rules themselves still run in the host for the editor providers,
10- //! run configurations and the Java test workflow; the backend is where they
11- //! move, one host API at a time (see `MIGRATION.md`).
9+ //! The run, debug and test actions of Java files are the backend's own as
10+ //! well ([`run`]): it collects them through editor actions and starts the
11+ //! processes through the host's `run/start` method. What still waits for a
12+ //! host API is listed in `MIGRATION.md`.
13+ //!
14+ //! # Language server launch (serverProcess 3)
15+ //!
16+ //! The manifest declares the `java` language server with
17+ //! `launch.kind: "backend"`, so the host asks [`launch`] for the JDT LS
18+ //! command line, initialization options and startup settings before each
19+ //! start. The launch reads the settings the [`settings_session`] knows for
20+ //! the workspace, so a restart starts with the last pushed settings.
1221//!
1322//! # Cross-plugin settings (API-35)
1423//!
3847//! `settings_session::SESSION_CATEGORIES`. The backend never writes to
3948//! stderr, and a fact carries no path, source or tool output.
4049
50+ pub mod launch;
4151pub mod plugin_functions;
52+ pub mod run;
4253pub mod settings_session;
4354
55+ use crate :: launch:: LAUNCH_FUNCTION_ID ;
56+ use crate :: run:: {
57+ RunSession , COLLECT_FUNCTION_ID , LANGUAGE_SERVER_NOTIFICATION , RERUN_FUNCTION_ID ,
58+ RESOLVE_LINK_FUNCTION_ID , RUN_ACTION_FUNCTION_ID , RUN_DID_EXIT_NOTIFICATION ,
59+ } ;
4460use crate :: settings_session:: {
4561 HostServices , SettingsSession , LANGUAGE_SERVER_STATE_NOTIFICATION , SETTINGS_CHANGED_FUNCTION_ID ,
4662} ;
@@ -66,10 +82,19 @@ const NOTIFICATION_OPERATION: &str = "notification";
6682/// `languageImport.settingsChanged` is a key operation: another plugin
6783/// reports a change a user made, it happens rarely, and its success is the
6884/// only trace that the change reached the language server.
85+ /// `java.resolveLaunch` is one too: it runs once per language server start
86+ /// and its success is the only trace of which package files the server
87+ /// started from. `java.runAction` and `java.rerun` are key operations
88+ /// because each is one user click that starts a process; collection and
89+ /// output link resolution run on every edit and every output line, so their
90+ /// successes are suppressed.
6991pub const KEY_OPERATIONS : & [ & str ] = & [
7092 "debug.javaTestLaunch" ,
7193 "execution.planLaunchCommand" ,
7294 "java.prepareLaunch" ,
95+ LAUNCH_FUNCTION_ID ,
96+ RERUN_FUNCTION_ID ,
97+ RUN_ACTION_FUNCTION_ID ,
7398 SETTINGS_CHANGED_FUNCTION_ID ,
7499 "runConfig.selectJava" ,
75100] ;
@@ -78,8 +103,9 @@ pub const KEY_OPERATIONS: &[&str] = &[
78103///
79104/// A function can only be suppressed once it is registered, so the successes
80105/// of the functions outside [`KEY_OPERATIONS`] are suppressed after the
81- /// registration loop. `languageImport.settingsChanged` is registered after
82- /// that loop and is a key operation, so it needs no suppression.
106+ /// registration loop. `languageImport.settingsChanged` and
107+ /// `java.resolveLaunch` are registered after that loop and are key
108+ /// operations, so they need no suppression.
83109///
84110/// Every input is a compile-time constant, so the result is the same on each
85111/// run: it fails only when a function ID is invalid, repeated or over the
@@ -120,9 +146,69 @@ pub fn backend() -> Result<Backend, SdkError> {
120146 Ok ( ( ) )
121147 }
122148 } ) ?;
123- backend. function ( SETTINGS_CHANGED_FUNCTION_ID , move |params, context| {
124- settings_changed ( & session, params, context)
149+ backend. function ( SETTINGS_CHANGED_FUNCTION_ID , {
150+ let session = Arc :: clone ( & session) ;
151+ move |params, context| settings_changed ( & session, params, context)
152+ } ) ?;
153+ backend. function ( LAUNCH_FUNCTION_ID , move |params, context| {
154+ launch:: resolve_launch_function ( & session, params, context)
155+ } ) ?;
156+
157+ // The run session registers the editor actions of every workspace context
158+ // and keeps the result listener of each test run; both happen outside a
159+ // function call, so it holds the backend handle too.
160+ let run_session = Arc :: new ( RunSession :: new ( backend. handle ( ) ) ) ;
161+ let report: run:: Report = {
162+ let handle = backend. handle ( ) ;
163+ Arc :: new ( move |code : & str , count : u64 | {
164+ let _ = handle
165+ . diagnostics ( )
166+ . degraded ( NOTIFICATION_OPERATION , code, Some ( count) ) ;
167+ } )
168+ } ;
169+ backend. on_initialize ( {
170+ let run_session = Arc :: clone ( & run_session) ;
171+ let report = Arc :: clone ( & report) ;
172+ move |_initialize| {
173+ run_session. sync_after_initialize ( Arc :: clone ( & report) ) ;
174+ Ok ( ( ) )
175+ }
176+ } ) ;
177+ backend. on_contexts_changed ( {
178+ let run_session = Arc :: clone ( & run_session) ;
179+ let report = Arc :: clone ( & report) ;
180+ move |_params| {
181+ run_session. sync_contexts_reporting ( & * report) ;
182+ Ok ( ( ) )
183+ }
184+ } ) ;
185+ backend. on_host_notification ( RUN_DID_EXIT_NOTIFICATION , {
186+ let run_session = Arc :: clone ( & run_session) ;
187+ move |params| {
188+ run_session. run_did_exit ( & params) ;
189+ Ok ( ( ) )
190+ }
191+ } ) ?;
192+ backend. on_host_notification ( LANGUAGE_SERVER_NOTIFICATION , {
193+ let run_session = Arc :: clone ( & run_session) ;
194+ let report = Arc :: clone ( & report) ;
195+ move |params| {
196+ run_session. did_receive_notification ( & params, & * report) ;
197+ Ok ( ( ) )
198+ }
199+ } ) ?;
200+ backend. function ( COLLECT_FUNCTION_ID , run:: collect_actions_function) ?;
201+ backend. suppress_success_diagnostics ( COLLECT_FUNCTION_ID ) ?;
202+ backend. function ( RUN_ACTION_FUNCTION_ID , {
203+ let run_session = Arc :: clone ( & run_session) ;
204+ move |params, context| run:: run_action_function ( & run_session, params, context)
205+ } ) ?;
206+ backend. function ( RERUN_FUNCTION_ID , {
207+ let run_session = Arc :: clone ( & run_session) ;
208+ move |params, context| run:: rerun_function ( & run_session, params, context)
125209 } ) ?;
210+ backend. function ( RESOLVE_LINK_FUNCTION_ID , run:: resolve_output_link_function) ?;
211+ backend. suppress_success_diagnostics ( RESOLVE_LINK_FUNCTION_ID ) ?;
126212 Ok ( backend)
127213}
128214
@@ -263,9 +349,9 @@ mod tests {
263349 . all( |code| lithe_plugin_sdk:: is_plugin_error_code( code) ) ) ;
264350 }
265351
266- /// An error code names one cause. The codes `settingsChanged` answers
267- /// with, the domain codes and the diagnostics categories of the settings
268- /// modules must never share a name.
352+ /// An error code names one cause. The codes `settingsChanged` and
353+ /// `java.resolveLaunch` answer with, the domain codes and the diagnostics
354+ /// categories of the settings and launch modules must never share a name.
269355 #[ test]
270356 fn settings_relay_codes_never_share_a_name_with_another_code ( ) {
271357 let domain: Vec < & str > = [
@@ -290,6 +376,10 @@ mod tests {
290376 . iter ( )
291377 . chain ( settings_session:: SESSION_CATEGORIES )
292378 . chain ( plugin_functions:: RELAY_CATEGORIES )
379+ . chain ( launch:: LAUNCH_ERROR_CODES )
380+ . chain ( launch:: LAUNCH_CATEGORIES )
381+ . chain ( run:: RUN_ERROR_CODES )
382+ . chain ( run:: RUN_CATEGORIES )
293383 {
294384 assert ! ( seen. insert( * name) , "{name} names two causes" ) ;
295385 }
@@ -309,12 +399,19 @@ mod tests {
309399
310400 #[ test]
311401 fn key_operations_are_registered_functions_without_duplicates ( ) {
312- // The commands, and the one function registered next to them.
402+ // The commands, and the functions registered next to them.
313403 let commands: std:: collections:: BTreeSet < & str > = SUPPORTED_COMMANDS
314404 . iter ( )
315405 . chain ( SESSION_COMMANDS )
316406 . copied ( )
317- . chain ( [ SETTINGS_CHANGED_FUNCTION_ID ] )
407+ . chain ( [
408+ SETTINGS_CHANGED_FUNCTION_ID ,
409+ LAUNCH_FUNCTION_ID ,
410+ COLLECT_FUNCTION_ID ,
411+ RUN_ACTION_FUNCTION_ID ,
412+ RERUN_FUNCTION_ID ,
413+ RESOLVE_LINK_FUNCTION_ID ,
414+ ] )
318415 . collect ( ) ;
319416 let distinct: std:: collections:: BTreeSet < & str > = KEY_OPERATIONS . iter ( ) . copied ( ) . collect ( ) ;
320417 assert_eq ! (
0 commit comments