Skip to main content

DevelopmentNodeEnvironment_MicrosoftVSCodeDependency_22NodeVersion_Bundle_Clean_Debug_ElectronProfile_EsbuildCompiler_Mountain/Command/LanguageFeature/
References.rs

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