Skip to main content

DevelopmentNodeEnvironment_MicrosoftVSCodeDependency_22NodeVersion_Bundle_Clean_Debug_ElectronProfile_EsbuildCompiler_Mountain/RPC/CocoonService/Provider/
ProvideCodeActions.rs

1//! Forward a code-actions request to the registered provider. Currently
2//! returns an empty list pending the action-DTO mapping.
3
4use serde_json::json;
5use tonic::{Response, Status};
6use url::Url;
7use CommonLibrary::LanguageFeature::LanguageFeatureProviderRegistry::LanguageFeatureProviderRegistry;
8
9use crate::{
10	RPC::CocoonService::CocoonServiceImpl,
11	Vine::Generated::{ProvideCodeActionsRequest, ProvideCodeActionsResponse},
12	dev_log,
13};
14
15pub async fn Fn(
16	Service:&CocoonServiceImpl,
17
18	Request:ProvideCodeActionsRequest,
19) -> Result<Response<ProvideCodeActionsResponse>, Status> {
20	dev_log!(
21		"cocoon",
22		"[CocoonService] Providing code actions for provider {}",
23		Request.provider_handle
24	);
25
26	let URI = Request.uri.as_ref().map(|U| U.value.as_str()).unwrap_or("");
27
28	let DocumentURI = Url::parse(URI).map_err(|E| Status::invalid_argument(format!("Invalid URI: {}", E)))?;
29
30	let R = Request.range.as_ref();
31
32	let RangeDTO = json!({
33		"StartLineNumber": R.and_then(|R| R.start.as_ref()).map(|P| P.line).unwrap_or(0),
34		"StartColumn": R.and_then(|R| R.start.as_ref()).map(|P| P.character).unwrap_or(0),
35		"EndLineNumber": R.and_then(|R| R.end.as_ref()).map(|P| P.line).unwrap_or(0),
36		"EndColumn": R.and_then(|R| R.end.as_ref()).map(|P| P.character).unwrap_or(0),
37	});
38
39	let ContextDTO = json!({ "diagnostics": [], "only": null });
40
41	match Service.environment.ProvideCodeActions(DocumentURI, RangeDTO, ContextDTO).await {
42		Ok(_) => Ok(Response::new(ProvideCodeActionsResponse { actions:Vec::new() })),
43
44		Err(Error) => Err(Status::internal(format!("Code actions failed: {}", Error))),
45	}
46}