use super::Backend;
use tower_lsp_server::jsonrpc::Result;
use tower_lsp_server::ls_types::request::{GotoImplementationParams, GotoImplementationResponse};
use tower_lsp_server::ls_types::*;
use tracing::info;
impl Backend {
pub async fn handle_goto_implementation(
&self,
params: GotoImplementationParams,
) -> Result<Option<GotoImplementationResponse>> {
let uri = params.text_document_position_params.text_document.uri;
let position = params.text_document_position_params.position;
info!(
"goto_implementation request: uri={:?}, line={}, char={}",
uri, position.line, position.character
);
if let Some(file_path) = self.uri_to_path(&uri) {
info!(
"Looking for fixture implementation at {:?}:{}:{}",
file_path, position.line, position.character
);
if let Some(definition) = self.fixture_db.find_fixture_or_definition_at_position(
&file_path,
position.line,
position.character,
) {
info!("Found definition: {:?}", definition);
if let Some(yield_line) = definition.yield_line {
let Some(def_uri) = self.path_to_uri(&definition.file_path) else {
return Ok(None);
};
let lsp_line = Self::internal_line_to_lsp(yield_line);
let location = Location {
uri: def_uri.clone(),
range: Self::create_point_range(lsp_line, 0),
};
info!("Returning yield location: {:?}", location);
return Ok(Some(GotoImplementationResponse::Scalar(location)));
} else {
info!("Fixture has no yield statement (not a generator fixture)");
let Some(def_uri) = self.path_to_uri(&definition.file_path) else {
return Ok(None);
};
let def_line = Self::internal_line_to_lsp(definition.line);
let location = Location {
uri: def_uri.clone(),
range: Self::create_point_range(def_line, 0),
};
info!("Returning definition location (no yield): {:?}", location);
return Ok(Some(GotoImplementationResponse::Scalar(location)));
}
} else {
info!("No fixture definition found");
}
}
Ok(None)
}
}