use lsp_types::{self as types, request as req};

use crate::call_hierarchy;
use crate::server::Result;
use crate::session::{Client, RequestCancellationToken, Session};
use crate::workspace_functions::WorkspaceFunctionContext;

pub(crate) struct CallHierarchyIncomingCalls;

impl super::RequestHandler for CallHierarchyIncomingCalls {
    type RequestType = req::CallHierarchyIncomingCalls;
}

impl super::super::traits::BackgroundRequestHandler for CallHierarchyIncomingCalls {
    type Snapshot = WorkspaceFunctionContext;

    fn snapshot(
        session: &Session,
        _params: &types::CallHierarchyIncomingCallsParams,
        cancellation: RequestCancellationToken,
    ) -> Result<Self::Snapshot> {
        Ok(session.workspace_function_context(cancellation))
    }

    fn run_with_snapshot(
        snapshot: Self::Snapshot,
        _client: &Client,
        params: types::CallHierarchyIncomingCallsParams,
    ) -> Result<call_hierarchy::IncomingResponse> {
        call_hierarchy::incoming_calls(snapshot, params)
    }
}
