Skip to main content

Mountain/Track/Effect/CreateEffectForRequest/
mod.rs

1//! # CreateEffectForRequest (Track)
2//!
3//! Central routing table that maps string-based commands/RPC methods to typed
4//! effects ([`MappedEffect`]). Each domain module handles its own match arms
5//! and returns `None` for unrecognised methods, enabling the chain-of-
6//! responsibility pattern below.
7//!
8//! ## Domain modules
9//!
10//! | Module            | Commands handled                                         |
11//! |-------------------|----------------------------------------------------------|
12//! | Authentication    | `Authentication.GetSession`, `Authentication.GetAccounts`|
13//! | Clipboard         | `Clipboard.Read`, `Clipboard.Write`                      |
14//! | Commands          | `executeCommand`, `Command.Execute`, `Command.GetAll`    |
15//! | Configuration     | `config.get`, `config.update`, `Configuration.*`        |
16//! | Debug             | `Debug.Start`, `Debug.RegisterConfigurationProvider`, `Debug.Stop` |
17//! | Diagnostics       | `Diagnostic.Set`, `Diagnostic.Clear`                    |
18//! | Documents         | `Document.Save`, `Document.SaveAs`                      |
19//! | FileSystem        | `FileSystem.*`, `FileWatcher.*`, `openDocument` aliases  |
20//! | Git               | `$gitExec`                                               |
21//! | Keybinding        | `Keybinding.GetResolved`                                 |
22//! | LanguageFeatures  | `register_*_provider` (one arm per provider type)        |
23//! | Languages         | `Languages.GetAll`                                       |
24//! | NativeHost        | `NativeHost.OpenExternal`                                |
25//! | SCM               | `$scm:*`, `vscode.diff`, `$scm:openDiff`                 |
26//! | Search            | `findFiles`, `findTextInFiles`, `Search.TextSearch`      |
27//! | Secrets           | `secrets.get`, `secrets.store`, `secrets.delete`        |
28//! | StatusBar         | `$statusBar:*`, `$setStatusBarMessage`, `$disposeStatusBarMessage` |
29//! | Storage           | `Storage.Get`, `Storage.Set`                             |
30//! | Task              | `Task.Fetch`, `Task.Execute`                             |
31//! | Terminal          | `$terminal:*`, `Terminal.*`                              |
32//! | TreeView          | `$tree:register`, `tree.*`                               |
33//! | UserInterface     | `UserInterface.*`, `Window.*`                            |
34//! | Webview           | `$webview:*`, `webview.*`, `$resolveCustomEditor`        |
35//! | Workspace         | `applyEdit`, `showTextDocument`, `$updateWorkspaceFolders` |
36
37pub mod Utilities;
38
39pub mod Authentication;
40
41pub mod Clipboard;
42
43pub mod Commands;
44
45pub mod Configuration;
46
47pub mod Debug;
48
49pub mod Diagnostics;
50
51pub mod Documents;
52
53pub mod FileReadAlias;
54
55pub mod FileSystem;
56
57pub mod FileWatcher;
58
59pub mod Git;
60
61pub mod Keybinding;
62
63pub mod LanguageFeatures;
64
65pub mod Languages;
66
67pub mod NativeHost;
68
69pub mod SCM;
70
71pub mod Search;
72
73pub mod Secrets;
74
75pub mod StatusBar;
76
77pub mod Storage;
78
79pub mod Task;
80
81pub mod Terminal;
82
83pub mod TreeView;
84
85pub mod UserInterface;
86
87pub mod Webview;
88
89pub mod WindowUI;
90
91pub mod Workspace;
92
93use serde_json::Value;
94use tauri::{AppHandle, Runtime};
95
96use crate::Track::Effect::MappedEffectType::MappedEffect;
97
98/// Maps a string-based method name (command or RPC) to its corresponding effect
99/// constructor, returning a boxed closure ([`MappedEffect`]) that can be
100/// executed by the ApplicationRunTime.
101///
102/// Delegates to domain modules in priority order. The first module that returns
103/// `Some(result)` wins; unknown methods fall through to an error.
104pub fn Fn<R:Runtime>(
105	_ApplicationHandle:&AppHandle<R>,
106
107	MethodName:&str,
108
109	Parameters:Value,
110) -> Result<MappedEffect, String> {
111	macro_rules! Try {
112		($Module:ident) => {
113			if let Some(Result) = $Module::CreateEffect::<R>(MethodName, Parameters.clone()) {
114				return Result;
115			}
116		};
117	}
118
119	Try!(Commands);
120
121	Try!(Configuration);
122
123	Try!(Diagnostics);
124
125	Try!(Documents);
126
127	Try!(FileReadAlias);
128
129	Try!(FileSystem);
130
131	Try!(FileWatcher);
132
133	Try!(Keybinding);
134
135	Try!(LanguageFeatures);
136
137	Try!(Languages);
138
139	Try!(Search);
140
141	Try!(Storage);
142
143	Try!(StatusBar);
144
145	Try!(Terminal);
146
147	Try!(TreeView);
148
149	Try!(UserInterface);
150
151	Try!(WindowUI);
152
153	Try!(Webview);
154
155	Try!(Debug);
156
157	Try!(SCM);
158
159	Try!(Workspace);
160
161	Try!(Secrets);
162
163	Try!(Clipboard);
164
165	Try!(NativeHost);
166
167	Try!(Git);
168
169	Try!(Task);
170
171	Try!(Authentication);
172
173	crate::dev_log!("ipc", "warn: [EffectCreation] Unknown method: {}", MethodName);
174
175	Err(format!("Unknown method: {}", MethodName))
176}