code_moniker_workspace/registry/
local.rs1use std::path::PathBuf;
4
5use crate::changes::LocalChangeOverlay;
6use crate::code::{LocalCodeIndex, LocalCodeIndexOptions};
7use crate::linkage::LocalLinkage;
8use crate::source::{
9 LocalIdentityResolver, LocalResourceCache, LocalSourceCatalog, LocalSourceCatalogOptions,
10};
11
12use super::{WorkspacePorts, WorkspaceRegistry};
13
14pub type LocalWorkspaceRegistry = WorkspaceRegistry;
15
16#[derive(Clone, Debug, Eq, PartialEq)]
17pub struct LocalWorkspaceOptions {
18 pub paths: Vec<PathBuf>,
19 pub project: Option<String>,
20 pub cache_dir: Option<PathBuf>,
21 pub files: Option<Vec<PathBuf>>,
22 pub identity: LocalIdentityResolver,
23 pub detailed_telemetry: bool,
24}
25
26impl LocalWorkspaceOptions {
27 pub fn new(paths: Vec<PathBuf>, project: Option<String>) -> Self {
28 Self {
29 paths,
30 project,
31 cache_dir: None,
32 files: None,
33 identity: LocalIdentityResolver::default(),
34 detailed_telemetry: false,
35 }
36 }
37
38 pub fn with_cache_dir(mut self, cache_dir: Option<PathBuf>) -> Self {
39 self.cache_dir = cache_dir;
40 self
41 }
42
43 pub fn with_files(mut self, files: Vec<PathBuf>) -> Self {
44 self.files = Some(files);
45 self
46 }
47
48 pub fn with_identity(mut self, identity: LocalIdentityResolver) -> Self {
49 self.identity = identity;
50 self
51 }
52
53 pub fn with_detailed_telemetry(mut self, enabled: bool) -> Self {
54 self.detailed_telemetry = enabled;
55 self
56 }
57}
58
59impl LocalWorkspaceRegistry {
60 pub fn local(options: LocalWorkspaceOptions) -> Self {
61 Self::local_with_cache(options, LocalResourceCache::default())
62 }
63
64 pub fn local_with_cache(options: LocalWorkspaceOptions, cache: LocalResourceCache) -> Self {
65 Self::new(local_workspace_ports(options, cache))
66 }
67}
68
69pub(crate) fn local_workspace_ports(
70 options: LocalWorkspaceOptions,
71 cache: LocalResourceCache,
72) -> WorkspacePorts {
73 let watch_paths = options.paths.clone();
74 let watch_cache_dir = options.cache_dir.clone();
75 let mut source_options = LocalSourceCatalogOptions::new(options.paths, options.project)
76 .with_identity(options.identity);
77 if let Some(files) = options.files {
78 source_options = source_options.with_files(files);
79 }
80 WorkspacePorts::new(
81 LocalSourceCatalog::new(source_options, cache.clone()),
82 LocalCodeIndex::new(
83 LocalCodeIndexOptions::new(options.cache_dir)
84 .with_detailed_telemetry(options.detailed_telemetry),
85 cache.clone(),
86 ),
87 LocalLinkage::new(cache.clone()),
88 LocalChangeOverlay::new(cache),
89 )
90 .with_live_watch_roots(move |_| {
91 crate::live::watch_roots_for_paths(&watch_paths, watch_cache_dir.as_deref())
92 })
93}