Skip to main content

Mountain/RPC/CocoonService/Provider/
PrepareCallHierarchy.rs

1
2//! `PrepareCallHierarchy` gRPC RPC handler.
3//!
4//! The entry-point call for VS Code's call hierarchy feature. Mountain calls
5//! this with `uri + position`; Cocoon's `$prepareCallHierarchyItems` dispatch
6//! asks the registered provider to return the root `CallHierarchyItem` at that
7//! location. Without this step the incoming/outgoing calls panels are always
8//! empty even when the provider is correctly registered.
9
10use tonic::{Response, Status};
11use url::Url;
12use CommonLibrary::LanguageFeature::{
13	DTO::PositionDTO::PositionDTO,
14	LanguageFeatureProviderRegistry::LanguageFeatureProviderRegistry,
15};
16
17use crate::{
18	RPC::CocoonService::CocoonServiceImpl,
19	Vine::Generated::{ProvideCallHierarchyRequest, ProvideCallHierarchyResponse},
20	dev_log,
21};
22
23pub async fn Fn(
24	Service:&CocoonServiceImpl,
25
26	Request:ProvideCallHierarchyRequest,
27) -> Result<Response<ProvideCallHierarchyResponse>, Status> {
28	let URI = Request.uri.as_ref().map(|U| U.value.as_str()).unwrap_or("");
29
30	let Position_ = Request.position.as_ref();
31
32	let Line = Position_.map(|P| P.line).unwrap_or(0);
33
34	let Character = Position_.map(|P| P.character).unwrap_or(0);
35
36	dev_log!(
37		"provider",
38		"PrepareCallHierarchy handle={} uri={} line={} char={}",
39		Request.provider_handle,
40		URI,
41		Line,
42		Character
43	);
44
45	let DocumentURI = Url::parse(URI).map_err(|E| Status::invalid_argument(format!("Invalid URI: {}", E)))?;
46
47	let PositionDTO_ = PositionDTO { LineNumber:Line, Column:Character };
48
49	match Service.environment.PrepareCallHierarchy(DocumentURI, PositionDTO_).await {
50		Ok(_) => Ok(Response::new(ProvideCallHierarchyResponse::default())),
51
52		Err(Error) => Err(Status::internal(format!("prepare call hierarchy failed: {}", Error))),
53	}
54}