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!("commands", "[Language Feature] Providing code actions for: {} at {:?}", uri, position);
26
27	validate_language_feature_request("code_actions", &uri, &position)?;
28
29	let document_uri = Url::parse(&uri).map_err(|error| error.to_string())?;
30
31	// Position is passed as RangeOrSelectionDTO (raw Value) per trait signature
32	invoke_provider(application_handle, |provider| {
33		async move {
34			let result = provider
35				.ProvideCodeActions(document_uri, position.clone(), context.clone())
36				.await?;
37			Ok(serde_json::to_value(result)?)
38		}
39	})
40	.await
41}