Skip to main content

Mountain/Command/LanguageFeature/
References.rs

1//! # LanguageFeature - References
2//!
3//! Finds all references to a symbol
4
5#[allow(unused_imports)]
6use CommonLibrary::{
7	Error::CommonError::CommonError,
8	LanguageFeature::{
9		DTO::PositionDTO::PositionDTO,
10		LanguageFeatureProviderRegistry::LanguageFeatureProviderRegistry,
11	},
12};
13use serde_json::Value;
14use tauri::{AppHandle, Wry};
15use url::Url;
16
17use super::{InvokeProvider::invoke_provider, Validation::validate_language_feature_request};
18use crate::dev_log;
19
20/// Implementation of references command - called by the command wrapper in the
21/// parent module.
22pub(super) async fn provide_references_impl(
23	application_handle:AppHandle<Wry>,
24	uri:String,
25	position:Value,
26	context:Value,
27) -> Result<Value, String> {
28	dev_log!("commands", "[Language Feature] Providing references for: {} at {:?}", uri, position);
29
30	validate_language_feature_request("references", &uri, &position)?;
31
32	let document_uri = Url::parse(&uri).map_err(|error| error.to_string())?;
33
34	let position_dto:PositionDTO =
35		serde_json::from_value(position.clone()).map_err(|error| format!("Failed to parse position: {}", error))?;
36
37	// Context is passed as raw Value per trait signature
38	invoke_provider(application_handle, |provider| {
39		async move {
40			let result = provider.ProvideReferences(document_uri, position_dto, context.clone()).await?;
41			Ok(serde_json::to_value(result)?)
42		}
43	})
44	.await
45}