Skip to main content

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;
8use ::Vine::Generated::{ProvideCodeActionsRequest, ProvideCodeActionsResponse};
9
10use crate::{RPC::CocoonService::CocoonServiceImpl, dev_log};
11
12pub async fn Fn(
13	Service:&CocoonServiceImpl,
14
15	Request:ProvideCodeActionsRequest,
16) -> Result<Response<ProvideCodeActionsResponse>, Status> {
17	dev_log!(
18		"cocoon",
19		"[CocoonService] Providing code actions for provider {}",
20		Request.provider_handle
21	);
22
23	let URI = Request.uri.as_ref().map(|U| U.value.as_str()).unwrap_or("");
24
25	let DocumentURI = Url::parse(URI).map_err(|E| Status::invalid_argument(format!("Invalid URI: {}", E)))?;
26
27	let R = Request.range.as_ref();
28
29	let RangeDTO = json!({
30		"StartLineNumber": R.and_then(|R| R.start.as_ref()).map(|P| P.line).unwrap_or(0),
31		"StartColumn": R.and_then(|R| R.start.as_ref()).map(|P| P.character).unwrap_or(0),
32		"EndLineNumber": R.and_then(|R| R.end.as_ref()).map(|P| P.line).unwrap_or(0),
33		"EndColumn": R.and_then(|R| R.end.as_ref()).map(|P| P.character).unwrap_or(0),
34	});
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
41		Err(Error) => Err(Status::internal(format!("Code actions failed: {}", Error))),
42	}
43}