autoload: improve enum naming

This commit is contained in:
Johannes Altmanninger
2026-04-28 21:18:24 +08:00
parent ab2678082e
commit 319b093ef8

View File

@@ -54,8 +54,8 @@ enum AssetDir {
#[derive(Debug)]
pub enum AutoloadPath {
OnDisk(WString),
Embedded(String),
Path(WString),
}
#[derive(Debug)]
@@ -102,10 +102,7 @@ pub fn resolve_command(&mut self, cmd: &wstr, env: &dyn Environment) -> Autoload
.unwrap_or_default(),
);
match result {
AutoloadResult::Path(AutoloadPath::Embedded(_)) => {
flogf!(autoload, "Embedded: %s", cmd);
}
AutoloadResult::Path(AutoloadPath::Path(ref path)) => {
AutoloadResult::Path(AutoloadPath::OnDisk(ref path)) => {
flogf!(
autoload,
"Loading %s from var %s from path %s",
@@ -114,6 +111,9 @@ pub fn resolve_command(&mut self, cmd: &wstr, env: &dyn Environment) -> Autoload
path
);
}
AutoloadResult::Path(AutoloadPath::Embedded(_)) => {
flogf!(autoload, "Embedded: %s", cmd);
}
AutoloadResult::Loaded | AutoloadResult::Pending | AutoloadResult::None => {}
}
result
@@ -129,7 +129,7 @@ pub fn perform_autoload(path: &AutoloadPath, parser: &Parser) {
let prev_statuses = parser.get_last_statuses();
let _put_back = ScopeGuard::new((), |()| parser.set_last_statuses(prev_statuses));
match path {
AutoloadPath::Path(p) => {
AutoloadPath::OnDisk(p) => {
let script_source = L!("source ").to_owned() + &escape(p)[..];
parser.eval(&script_source, &IoChain::new());
}
@@ -219,8 +219,8 @@ fn resolve_command_impl(&mut self, cmd: &wstr, paths: &[WString]) -> AutoloadRes
};
let file_id = match &file {
AutoloadableFileInfo::FileInfo(file) => &file.file_id,
AutoloadableFileInfo::EmbeddedPath(_) => &INVALID_FILE_ID,
AutoloadableFileInfo::OnDisk { file_id, .. } => file_id,
AutoloadableFileInfo::Embedded { .. } => &INVALID_FILE_ID,
};
// Is this file the same as what we previously autoloaded?
@@ -236,8 +236,8 @@ fn resolve_command_impl(&mut self, cmd: &wstr, paths: &[WString]) -> AutoloadRes
self.autoloaded_files
.insert(cmd.to_owned(), file_id.clone());
AutoloadResult::Path(match file {
AutoloadableFileInfo::FileInfo(path) => AutoloadPath::Path(path.path),
AutoloadableFileInfo::EmbeddedPath(path) => AutoloadPath::Embedded(path),
AutoloadableFileInfo::OnDisk { path, .. } => AutoloadPath::OnDisk(path),
AutoloadableFileInfo::Embedded { path } => AutoloadPath::Embedded(path),
})
}
}
@@ -246,20 +246,12 @@ fn resolve_command_impl(&mut self, cmd: &wstr, paths: &[WString]) -> AutoloadRes
const AUTOLOAD_STALENESS_INTERVALL: u64 = 15;
/// Represents a file that we might want to autoload.
#[derive(Clone)]
struct FileInfo {
/// The path to the file.
path: WString,
/// The metadata for the file.
file_id: FileId,
}
#[derive(Clone)]
enum AutoloadableFileInfo {
/// An on-disk file.
FileInfo(FileInfo),
OnDisk { path: WString, file_id: FileId },
/// An embedded file.
EmbeddedPath(String),
Embedded { path: String },
}
// A timestamp is a monotonic point in time.
@@ -329,7 +321,7 @@ fn check(
// Check hits.
if let Some(value) = self.known_files.get(cmd) {
let embedded = matches!(value.file, AutoloadableFileInfo::EmbeddedPath(_));
let embedded = matches!(value.file, AutoloadableFileInfo::Embedded { .. });
if allow_stale
|| embedded
|| Self::is_fresh(value.last_checked, Self::current_timestamp())
@@ -431,7 +423,7 @@ fn locate_file(
let file_id = file_id_for_path(&path);
if file_id != INVALID_FILE_ID {
// Found it.
return Some(AutoloadableFileInfo::FileInfo(FileInfo { path, file_id }));
return Some(AutoloadableFileInfo::OnDisk { path, file_id });
}
}
None
@@ -445,11 +437,11 @@ fn locate_asset(&self, cmd: &wstr, asset_dir: AssetDir) -> Option<AutoloadableFi
}
let narrow = wcs2bytes(cmd);
let cmdstr = std::str::from_utf8(&narrow).ok()?;
let p = match asset_dir {
let path = match asset_dir {
AssetDir::Functions => "functions/".to_owned() + cmdstr + ".fish",
AssetDir::Completions => "completions/".to_owned() + cmdstr + ".fish",
};
has_asset(&p).then_some(AutoloadableFileInfo::EmbeddedPath(p))
has_asset(&path).then_some(AutoloadableFileInfo::Embedded { path })
}
}