/
pen-lsp-complete
executable file
·53 lines (36 loc) · 1.45 KB
/
pen-lsp-complete
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash
export TTY
# Number of characters. I'm not using lsp much, so keep it reasonable
max_context_length=300
export UPDATE=y
stdin_exists() {
! [ -t 0 ] && ! test "$(readlink /proc/$$/fd/0)" = /dev/null
}
if stdin_exists; then
# 0</dev/null env | tv &>/dev/null
# cmd "$@" | tv &>/dev/null
input_fp="$(pen-tf txt)"
if test -n "$POSITION"; then
line="$(echo "$POSITION" | cut -d : -f 1)"
col="$(echo "$POSITION" | cut -d : -f 2)"
this_line="$(( line + 1 ))"
next_line="$(( line + 2 ))"
sed -i "$next_line,\$d" "$input_fp"
sed -i "${this_line}s/^\\(.\\{$col\\}\\).*\$/\\1/" "$input_fp"
fi
# sps v "$input_fp"
exec < <(cat "$input_fp" | tail -c "-$max_context_length")
fi
# tv &>/dev/null
# cmd "$MYGIT/semiosis/pen.el/scripts/$sn" "$@" | tv &>/dev/null
# What should the output look like?
# It looks like json. I have to structure the json
# I should just intercept a request and investigate its structure
# stdin may exist and it should go into pen
# IFS= read -rd '' RESULTS < <(pena pf-generic-completion-50-tokens/1);typeset -p RESULTS &>/dev/null
# I have one result so far but make more and return JSON.
# The individual word doesn't matter at this stage.
# Perhaps I should just calculate it from the last word in the input.
# Yeah, I'll do that.
# jq '[.[] | {label: .}]'
ci pena pf-generic-completion-50-tokens/1 | jq .[] | sed -e 's/^"//' -e 's/"$//' | sed "s/\\\n/<pen-nl>/g"