react-code-dataset
/
next.js
/turbopack
/crates
/turbopack-dev-server
/src
/source
/issue_context.rs
| use anyhow::Result; | |
| use turbo_rcstr::{RcStr, rcstr}; | |
| use turbo_tasks::{ResolvedVc, Vc}; | |
| use turbo_tasks_fs::FileSystemPath; | |
| use turbopack_core::{ | |
| introspect::{Introspectable, IntrospectableChildren}, | |
| issue::IssueDescriptionExt, | |
| }; | |
| use super::{ | |
| ContentSource, ContentSourceContent, ContentSourceData, ContentSourceDataVary, ContentSources, | |
| GetContentSourceContent, | |
| route_tree::{MapGetContentSourceContent, RouteTree}, | |
| }; | |
| pub struct IssueFilePathContentSource { | |
| file_path: Option<FileSystemPath>, | |
| description: RcStr, | |
| source: ResolvedVc<Box<dyn ContentSource>>, | |
| } | |
| impl IssueFilePathContentSource { | |
| pub fn new_file_path( | |
| file_path: FileSystemPath, | |
| description: RcStr, | |
| source: ResolvedVc<Box<dyn ContentSource>>, | |
| ) -> Vc<Self> { | |
| IssueFilePathContentSource { | |
| file_path: Some(file_path), | |
| description, | |
| source, | |
| } | |
| .cell() | |
| } | |
| pub fn new_description( | |
| description: RcStr, | |
| source: ResolvedVc<Box<dyn ContentSource>>, | |
| ) -> Vc<Self> { | |
| IssueFilePathContentSource { | |
| file_path: None, | |
| description, | |
| source, | |
| } | |
| .cell() | |
| } | |
| } | |
| impl ContentSource for IssueFilePathContentSource { | |
| async fn get_routes(self: ResolvedVc<Self>) -> Result<Vc<RouteTree>> { | |
| let this = self.await?; | |
| let routes = content_source_get_routes_operation(this.source) | |
| .issue_file_path(this.file_path.clone(), &*this.description) | |
| .await? | |
| .connect(); | |
| Ok(routes.map_routes(Vc::upcast( | |
| IssueContextContentSourceMapper { source: self }.cell(), | |
| ))) | |
| } | |
| fn get_children(&self) -> Vc<ContentSources> { | |
| Vc::cell(vec![self.source]) | |
| } | |
| } | |
| fn content_source_get_routes_operation( | |
| source: ResolvedVc<Box<dyn ContentSource>>, | |
| ) -> Vc<RouteTree> { | |
| source.get_routes() | |
| } | |
| struct IssueContextContentSourceMapper { | |
| source: ResolvedVc<IssueFilePathContentSource>, | |
| } | |
| impl MapGetContentSourceContent for IssueContextContentSourceMapper { | |
| fn map_get_content( | |
| &self, | |
| get_content: ResolvedVc<Box<dyn GetContentSourceContent>>, | |
| ) -> Vc<Box<dyn GetContentSourceContent>> { | |
| Vc::upcast( | |
| IssueContextGetContentSourceContent { | |
| get_content, | |
| source: self.source, | |
| } | |
| .cell(), | |
| ) | |
| } | |
| } | |
| struct IssueContextGetContentSourceContent { | |
| get_content: ResolvedVc<Box<dyn GetContentSourceContent>>, | |
| source: ResolvedVc<IssueFilePathContentSource>, | |
| } | |
| impl GetContentSourceContent for IssueContextGetContentSourceContent { | |
| async fn vary(&self) -> Result<Vc<ContentSourceDataVary>> { | |
| let source = self.source.await?; | |
| Ok(get_content_source_vary_operation(self.get_content) | |
| .issue_file_path(source.file_path.clone(), &*source.description) | |
| .await? | |
| .connect()) | |
| } | |
| async fn get(&self, path: RcStr, data: ContentSourceData) -> Result<Vc<ContentSourceContent>> { | |
| let source = self.source.await?; | |
| Ok( | |
| get_content_source_get_operation(self.get_content, path, data) | |
| .issue_file_path(source.file_path.clone(), &*source.description) | |
| .await? | |
| .connect(), | |
| ) | |
| } | |
| } | |
| fn get_content_source_vary_operation( | |
| get_content: ResolvedVc<Box<dyn GetContentSourceContent>>, | |
| ) -> Vc<ContentSourceDataVary> { | |
| get_content.vary() | |
| } | |
| fn get_content_source_get_operation( | |
| get_content: ResolvedVc<Box<dyn GetContentSourceContent>>, | |
| path: RcStr, | |
| data: ContentSourceData, | |
| ) -> Vc<ContentSourceContent> { | |
| get_content.get(path, data) | |
| } | |
| impl Introspectable for IssueFilePathContentSource { | |
| fn ty(&self) -> Result<Vc<RcStr>> { | |
| Ok( | |
| if let Some(source) = ResolvedVc::try_sidecast::<Box<dyn Introspectable>>(self.source) { | |
| source.ty() | |
| } else { | |
| Vc::cell(rcstr!("IssueContextContentSource")) | |
| }, | |
| ) | |
| } | |
| async fn title(&self) -> Result<Vc<RcStr>> { | |
| Ok( | |
| if let Some(source) = ResolvedVc::try_sidecast::<Box<dyn Introspectable>>(self.source) { | |
| let title = source.title().await?; | |
| Vc::cell(format!("{}: {}", self.description, title).into()) | |
| } else { | |
| Vc::cell(self.description.clone()) | |
| }, | |
| ) | |
| } | |
| fn details(&self) -> Result<Vc<RcStr>> { | |
| Ok( | |
| if let Some(source) = ResolvedVc::try_sidecast::<Box<dyn Introspectable>>(self.source) { | |
| source.details() | |
| } else { | |
| Vc::cell(RcStr::default()) | |
| }, | |
| ) | |
| } | |
| fn children(&self) -> Result<Vc<IntrospectableChildren>> { | |
| Ok( | |
| if let Some(source) = ResolvedVc::try_sidecast::<Box<dyn Introspectable>>(self.source) { | |
| source.children() | |
| } else { | |
| Vc::cell(Default::default()) | |
| }, | |
| ) | |
| } | |
| } | |