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
22	Request:ProvideSelectionRangesRequest,
23) -> Result<Response<ProvideSelectionRangesResponse>, Status> {
24	dev_log!("cocoon", "[CocoonService] Providing selection ranges");
25
26	let URI = Request.uri.as_ref().map(|U| U.value.as_str()).unwrap_or("");
27
28	let DocumentURI = Url::parse(URI).map_err(|E| Status::invalid_argument(format!("Invalid URI: {}", E)))?;
29
30	let PositionDTOs:Vec<PositionDTO> = Request
31		.positions
32		.iter()
33		.map(|P| PositionDTO { LineNumber:P.line, Column:P.character })
34		.collect();
35
36	match Service.environment.ProvideSelectionRanges(DocumentURI, PositionDTOs).await {
37		Ok(_) => Ok(Response::new(ProvideSelectionRangesResponse::default())),
38
39		Err(Error) => Err(Status::internal(format!("Selection ranges failed: {}", Error))),
40	}
41}