Mountain/Command/LanguageFeature/
code_actions.rs

1//! # LanguageFeature - Code Actions
2//!
3//! Provides code actions (quick fixes and refactorings) for a code range
4
5use CommonLibrary::{
6	Error::CommonError::CommonError,
7	LanguageFeature::LanguageFeatureProviderRegistry::LanguageFeatureProviderRegistry,
8};
9use log::debug;
10use serde_json::Value;
11use tauri::{AppHandle, Wry};
12use url::Url;
13
14use super::{invoke_provider::invoke_provider, validation::validate_language_feature_request};
15
16/// Implementation of code actions command - called by the command wrapper in
17/// the parent module.
18pub(super) async fn provide_code_actions_impl(
19	application_handle:AppHandle<Wry>,
20	uri:String,
21	position:Value,
22	context:Value,
23) -> Result<Value, String> {
24	debug!("[Language Feature] Providing code actions for: {} at {:?}", uri, position);
25
26	validate_language_feature_request("code_actions", &uri, &position)?;
27
28	let document_uri = Url::parse(&uri).map_err(|error| error.to_string())?;
29
30	// Position is passed as RangeOrSelectionDTO (raw Value) per trait signature
31	invoke_provider(application_handle, |provider| {
32		async move {
33			let result = provider
34				.ProvideCodeActions(document_uri, position.clone(), context.clone())
35				.await?;
36			Ok(serde_json::to_value(result)?)
37		}
38	})
39	.await
40}