Skip to main content

DevelopmentNodeEnvironment_MicrosoftVSCodeDependency_22NodeVersion_Bundle_Clean_Debug_ElectronProfile_EsbuildCompiler_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};
15
16use crate::{
17	RPC::CocoonService::CocoonServiceImpl,
18	Vine::Generated::{ProvideCallHierarchyRequest, ProvideCallHierarchyResponse},
19	dev_log,
20};
21
22pub async fn Fn(
23	Service:&CocoonServiceImpl,
24
25	Request:ProvideCallHierarchyRequest,
26) -> Result<Response<ProvideCallHierarchyResponse>, Status> {
27	let URI = Request.uri.as_ref().map(|U| U.value.as_str()).unwrap_or("");
28
29	let Position_ = Request.position.as_ref();
30
31	let Line = Position_.map(|P| P.line).unwrap_or(0);
32
33	let Character = Position_.map(|P| P.character).unwrap_or(0);
34
35	dev_log!(
36		"provider",
37		"PrepareCallHierarchy handle={} uri={} line={} char={}",
38		Request.provider_handle,
39		URI,
40		Line,
41		Character
42	);
43
44	let DocumentURI = Url::parse(URI).map_err(|E| Status::invalid_argument(format!("Invalid URI: {}", E)))?;
45
46	let PositionDTO_ = PositionDTO { LineNumber:Line, Column:Character };
47
48	match Service.environment.PrepareCallHierarchy(DocumentURI, PositionDTO_).await {
49		Ok(_) => Ok(Response::new(ProvideCallHierarchyResponse::default())),
50
51		Err(Error) => Err(Status::internal(format!("prepare call hierarchy failed: {}", Error))),
52	}
53}