hover
Retrieve Javadoc and type information for Java symbols by specifying file path and position to understand code functionality during development.
Instructions
Get hover information (Javadoc, type info) for a symbol at the given position.
Args: file_path: Absolute path to the Java file line: 0-indexed line number character: 0-indexed character position
Returns: Dictionary with 'content' (markdown) or 'status'/'message' if initializing
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file_path | Yes | ||
| line | Yes | ||
| character | Yes |
Implementation Reference
- src/jons_mcp_java/tools/info.py:10-75 (handler)The primary handler for the 'hover' tool. It is decorated with @mcp.tool(), which both defines and registers the tool in the MCP server. The function sends an LSP 'textDocument/hover' request to the JDTLS language server for the specified position in a Java file and formats the response contents into a markdown string.@mcp.tool() async def hover( file_path: str, line: int, character: int, ) -> dict: """ Get hover information (Javadoc, type info) for a symbol at the given position. Args: file_path: Absolute path to the Java file line: 0-indexed line number character: 0-indexed character position Returns: Dictionary with 'content' (markdown) or 'status'/'message' if initializing """ manager = get_manager() if manager is None: return {"status": "error", "message": "Server not initialized"} client, status = await manager.get_client_for_file_with_status(Path(file_path)) if client is None: return {"status": "initializing", "message": status} await client.ensure_file_open(file_path) response = await client.request( LSP_TEXT_DOCUMENT_HOVER, { "textDocument": {"uri": path_to_uri(file_path)}, "position": {"line": line, "character": character} } ) if response is None: return {"content": None, "message": "No hover information available"} # Extract content from hover response contents = response.get("contents", {}) if isinstance(contents, str): return {"content": contents} if isinstance(contents, dict): # MarkupContent return {"content": contents.get("value", "")} if isinstance(contents, list): # Array of MarkedString or MarkupContent parts = [] for item in contents: if isinstance(item, str): parts.append(item) elif isinstance(item, dict): if "value" in item: parts.append(item["value"]) elif "language" in item: # MarkedString with language lang = item.get("language", "") value = item.get("value", "") parts.append(f"```{lang}\n{value}\n```") return {"content": "\n\n".join(parts)} return {"content": None}
- src/jons_mcp_java/server.py:64-65 (registration)The import statement in the MCP server lifespan that loads the tools modules, triggering the registration of the 'hover' tool (located in the 'info' module) via its @mcp.tool() decorator.# Import tools to register them from jons_mcp_java.tools import navigation, symbols, diagnostics, info # noqa: E402, F401
- src/jons_mcp_java/constants.py:17-17 (helper)Constant defining the LSP method name used exclusively by the hover tool to request hover information from the JDTLS server.LSP_TEXT_DOCUMENT_HOVER = "textDocument/hover"