The diff in this comment:
pub fn find_and_load(
start_dir: &Path,
) -> Result<Option<(PathBuf, Self)>, LoadWorkspaceYamlError> {
- let Some(path) = find_workspace_manifest(start_dir) else {
- return Ok(None);
- };
-
- let read_result = fs::read_to_string(&path);
-
- // TOCTOU: `find_workspace_manifest` checked `is_file()`, but
- // the file may be removed before this read. Match pnpm and
- // treat `ENOENT` during the read as "no manifest" too.
- if let Err(error) = &read_result
- && error.kind() == ErrorKind::NotFound
- {
- return Ok(None);
- }
-
- let settings: WorkspaceSettings = read_result
- .map_err(|source| LoadWorkspaceYamlError::ReadFile { path: path.clone(), source })?
- .pipe_as_ref(serde_saphyr::from_str)
- .map_err(Box::new)
- .map_err(|source| LoadWorkspaceYamlError::ParseYaml { path: path.clone(), source })?;
-
- Ok(Some((path, settings)))
+ let mut cursor = Some(start_dir);
+ while let Some(dir) = cursor {
+ let path = dir.join(WORKSPACE_MANIFEST_FILENAME);
+ let read_result = fs::read_to_string(&path);
+
+ if let Err(error) = &read_result
+ && error.kind() == ErrorKind::NotFound
+ {
+ cursor = dir.parent();
+ continue;
+ }
+
+ let settings: WorkspaceSettings = read_result
+ .map_err(|source| LoadWorkspaceYamlError::ReadFile { path: path.clone(), source })?
+ .pipe_as_ref(serde_saphyr::from_str)
+ .map_err(Box::new)
+ .map_err(|source| LoadWorkspaceYamlError::ParseYaml { path: path.clone(), source })?;
+
+ return Ok(Some((path, settings)));
+ }
+
+ Ok(None)
}
Neither git apply nor patch can use it.
Suggestion
Use git diff to generate the code suggestions.
The diff in this comment:
pub fn find_and_load( start_dir: &Path, ) -> Result<Option<(PathBuf, Self)>, LoadWorkspaceYamlError> { - let Some(path) = find_workspace_manifest(start_dir) else { - return Ok(None); - }; - - let read_result = fs::read_to_string(&path); - - // TOCTOU: `find_workspace_manifest` checked `is_file()`, but - // the file may be removed before this read. Match pnpm and - // treat `ENOENT` during the read as "no manifest" too. - if let Err(error) = &read_result - && error.kind() == ErrorKind::NotFound - { - return Ok(None); - } - - let settings: WorkspaceSettings = read_result - .map_err(|source| LoadWorkspaceYamlError::ReadFile { path: path.clone(), source })? - .pipe_as_ref(serde_saphyr::from_str) - .map_err(Box::new) - .map_err(|source| LoadWorkspaceYamlError::ParseYaml { path: path.clone(), source })?; - - Ok(Some((path, settings))) + let mut cursor = Some(start_dir); + while let Some(dir) = cursor { + let path = dir.join(WORKSPACE_MANIFEST_FILENAME); + let read_result = fs::read_to_string(&path); + + if let Err(error) = &read_result + && error.kind() == ErrorKind::NotFound + { + cursor = dir.parent(); + continue; + } + + let settings: WorkspaceSettings = read_result + .map_err(|source| LoadWorkspaceYamlError::ReadFile { path: path.clone(), source })? + .pipe_as_ref(serde_saphyr::from_str) + .map_err(Box::new) + .map_err(|source| LoadWorkspaceYamlError::ParseYaml { path: path.clone(), source })?; + + return Ok(Some((path, settings))); + } + + Ok(None) }Neither
git applynorpatchcan use it.Suggestion
Use
git diffto generate the code suggestions.