Skip to main content

DevelopmentNodeEnvironment_MicrosoftVSCodeDependency_22NodeVersion_Bundle_Clean_Debug_ElectronProfile_EsbuildCompiler_Mountain/Command/LanguageFeature/
CodeActions.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 serde_json::Value;
10use tauri::{AppHandle, Wry};
11use url::Url;
12
13use super::{InvokeProvider::invoke_provider, Validation::validate_language_feature_request};
14use crate::dev_log;
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
21	uri:String,
22
23	position:Value,
24
25	context:Value,
26) -> Result<Value, String> {
27	dev_log!(
28		"commands",
29		"[Language Feature] Providing code actions for: {} at {:?}",
30		uri,
31		position
32	);
33
34	validate_language_feature_request("code_actions", &uri, &position)?;
35
36	let document_uri = Url::parse(&uri).map_err(|error| error.to_string())?;
37
38	// Position is passed as RangeOrSelectionDTO (raw Value) per trait signature
39	invoke_provider(application_handle, |provider| {
40		async move {
41			let result = provider
42				.ProvideCodeActions(document_uri, position.clone(), context.clone())
43				.await?;
44			Ok(serde_json::to_value(result)?)
45		}
46	})
47	.await
48}