Skip to main content

Mountain/Command/LanguageFeature/
CodeActions.rs

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