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::{
38	ApplicationState::DTO::ProviderRegistrationDTO::ProviderRegistrationDTO,
39	Environment::MountainEnvironment::MountainEnvironment,
40};
41
42// Private helper modules (not re-exported)
43mod Registration;
44mod ProviderLookup;
45mod FeatureMethods;
46
47#[async_trait]
48impl LanguageFeatureProviderRegistry for MountainEnvironment {
49	async fn RegisterProvider(
50		&self,
51		SideCarIdentifier:String,
52		ProviderType:ProviderType,
53		SelectorDTO:Value,
54		ExtensionIdentifierDTO:Value,
55		OptionsDTO:Option<Value>,
56	) -> Result<u32, CommonError> {
57		Registration::register_provider(
58			self,
59			SideCarIdentifier,
60			ProviderType,
61			SelectorDTO,
62			ExtensionIdentifierDTO,
63			OptionsDTO,
64		)
65		.await
66	}
67
68	async fn UnregisterProvider(&self, Handle:u32) -> Result<(), CommonError> {
69		Registration::unregister_provider(self, Handle).await
70	}
71
72	async fn ProvideCodeActions(
73		&self,
74		DocumentURI:Url,
75		RangeOrSelectionDTO:Value,
76		ContextDTO:Value,
77	) -> Result<Option<Value>, CommonError> {
78		FeatureMethods::provide_code_actions(self, DocumentURI, RangeOrSelectionDTO, ContextDTO).await
79	}
80
81	async fn ProvideCodeLenses(&self, DocumentURI:Url) -> Result<Option<Value>, CommonError> {
82		FeatureMethods::provide_code_lenses(self, DocumentURI).await
83	}
84
85	async fn ProvideCompletions(
86		&self,
87		DocumentURI:Url,
88		PositionDTO:PositionDTO,
89		ContextDTO:CompletionContextDTO,
90		CancellationTokenValue:Option<Value>,
91	) -> Result<Option<CompletionListDTO>, CommonError> {
92		FeatureMethods::provide_completions(self, DocumentURI, PositionDTO, ContextDTO, CancellationTokenValue).await
93	}
94
95	async fn ProvideDefinition(
96		&self,
97		DocumentURI:Url,
98		PositionDTO:PositionDTO,
99	) -> Result<Option<Vec<LocationDTO>>, CommonError> {
100		FeatureMethods::provide_definition(self, DocumentURI, PositionDTO).await
101	}
102
103	async fn ProvideDocumentFormattingEdits(
104		&self,
105		DocumentURI:Url,
106		OptionsDTO:Value,
107	) -> Result<Option<Vec<TextEditDTO>>, CommonError> {
108		FeatureMethods::provide_document_formatting_edits(self, DocumentURI, OptionsDTO).await
109	}
110
111	async fn ProvideDocumentHighlights(
112		&self,
113		DocumentURI:Url,
114		PositionDTO:PositionDTO,
115	) -> Result<Option<Value>, CommonError> {
116		FeatureMethods::provide_document_highlights(self, DocumentURI, PositionDTO).await
117	}
118
119	async fn ProvideDocumentLinks(&self, DocumentURI:Url) -> Result<Option<Value>, CommonError> {
120		FeatureMethods::provide_document_links(self, DocumentURI).await
121	}
122
123	async fn ProvideDocumentRangeFormattingEdits(
124		&self,
125		DocumentURI:Url,
126		RangeDTO:Value,
127		OptionsDTO:Value,
128	) -> Result<Option<Vec<TextEditDTO>>, CommonError> {
129		FeatureMethods::provide_document_range_formatting_edits(self, DocumentURI, RangeDTO, OptionsDTO).await
130	}
131
132	async fn ProvideHover(
133		&self,
134		DocumentURI:Url,
135		PositionDTO:PositionDTO,
136	) -> Result<Option<HoverResultDTO>, CommonError> {
137		FeatureMethods::provide_hover(self, DocumentURI, PositionDTO).await
138	}
139
140	async fn ProvideReferences(
141		&self,
142		DocumentURI:Url,
143		PositionDTO:PositionDTO,
144		ContextDTO:Value,
145	) -> Result<Option<Vec<LocationDTO>>, CommonError> {
146		FeatureMethods::provide_references(self, DocumentURI, PositionDTO, ContextDTO).await
147	}
148
149	async fn PrepareRename(&self, DocumentURI:Url, PositionDTO:PositionDTO) -> Result<Option<Value>, CommonError> {
150		FeatureMethods::prepare_rename(self, DocumentURI, PositionDTO).await
151	}
152}