Skip to main content

Mountain/RPC/CocoonService/Provider/
PrepareCallHierarchy.rs

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