Mountain/RPC/CocoonService/Provider/
ProvideRenameEdits.rs1
2use tonic::{Response, Status};
5use url::Url;
6use CommonLibrary::LanguageFeature::{
7 DTO::PositionDTO::PositionDTO,
8 LanguageFeatureProviderRegistry::LanguageFeatureProviderRegistry,
9};
10
11use crate::{
12 RPC::CocoonService::CocoonServiceImpl,
13 Vine::Generated::{ProvideRenameEditsRequest, ProvideRenameEditsResponse},
14 dev_log,
15};
16
17pub async fn Fn(
18 Service:&CocoonServiceImpl,
19
20 Request:ProvideRenameEditsRequest,
21) -> Result<Response<ProvideRenameEditsResponse>, Status> {
22 dev_log!(
23 "cocoon",
24 "[CocoonService] Providing rename edits: new_name={}",
25 Request.new_name
26 );
27
28 let URI = Request.uri.as_ref().map(|U| U.value.as_str()).unwrap_or("");
29
30 let DocumentURI = Url::parse(URI).map_err(|E| Status::invalid_argument(format!("Invalid URI: {}", E)))?;
31
32 let Position_ = Request.position.as_ref();
33
34 let PositionDTO_ = PositionDTO {
35 LineNumber:Position_.map(|P| P.line).unwrap_or(0),
36
37 Column:Position_.map(|P| P.character).unwrap_or(0),
38 };
39
40 match Service
41 .environment
42 .ProvideRenameEdits(DocumentURI, PositionDTO_, Request.new_name)
43 .await
44 {
45 Ok(_) => Ok(Response::new(ProvideRenameEditsResponse::default())),
46
47 Err(Error) => Err(Status::internal(format!("Rename edits failed: {}", Error))),
48 }
49}