Skip to main content

Mountain/Environment/LanguageFeatureProvider/
mod.rs

1//! # LanguageFeatureProvider (Environment)
2//!
3//! Provides language feature intelligence through extension-hosted LSP
4//! providers. Manages provider registration, lookup, and invocation for hover,
5//! completion, definition, references, formatting, code actions, and more.
6//!
7//! ## Implementation Strategy
8//!
9//! The trait implementation is split across multiple helper modules:
10//! - `Registration`: RegisterProvider, UnregisterProvider
11//! - `ProviderLookup`: GetMatchingProvider (private helper)
12//! - `FeatureMethods`: All LSP feature methods (Hover, Completion, etc.)
13//!
14//! The single `impl LanguageFeatureProviderRegistry for MountainEnvironment`
15//! block in this file delegates to those helper functions. This satisfies
16//! Rust's orphan rules while keeping code organized and atomic.
17
18use CommonLibrary::{
19	Error::CommonError::CommonError,
20	LanguageFeature::{
21		DTO::{
22			CompletionContextDTO::CompletionContextDTO,
23			CompletionListDTO::CompletionListDTO,
24			HoverResultDTO::HoverResultDTO,
25			LocationDTO::LocationDTO,
26			PositionDTO::PositionDTO,
27			ProviderType::ProviderType,
28			TextEditDTO::TextEditDTO,
29		},
30		LanguageFeatureProviderRegistry::LanguageFeatureProviderRegistry,
31	},
32};
33use async_trait::async_trait;
34use serde_json::Value;
35use url::Url;
36
37use crate::Environment::MountainEnvironment::MountainEnvironment;
38
39// Private helper modules (not re-exported)
40mod Registration;
41
42mod ProviderLookup;
43
44mod FeatureMethods;
45
46#[async_trait]
47impl LanguageFeatureProviderRegistry for MountainEnvironment {
48	async fn RegisterProvider(
49		&self,
50
51		SideCarIdentifier:String,
52
53		ProviderType:ProviderType,
54
55		SelectorDTO:Value,
56
57		ExtensionIdentifierDTO:Value,
58
59		OptionsDTO:Option<Value>,
60	) -> Result<u32, CommonError> {
61		Registration::register_provider(
62			self,
63			SideCarIdentifier,
64			ProviderType,
65			SelectorDTO,
66			ExtensionIdentifierDTO,
67			OptionsDTO,
68		)
69		.await
70	}
71
72	async fn UnregisterProvider(&self, Handle:u32) -> Result<(), CommonError> {
73		Registration::unregister_provider(self, Handle).await
74	}
75
76	async fn ProvideCodeActions(
77		&self,
78
79		DocumentURI:Url,
80
81		RangeOrSelectionDTO:Value,
82
83		ContextDTO:Value,
84	) -> Result<Option<Value>, CommonError> {
85		FeatureMethods::provide_code_actions(self, DocumentURI, RangeOrSelectionDTO, ContextDTO).await
86	}
87
88	async fn ProvideCodeLenses(&self, DocumentURI:Url) -> Result<Option<Value>, CommonError> {
89		FeatureMethods::provide_code_lenses(self, DocumentURI).await
90	}
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		FeatureMethods::provide_completions(self, DocumentURI, PositionDTO, ContextDTO, CancellationTokenValue).await
104	}
105
106	async fn ProvideDefinition(
107		&self,
108
109		DocumentURI:Url,
110
111		PositionDTO:PositionDTO,
112	) -> Result<Option<Vec<LocationDTO>>, CommonError> {
113		FeatureMethods::provide_definition(self, DocumentURI, PositionDTO).await
114	}
115
116	async fn ProvideDocumentFormattingEdits(
117		&self,
118
119		DocumentURI:Url,
120
121		OptionsDTO:Value,
122	) -> Result<Option<Vec<TextEditDTO>>, CommonError> {
123		FeatureMethods::provide_document_formatting_edits(self, DocumentURI, OptionsDTO).await
124	}
125
126	async fn ProvideDocumentHighlights(
127		&self,
128
129		DocumentURI:Url,
130
131		PositionDTO:PositionDTO,
132	) -> Result<Option<Value>, CommonError> {
133		FeatureMethods::provide_document_highlights(self, DocumentURI, PositionDTO).await
134	}
135
136	async fn ProvideDocumentLinks(&self, DocumentURI:Url) -> Result<Option<Value>, CommonError> {
137		FeatureMethods::provide_document_links(self, DocumentURI).await
138	}
139
140	async fn ProvideDocumentRangeFormattingEdits(
141		&self,
142
143		DocumentURI:Url,
144
145		RangeDTO:Value,
146
147		OptionsDTO:Value,
148	) -> Result<Option<Vec<TextEditDTO>>, CommonError> {
149		FeatureMethods::provide_document_range_formatting_edits(self, DocumentURI, RangeDTO, OptionsDTO).await
150	}
151
152	async fn ProvideHover(
153		&self,
154
155		DocumentURI:Url,
156
157		PositionDTO:PositionDTO,
158	) -> Result<Option<HoverResultDTO>, CommonError> {
159		FeatureMethods::provide_hover(self, DocumentURI, PositionDTO).await
160	}
161
162	async fn ProvideReferences(
163		&self,
164
165		DocumentURI:Url,
166
167		PositionDTO:PositionDTO,
168
169		ContextDTO:Value,
170	) -> Result<Option<Vec<LocationDTO>>, CommonError> {
171		FeatureMethods::provide_references(self, DocumentURI, PositionDTO, ContextDTO).await
172	}
173
174	async fn PrepareRename(&self, DocumentURI:Url, PositionDTO:PositionDTO) -> Result<Option<Value>, CommonError> {
175		FeatureMethods::prepare_rename(self, DocumentURI, PositionDTO).await
176	}
177
178	async fn ProvideRenameEdits(
179		&self,
180
181		DocumentURI:Url,
182
183		PositionDTO:PositionDTO,
184
185		NewName:String,
186	) -> Result<Option<Value>, CommonError> {
187		FeatureMethods::provide_rename_edits(self, DocumentURI, PositionDTO, NewName).await
188	}
189
190	async fn ProvideDocumentSymbols(&self, DocumentURI:Url) -> Result<Option<Value>, CommonError> {
191		FeatureMethods::provide_document_symbols(self, DocumentURI).await
192	}
193
194	async fn ProvideWorkspaceSymbols(&self, Query:String) -> Result<Option<Value>, CommonError> {
195		FeatureMethods::provide_workspace_symbols(self, Query).await
196	}
197
198	async fn ProvideSignatureHelp(
199		&self,
200
201		DocumentURI:Url,
202
203		PositionDTO:PositionDTO,
204
205		ContextDTO:Value,
206	) -> Result<Option<Value>, CommonError> {
207		FeatureMethods::provide_signature_help(self, DocumentURI, PositionDTO, ContextDTO).await
208	}
209
210	async fn ProvideFoldingRanges(&self, DocumentURI:Url) -> Result<Option<Value>, CommonError> {
211		FeatureMethods::provide_folding_ranges(self, DocumentURI).await
212	}
213
214	async fn ProvideSelectionRanges(
215		&self,
216
217		DocumentURI:Url,
218
219		Positions:Vec<PositionDTO>,
220	) -> Result<Option<Value>, CommonError> {
221		FeatureMethods::provide_selection_ranges(self, DocumentURI, Positions).await
222	}
223
224	async fn ProvideSemanticTokensFull(&self, DocumentURI:Url) -> Result<Option<Value>, CommonError> {
225		FeatureMethods::provide_semantic_tokens_full(self, DocumentURI).await
226	}
227
228	async fn ProvideInlayHints(&self, DocumentURI:Url, RangeDTO:Value) -> Result<Option<Value>, CommonError> {
229		FeatureMethods::provide_inlay_hints(self, DocumentURI, RangeDTO).await
230	}
231
232	async fn ProvideTypeHierarchySupertypes(&self, ItemDTO:Value) -> Result<Option<Value>, CommonError> {
233		FeatureMethods::provide_type_hierarchy_supertypes(self, ItemDTO).await
234	}
235
236	async fn ProvideTypeHierarchySubtypes(&self, ItemDTO:Value) -> Result<Option<Value>, CommonError> {
237		FeatureMethods::provide_type_hierarchy_subtypes(self, ItemDTO).await
238	}
239
240	async fn ProvideCallHierarchyIncomingCalls(&self, ItemDTO:Value) -> Result<Option<Value>, CommonError> {
241		FeatureMethods::provide_call_hierarchy_incoming_calls(self, ItemDTO).await
242	}
243
244	async fn ProvideCallHierarchyOutgoingCalls(&self, ItemDTO:Value) -> Result<Option<Value>, CommonError> {
245		FeatureMethods::provide_call_hierarchy_outgoing_calls(self, ItemDTO).await
246	}
247
248	async fn ProvideLinkedEditingRanges(
249		&self,
250
251		DocumentURI:Url,
252
253		PositionDTO:PositionDTO,
254	) -> Result<Option<Value>, CommonError> {
255		FeatureMethods::provide_linked_editing_ranges(self, DocumentURI, PositionDTO).await
256	}
257
258	async fn ProvideOnTypeFormattingEdits(
259		&self,
260
261		DocumentURI:Url,
262
263		PositionDTO:PositionDTO,
264
265		Character:String,
266
267		OptionsDTO:Value,
268	) -> Result<Option<Vec<TextEditDTO>>, CommonError> {
269		FeatureMethods::provide_on_type_formatting_edits(self, DocumentURI, PositionDTO, Character, OptionsDTO).await
270	}
271}