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