From 0b1c27956bbca515bd4848f0308015e5454f4e6b Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Mon, 13 Dec 2021 17:44:15 -0800 Subject: [PATCH] Add Project::open_buffer method --- crates/project/src/project.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/crates/project/src/project.rs b/crates/project/src/project.rs index 78c59404a6..cd3f09c98b 100644 --- a/crates/project/src/project.rs +++ b/crates/project/src/project.rs @@ -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, + ) -> Task>> { + 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,