Created
May 19, 2025 20:59
-
-
Save henriquegogo/719b5947821cf96b3be93ad5542fad98 to your computer and use it in GitHub Desktop.
Invoke code completion using only the terminal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
CODE='console.' | |
INIT='{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"processId":1,"rootUri":null,"capabilities":{}}}' | |
INITIALIZED='{"jsonrpc":"2.0","method":"initialized","params":{}}' | |
DIDOPEN="{\"jsonrpc\":\"2.0\",\"method\":\"textDocument/didOpen\",\"params\":{\"textDocument\":{\"uri\":\"file:///dev/null\",\"languageId\":\"typescript\",\"version\":1,\"text\":\"$CODE\"}}}" | |
COMPLETION="{\"jsonrpc\":\"2.0\",\"id\":2,\"method\":\"textDocument/completion\",\"params\":{\"textDocument\":{\"uri\":\"file:///dev/null\"},\"position\":{\"line\":0,\"character\":${#CODE}}}}" | |
{ | |
printf 'Content-Length: %d\r\n\r\n%s' $(echo -n "$INIT" | wc -c) "$INIT" | |
printf 'Content-Length: %d\r\n\r\n%s' $(echo -n "$INITIALIZED" | wc -c) "$INITIALIZED" | |
printf 'Content-Length: %d\r\n\r\n%s' $(echo -n "$DIDOPEN" | wc -c) "$DIDOPEN"; sleep 0.3 | |
printf 'Content-Length: %d\r\n\r\n%s' $(echo -n "$COMPLETION" | wc -c) "$COMPLETION"; sleep 0.3 | |
} | typescript-language-server --stdio | tail -n1 | jq -r '.result.items[].label' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment