Skip to main content

DevelopmentNodeEnvironment_MicrosoftVSCodeDependency_22NodeVersion_Bundle_Clean_Debug_ElectronProfile_EsbuildCompiler_Mountain/RPC/CocoonService/Provider/
PrepareCallHierarchy.rs

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