Skip to main content

Mountain/RPC/CocoonService/Provider/
ProvideCodeActions.rs

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