Validate actions in docs (#31073)
Adds a validation step to docs preprocessing so that actions referenced
in docs are checked against the list of all registered actions in GPUI.
In order for this to work properly, all of the crates that register
actions had to be importable by the `docs_preprocessor` crate and
actually used (see [this
comment](ec16e70336 (diff-2674caf14ae6d70752ea60c7061232393d84e7f61a52915ace089c30a797a1c3)
)
for why this is challenging).
In order to accomplish this I have moved the entry point of zed into a
separate stub file named `zed_main.rs` so that `main.rs` is importable
by the `docs_preprocessor` crate, this is kind of gross, but ensures
that all actions that are registered in the application are registered
when checking them in `docs_preprocessor`. An alternative solution
suggested by @mikayla-maki was to separate out all our `::init()`
functions into a lib entry point in the `zed` crate that can be imported
instead, however, this turned out to be a far bigger refactor and is in
my opinion better to do in a follow up PR with significant testing to
ensure no regressions in behavior occur.
Release Notes:
- N/A
This commit is contained in:
parent
52770cd3ad
commit
17c3b741ec
14 changed files with 216 additions and 48 deletions
|
@ -12,6 +12,10 @@ workspace = true
|
|||
|
||||
[[bin]]
|
||||
name = "zed"
|
||||
path = "src/zed-main.rs"
|
||||
|
||||
[lib]
|
||||
name = "zed"
|
||||
path = "src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
|
|
|
@ -163,7 +163,7 @@ fn fail_to_open_window(e: anyhow::Error, _cx: &mut App) {
|
|||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
pub fn main() {
|
||||
#[cfg(unix)]
|
||||
{
|
||||
let is_root = nix::unistd::geteuid().is_root();
|
||||
|
@ -199,6 +199,11 @@ Error: Running Zed as root or via sudo is unsupported.
|
|||
return;
|
||||
}
|
||||
|
||||
if args.dump_all_actions {
|
||||
dump_all_gpui_actions();
|
||||
return;
|
||||
}
|
||||
|
||||
// Set custom data directory.
|
||||
if let Some(dir) = &args.user_data_dir {
|
||||
paths::set_custom_data_dir(dir);
|
||||
|
@ -213,9 +218,6 @@ Error: Running Zed as root or via sudo is unsupported.
|
|||
}
|
||||
}
|
||||
|
||||
menu::init();
|
||||
zed_actions::init();
|
||||
|
||||
let file_errors = init_paths();
|
||||
if !file_errors.is_empty() {
|
||||
files_not_created_on_launch(file_errors);
|
||||
|
@ -356,6 +358,9 @@ Error: Running Zed as root or via sudo is unsupported.
|
|||
});
|
||||
|
||||
app.run(move |cx| {
|
||||
menu::init();
|
||||
zed_actions::init();
|
||||
|
||||
release_channel::init(app_version, cx);
|
||||
gpui_tokio::init(cx);
|
||||
if let Some(app_commit_sha) = app_commit_sha {
|
||||
|
@ -1018,7 +1023,7 @@ fn init_paths() -> HashMap<io::ErrorKind, Vec<&'static Path>> {
|
|||
})
|
||||
}
|
||||
|
||||
fn stdout_is_a_pty() -> bool {
|
||||
pub fn stdout_is_a_pty() -> bool {
|
||||
std::env::var(FORCE_CLI_MODE_ENV_VAR_NAME).ok().is_none() && io::stdout().is_terminal()
|
||||
}
|
||||
|
||||
|
@ -1055,7 +1060,7 @@ struct Args {
|
|||
#[arg(long, hide = true)]
|
||||
askpass: Option<String>,
|
||||
|
||||
/// Run zed in the foreground, only used on Windows, to match the behavior of the behavior on macOS.
|
||||
/// Run zed in the foreground, only used on Windows, to match the behavior on macOS.
|
||||
#[arg(long)]
|
||||
#[cfg(target_os = "windows")]
|
||||
#[arg(hide = true)]
|
||||
|
@ -1066,6 +1071,9 @@ struct Args {
|
|||
#[cfg(target_os = "windows")]
|
||||
#[arg(hide = true)]
|
||||
dock_action: Option<usize>,
|
||||
|
||||
#[arg(long, hide = true)]
|
||||
dump_all_actions: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
|
@ -1278,3 +1286,28 @@ fn watch_languages(fs: Arc<dyn fs::Fs>, languages: Arc<LanguageRegistry>, cx: &m
|
|||
|
||||
#[cfg(not(debug_assertions))]
|
||||
fn watch_languages(_fs: Arc<dyn fs::Fs>, _languages: Arc<LanguageRegistry>, _cx: &mut App) {}
|
||||
|
||||
fn dump_all_gpui_actions() {
|
||||
#[derive(Debug, serde::Serialize)]
|
||||
struct ActionDef {
|
||||
name: &'static str,
|
||||
human_name: String,
|
||||
aliases: &'static [&'static str],
|
||||
}
|
||||
let mut actions = gpui::generate_list_of_all_registered_actions()
|
||||
.into_iter()
|
||||
.map(|action| ActionDef {
|
||||
name: action.name,
|
||||
human_name: command_palette::humanize_action_name(action.name),
|
||||
aliases: action.aliases,
|
||||
})
|
||||
.collect::<Vec<ActionDef>>();
|
||||
|
||||
actions.sort_by_key(|a| a.name);
|
||||
|
||||
io::Write::write(
|
||||
&mut std::io::stdout(),
|
||||
serde_json::to_string_pretty(&actions).unwrap().as_bytes(),
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
|
5
crates/zed/src/zed-main.rs
Normal file
5
crates/zed/src/zed-main.rs
Normal file
|
@ -0,0 +1,5 @@
|
|||
pub fn main() {
|
||||
// separated out so that the file containing the main function can be imported by other crates,
|
||||
// while having all gpui resources that are registered in main (primarily actions) initialized
|
||||
zed::main();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue