Skip to main content

Mountain/RPC/CocoonService/Provider/
ProvideSelectionRanges.rs

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