mirror of
https://github.com/zed-industries/zed.git
synced 2025-02-11 12:46:07 +00:00
Add Project::open_buffer method
This commit is contained in:
parent
fe571f1d70
commit
0b1c27956b
1 changed files with 14 additions and 2 deletions
|
@ -2,13 +2,13 @@ pub mod fs;
|
||||||
mod ignore;
|
mod ignore;
|
||||||
mod worktree;
|
mod worktree;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::{anyhow, Result};
|
||||||
use client::{Client, UserStore};
|
use client::{Client, UserStore};
|
||||||
use clock::ReplicaId;
|
use clock::ReplicaId;
|
||||||
use futures::Future;
|
use futures::Future;
|
||||||
use fuzzy::{PathMatch, PathMatchCandidate, PathMatchCandidateSet};
|
use fuzzy::{PathMatch, PathMatchCandidate, PathMatchCandidateSet};
|
||||||
use gpui::{AppContext, Entity, ModelContext, ModelHandle, Task};
|
use gpui::{AppContext, Entity, ModelContext, ModelHandle, Task};
|
||||||
use language::{DiagnosticEntry, LanguageRegistry};
|
use language::{Buffer, DiagnosticEntry, LanguageRegistry};
|
||||||
use lsp::DiagnosticSeverity;
|
use lsp::DiagnosticSeverity;
|
||||||
use std::{
|
use std::{
|
||||||
path::Path,
|
path::Path,
|
||||||
|
@ -113,6 +113,18 @@ impl Project {
|
||||||
.cloned()
|
.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(
|
pub fn add_local_worktree(
|
||||||
&mut self,
|
&mut self,
|
||||||
abs_path: &Path,
|
abs_path: &Path,
|
||||||
|
|
Loading…
Reference in a new issue