Skip to main content

Mountain/Command/LanguageFeature/
Highlights.rs

1//! # LanguageFeature - Document Highlights
2//!
3//! Finds symbol occurrences (document highlights) in a document
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 document highlights command - called by the command
21/// wrapper in the parent module.
22pub(super) async fn provide_document_highlights_impl(
23	application_handle:AppHandle<Wry>,
24	uri:String,
25	position:Value,
26) -> Result<Value, String> {
27	dev_log!("commands", 
28		"[Language Feature] Providing document highlights for: {} at {:?}",
29		uri, position
30	);
31
32	validate_language_feature_request("document_highlights", &uri, &position)?;
33
34	let document_uri = Url::parse(&uri).map_err(|error| error.to_string())?;
35
36	let position_dto:PositionDTO =
37		serde_json::from_value(position.clone()).map_err(|error| format!("Failed to parse position: {}", error))?;
38
39	invoke_provider(application_handle, |provider| {
40		async move {
41			let result = provider.ProvideDocumentHighlights(document_uri, position_dto).await?;
42			Ok(serde_json::to_value(result)?)
43		}
44	})
45	.await
46}