Skip to main content

CommonLibrary/LanguageFeature/
LanguageFeatureProviderRegistry.rs

1// File: Common/Source/LanguageFeature/LanguageFeatureProviderRegistry.rs
2// Role: Defines the abstract service trait for managing and invoking all
3// language       feature providers. This serves as the central contract for all
4// language       intelligence capabilities.
5// Responsibilities:
6//   - Provide a contract for registering and unregistering providers.
7//   - Define the invocation signature for every language feature (e.g., hover,
8
9//     completion).
10
11//! # LanguageFeatureProviderRegistry Trait
12//!
13//! Defines the abstract service trait for managing and invoking all language
14//! feature providers. This serves as the central contract for all language
15//! intelligence capabilities.
16
17use async_trait::async_trait;
18use serde_json::Value;
19use url::Url;
20
21use super::DTO::{
22	CompletionContextDTO::CompletionContextDTO,
23	CompletionListDTO::CompletionListDTO,
24	HoverResultDTO::HoverResultDTO,
25	LocationDTO::LocationDTO,
26	PositionDTO::PositionDTO,
27	ProviderType::ProviderType,
28	TextEditDTO::TextEditDTO,
29};
30use crate::{Environment::Environment::Environment, Error::CommonError::CommonError};
31
32/// An abstract service contract for an environment component that can register,
33
34/// unregister, and invoke all types of language feature providers (e.g., for
35/// completions, hovers, definitions).
36///
37/// By consolidating all features into a single registry, we avoid the need for
38/// dozens of separate provider traits, simplifying the overall architecture.
39#[async_trait]
40pub trait LanguageFeatureProviderRegistry: Environment + Send + Sync {
41	// --- Provider Management ---
42
43	/// Registers a new language feature provider.
44	///
45	/// # Parameters
46	/// * `SideCarIdentifier`: The ID of the sidecar hosting the provider.
47	/// * `ProviderType`: The type of feature this provider implements.
48	/// * `SelectorDTO`: The document selector that determines which documents
49	///   this provider applies to.
50	/// * `ExtensionIdentifierDTO`: The ID of the extension contributing the
51	///   provider.
52	/// * `OptionsDTO`: Optional, feature-specific options.
53	///
54	/// # Returns
55	/// A `Result` containing a unique handle (u32) for the new registration.
56	async fn RegisterProvider(
57		&self,
58
59		SideCarIdentifier:String,
60
61		ProviderType:ProviderType,
62
63		SelectorDTO:Value,
64
65		ExtensionIdentifierDTO:Value,
66
67		OptionsDTO:Option<Value /* ProviderOptionsDTO */>,
68	) -> Result<u32, CommonError>;
69
70	/// Unregisters a previously registered provider.
71	///
72	/// # Parameters
73	/// * `Handle`: The unique handle of the provider registration to remove.
74	async fn UnregisterProvider(&self, Handle:u32) -> Result<(), CommonError>;
75
76	// --- Invocation Methods (sorted alphabetically) ---
77
78	async fn ProvideCodeActions(
79		&self,
80
81		DocumentURI:Url,
82
83		// Range DTO
84		RangeOrSelectionDTO:Value,
85
86		// CodeActionContextDTO
87		ContextDTO:Value,
88	) -> Result<Option<Value /* CodeActionListDTO */>, CommonError>;
89
90	async fn ProvideCodeLenses(&self, DocumentURI:Url) -> Result<Option<Value /* CodeLensListDTO */>, CommonError>;
91
92	async fn ProvideCompletions(
93		&self,
94
95		DocumentURI:Url,
96
97		PositionDTO:PositionDTO,
98
99		ContextDTO:CompletionContextDTO,
100
101		CancellationTokenValue:Option<Value>,
102	) -> Result<Option<CompletionListDTO>, CommonError>;
103
104	async fn ProvideDefinition(
105		&self,
106
107		DocumentURI:Url,
108
109		PositionDTO:PositionDTO,
110	) -> Result<Option<Vec<LocationDTO>>, CommonError>;
111
112	async fn ProvideDocumentFormattingEdits(
113		&self,
114
115		DocumentURI:Url,
116
117		// FormattingOptions DTO
118		OptionsDTO:Value,
119	) -> Result<Option<Vec<TextEditDTO>>, CommonError>;
120
121	async fn ProvideDocumentHighlights(
122		&self,
123
124		DocumentURI:Url,
125
126		PositionDTO:PositionDTO,
127	) -> Result<Option<Value /* Vec<DocumentHighlightDTO> */>, CommonError>;
128
129	async fn ProvideDocumentLinks(&self, DocumentURI:Url) -> Result<Option<Value /* LinksListDTO */>, CommonError>;
130
131	async fn ProvideDocumentRangeFormattingEdits(
132		&self,
133
134		DocumentURI:Url,
135
136		// Range DTO
137		RangeDTO:Value,
138
139		// FormattingOptions DTO
140		OptionsDTO:Value,
141	) -> Result<Option<Vec<TextEditDTO>>, CommonError>;
142
143	async fn ProvideHover(
144		&self,
145
146		DocumentURI:Url,
147
148		PositionDTO:PositionDTO,
149	) -> Result<Option<HoverResultDTO>, CommonError>;
150
151	async fn ProvideReferences(
152		&self,
153
154		DocumentURI:Url,
155
156		PositionDTO:PositionDTO,
157
158		// ReferenceContext DTO
159		ContextDTO:Value,
160	) -> Result<Option<Vec<LocationDTO>>, CommonError>;
161
162	async fn PrepareRename(&self, DocumentURI:Url, PositionDTO:PositionDTO) -> Result<Option<Value>, CommonError>;
163
164	/// Provides rename edits for a symbol at the given position.
165	async fn ProvideRenameEdits(
166		&self,
167
168		DocumentURI:Url,
169
170		PositionDTO:PositionDTO,
171
172		NewName:String,
173	) -> Result<Option<Value /* WorkspaceEditDTO */>, CommonError>;
174
175	/// Provides document symbols (outline) for the given document.
176	async fn ProvideDocumentSymbols(
177		&self,
178
179		DocumentURI:Url,
180	) -> Result<Option<Value /* Vec<DocumentSymbolDTO> */>, CommonError>;
181
182	/// Provides workspace symbols matching the given query.
183	async fn ProvideWorkspaceSymbols(
184		&self,
185
186		Query:String,
187	) -> Result<Option<Value /* Vec<WorkspaceSymbolDTO> */>, CommonError>;
188
189	/// Provides signature help at the given position.
190	async fn ProvideSignatureHelp(
191		&self,
192
193		DocumentURI:Url,
194
195		PositionDTO:PositionDTO,
196
197		ContextDTO:Value,
198	) -> Result<Option<Value /* SignatureHelpDTO */>, CommonError>;
199
200	/// Provides folding ranges for the given document.
201	async fn ProvideFoldingRanges(
202		&self,
203
204		DocumentURI:Url,
205	) -> Result<Option<Value /* Vec<FoldingRangeDTO> */>, CommonError>;
206
207	/// Provides selection ranges at the given positions.
208	async fn ProvideSelectionRanges(
209		&self,
210
211		DocumentURI:Url,
212
213		Positions:Vec<PositionDTO>,
214	) -> Result<Option<Value /* Vec<SelectionRangeDTO> */>, CommonError>;
215
216	/// Provides semantic tokens for the full document.
217	async fn ProvideSemanticTokensFull(
218		&self,
219
220		DocumentURI:Url,
221	) -> Result<Option<Value /* SemanticTokensDTO */>, CommonError>;
222
223	/// Provides inlay hints within the given range.
224	async fn ProvideInlayHints(
225		&self,
226
227		DocumentURI:Url,
228
229		RangeDTO:Value,
230	) -> Result<Option<Value /* Vec<InlayHintDTO> */>, CommonError>;
231
232	/// Provides type hierarchy supertypes for the given item.
233	async fn ProvideTypeHierarchySupertypes(
234		&self,
235
236		ItemDTO:Value,
237	) -> Result<Option<Value /* Vec<TypeHierarchyItemDTO> */>, CommonError>;
238
239	/// Provides type hierarchy subtypes for the given item.
240	async fn ProvideTypeHierarchySubtypes(
241		&self,
242
243		ItemDTO:Value,
244	) -> Result<Option<Value /* Vec<TypeHierarchyItemDTO> */>, CommonError>;
245
246	/// Provides call hierarchy incoming calls for the given item.
247	async fn ProvideCallHierarchyIncomingCalls(
248		&self,
249
250		ItemDTO:Value,
251	) -> Result<Option<Value /* Vec<CallHierarchyCallDTO> */>, CommonError>;
252
253	/// Provides call hierarchy outgoing calls for the given item.
254	async fn ProvideCallHierarchyOutgoingCalls(
255		&self,
256
257		ItemDTO:Value,
258	) -> Result<Option<Value /* Vec<CallHierarchyCallDTO> */>, CommonError>;
259
260	/// Provides linked editing ranges at the given position.
261	async fn ProvideLinkedEditingRanges(
262		&self,
263
264		DocumentURI:Url,
265
266		PositionDTO:PositionDTO,
267	) -> Result<Option<Value /* LinkedEditingRangesDTO */>, CommonError>;
268
269	/// Provides on-type formatting edits.
270	async fn ProvideOnTypeFormattingEdits(
271		&self,
272
273		DocumentURI:Url,
274
275		PositionDTO:PositionDTO,
276
277		Character:String,
278
279		OptionsDTO:Value,
280	) -> Result<Option<Vec<TextEditDTO>>, CommonError>;
281}