This repository has been archived on 2026-08-16. You can view files and clone it, but cannot push or open issues or pull requests.
ollie-9p/tools/lsp_hover

38 lines
963 B
Python
Executable File

#!/usr/bin/env python3
# ollie:parallel read
# description: Get type/documentation info for symbol at position.
# Args: <file> <line> <col>
import os
import sys
sys.path.insert(0, os.path.join(os.environ['OLLIE'], 's', os.environ['OLLIE_SESSION_ID'], 't'))
from _lib.lsp.client import request
if len(sys.argv) < 4:
print("usage: lsp_hover <file> <line> <col>")
sys.exit(1)
filepath = os.path.abspath(sys.argv[1])
line = int(sys.argv[2]) - 1
col = int(sys.argv[3]) - 1
result = request("hover", file=filepath, line=line, col=col)
if not result:
print("(no hover info)")
sys.exit(0)
contents = result.get("contents", "")
if isinstance(contents, dict):
# MarkedString or MarkupContent
print(contents.get("value", str(contents)))
elif isinstance(contents, list):
for item in contents:
if isinstance(item, dict):
print(item.get("value", str(item)))
else:
print(item)
else:
print(contents)