Skip to main content

code_moniker_workspace/registry/
command.rs

1use std::sync::Arc;
2
3use crate::snapshot::{WorkspaceRequest, WorkspaceSnapshot};
4
5#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
6pub struct WorkspaceCommandId(u64);
7
8impl WorkspaceCommandId {
9	pub fn new(value: u64) -> Self {
10		Self(value)
11	}
12
13	pub fn value(self) -> u64 {
14		self.0
15	}
16}
17
18#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
19pub struct WorkspaceScopeUri(String);
20
21impl WorkspaceScopeUri {
22	pub fn new(value: impl Into<String>) -> Self {
23		Self(value.into())
24	}
25
26	pub fn workspace() -> Self {
27		Self(format!("{}./", crate::DEFAULT_IDENTITY_SCHEME))
28	}
29
30	pub fn as_str(&self) -> &str {
31		&self.0
32	}
33}
34
35#[derive(Clone, Copy, Debug, Eq, PartialEq)]
36pub enum WorkspaceCommandKind {
37	LoadSources,
38	BuildIndex,
39	ResolveLinkage,
40	PublishSnapshot,
41	RefreshPaths,
42	RefreshChanges,
43	RefreshLivePlan,
44	Refresh,
45	RefreshStale,
46}
47
48#[derive(Clone, Debug, Eq, PartialEq)]
49pub struct WorkspaceCommand {
50	pub id: WorkspaceCommandId,
51	pub scope_uri: WorkspaceScopeUri,
52	pub kind: WorkspaceCommandKind,
53	pub request: WorkspaceRequest,
54}
55
56#[derive(Clone, Debug, Eq, PartialEq)]
57pub struct WorkspaceCommandSpec {
58	pub scope_uri: WorkspaceScopeUri,
59	pub kind: WorkspaceCommandKind,
60	pub request: WorkspaceRequest,
61}
62
63#[derive(Clone, Debug, Eq, PartialEq)]
64pub struct WorkspaceSnapshotPublication {
65	pub scope_uri: WorkspaceScopeUri,
66	pub request: WorkspaceRequest,
67	pub snapshot: Arc<WorkspaceSnapshot>,
68}
69
70impl WorkspaceCommandSpec {
71	pub fn new(
72		kind: WorkspaceCommandKind,
73		scope_uri: WorkspaceScopeUri,
74		request: WorkspaceRequest,
75	) -> Self {
76		Self {
77			scope_uri,
78			kind,
79			request,
80		}
81	}
82}
83
84impl WorkspaceSnapshotPublication {
85	pub fn new(
86		scope_uri: WorkspaceScopeUri,
87		request: WorkspaceRequest,
88		snapshot: Arc<WorkspaceSnapshot>,
89	) -> Self {
90		Self {
91			scope_uri,
92			request,
93			snapshot,
94		}
95	}
96
97	pub fn workspace(request: WorkspaceRequest, snapshot: Arc<WorkspaceSnapshot>) -> Self {
98		Self::new(WorkspaceScopeUri::workspace(), request, snapshot)
99	}
100}
101
102impl WorkspaceCommand {
103	pub fn new(
104		id: WorkspaceCommandId,
105		scope_uri: WorkspaceScopeUri,
106		kind: WorkspaceCommandKind,
107		request: WorkspaceRequest,
108	) -> Self {
109		Self {
110			id,
111			scope_uri,
112			kind,
113			request,
114		}
115	}
116}