Skip to main content

Mountain/RPC/CocoonService/Provider/
ProvideSelectionRanges.rs

1//! Forward a selection-ranges request (multiple positions per call) to
2//! the registered provider.
3
4use tonic::{Response, Status};
5use url::Url;
6use CommonLibrary::LanguageFeature::{
7	DTO::PositionDTO::PositionDTO,
8	LanguageFeatureProviderRegistry::LanguageFeatureProviderRegistry,
9};
10use ::Vine::Generated::{ProvideSelectionRangesRequest, ProvideSelectionRangesResponse};
11
12use crate::{RPC::CocoonService::CocoonServiceImpl, dev_log};
13
14pub async fn Fn(
15	Service:&CocoonServiceImpl,
16
17	Request:ProvideSelectionRangesRequest,
18) -> Result<Response<ProvideSelectionRangesResponse>, Status> {
19	dev_log!("cocoon", "[CocoonService] Providing selection ranges");
20
21	let URI = Request.uri.as_ref().map(|U| U.value.as_str()).unwrap_or("");
22
23	let DocumentURI = Url::parse(URI).map_err(|E| Status::invalid_argument(format!("Invalid URI: {}", E)))?;
24
25	let PositionDTOs:Vec<PositionDTO> = Request
26		.positions
27		.iter()
28		.map(|P| PositionDTO { LineNumber:P.line, Column:P.character })
29		.collect();
30
31	match Service.environment.ProvideSelectionRanges(DocumentURI, PositionDTOs).await {
32		Ok(_) => Ok(Response::new(ProvideSelectionRangesResponse::default())),
33
34		Err(Error) => Err(Status::internal(format!("Selection ranges failed: {}", Error))),
35	}
36}