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
25	uri:String,
26
27	position:Value,
28
29	context:Value,
30) -> Result<Value, String> {
31	dev_log!(
32		"commands",
33		"[Language Feature] Providing references for: {} at {:?}",
34		uri,
35		position
36	);
37
38	validate_language_feature_request("references", &uri, &position)?;
39
40	let document_uri = Url::parse(&uri).map_err(|error| error.to_string())?;
41
42	let position_dto:PositionDTO =
43		serde_json::from_value(position.clone()).map_err(|error| format!("Failed to parse position: {}", error))?;
44
45	// Context is passed as raw Value per trait signature
46	invoke_provider(application_handle, |provider| {
47		async move {
48			let result = provider.ProvideReferences(document_uri, position_dto, context.clone()).await?;
49			Ok(serde_json::to_value(result)?)
50		}
51	})
52	.await
53}