Mountain/Command/LanguageFeature/
highlights.rs

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