Start on adding support for editing via the assistant panel (#14795)

Note that this shouldn't have any visible user-facing behavior yet. The
feature is incomplete but we wanna merge early to avoid a long-running
branch.

Release Notes:

- N/A

---------

Co-authored-by: Nathan <nathan@zed.dev>
This commit is contained in:
Antonio Scandurra 2024-07-19 11:13:15 +02:00 committed by GitHub
parent 87457f9ae8
commit 4d177918c1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
44 changed files with 1999 additions and 968 deletions

View file

@ -8403,6 +8403,37 @@ impl Project {
})
}
/// Attempts to find a `ProjectPath` corresponding to the given full path.
///
/// This method iterates through all worktrees in the project, trying to match
/// the given full path against each worktree's root name. If a match is found,
/// it returns a `ProjectPath` containing the worktree ID and the relative path
/// within that worktree.
///
/// # Arguments
///
/// * `full_path` - A reference to a `Path` representing the full path to resolve.
/// * `cx` - A reference to the `AppContext`.
///
/// # Returns
///
/// Returns `Some(ProjectPath)` if a matching worktree is found, otherwise `None`.
pub fn project_path_for_full_path(
&self,
full_path: &Path,
cx: &AppContext,
) -> Option<ProjectPath> {
self.worktrees.iter().find_map(|worktree| {
let worktree = worktree.upgrade()?;
let worktree_root_name = worktree.read(cx).root_name();
let relative_path = full_path.strip_prefix(worktree_root_name).ok()?;
Some(ProjectPath {
worktree_id: worktree.read(cx).id(),
path: relative_path.into(),
})
})
}
pub fn get_workspace_root(
&self,
project_path: &ProjectPath,