Skip to main content

Mountain/RPC/CocoonService/Provider/
ProvideCodeActions.rs

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