Add Project::open_buffer method

This commit is contained in:
Max Brunsfeld 2021-12-13 17:44:15 -08:00
parent fe571f1d70
commit 0b1c27956b

View file

@ -2,13 +2,13 @@ pub mod fs;
mod ignore;
mod worktree;
use anyhow::Result;
use anyhow::{anyhow, Result};
use client::{Client, UserStore};
use clock::ReplicaId;
use futures::Future;
use fuzzy::{PathMatch, PathMatchCandidate, PathMatchCandidateSet};
use gpui::{AppContext, Entity, ModelContext, ModelHandle, Task};
use language::{DiagnosticEntry, LanguageRegistry};
use language::{Buffer, DiagnosticEntry, LanguageRegistry};
use lsp::DiagnosticSeverity;
use std::{
path::Path,
@ -113,6 +113,18 @@ impl Project {
.cloned()
}
pub fn open_buffer(
&self,
path: ProjectPath,
cx: &mut ModelContext<Self>,
) -> Task<Result<ModelHandle<Buffer>>> {
if let Some(worktree) = self.worktree_for_id(path.worktree_id) {
worktree.update(cx, |worktree, cx| worktree.open_buffer(path.path, cx))
} else {
cx.spawn(|_, _| async move { Err(anyhow!("no such worktree")) })
}
}
pub fn add_local_worktree(
&mut self,
abs_path: &Path,