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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
#!/bin/bash -e
LAUNCHER_PATH="./dist/mac/bin"
CMD_DELAY=10
FILE_NAME="/tmp/example.java"
FILE_CONTENT="import java."
call_method()
# Outputs a request to the java-language-server for the desired method and args
{
local method="$1"
local args="$2"
local payload content_length
payload='{"method":"'"${method}"'","jsonrpc":"2.0",'"${args}"'}'
content_length=${#payload}
printf "\nCalled method: ${method}\n" >&2
printf 'Content-Type: application/vscode-jsonrpc; charset=utf-8\r\n'
printf "Content-Length: ${content_length}\r\n"
printf '\r\n'
printf "${payload}"
}
# Create an example java source file for the java-language-server to operate on
[ -e "${FILE_NAME}" ] || printf "${FILE_CONTENT}" > "${FILE_NAME}"
# Group the method calls for a simple edit session together and pipe them into
# the java-language-server. For documentation of the methods, please see the
# protocol definition linked from README.md.
{
call_method "initialize" \
'"id":1,
"params":{
"rootUri":"file://'"${FILE_NAME%/*}"'",
"processId":null,"trace":"verbose"
}'
sleep ${CMD_DELAY}
call_method "initialized" '"params":{}'
sleep ${CMD_DELAY}
call_method "textDocument/didOpen" \
'"params":{
"textDocument":{
"uri":"file://'"${FILE_NAME}"'",
"version":1,
"languageId":"java",
"text":"'"${FILE_CONTENT}"'"
}
}
}'
sleep ${CMD_DELAY}
## To test including an external jar, change java to android in FILE_CONTENTS and uncomment this.
# call_method "workspace/didChangeConfiguration" \
# '"params":{
# "settings":{
# "java":{
# "classPath":[
# "/usr/lib/android-sdk/platforms/android-24/android.jar"
# ],
# "externalDependencies":[]
# }
# }
# }'
# sleep ${CMD_DELAY}
call_method "textDocument/completion" \
'"id":2,
"params":{
"textDocument":{
"uri":"file://'"${FILE_NAME}"'"
},
"position":{
"character":'${#FILE_CONTENT}',
"line":0
}
}'
sleep ${CMD_DELAY}
} | "${LAUNCHER_PATH}"/launcher --quiet
|