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_completion

36 lines
895 B
Python
Executable File

#!/usr/bin/env python3
# ollie:parallel read
# description: Get completions at cursor position from the language server.
# 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_completion <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("completion", file=filepath, line=line, col=col)
if not result:
sys.exit(0)
items = result.get("items", result) if isinstance(result, dict) else result
if not isinstance(items, list):
sys.exit(0)
for item in items[:20]:
label = item.get("label", "")
detail = item.get("detail", "")
if detail:
print(f"{label}\t{detail}")
else:
print(label)