summaryrefslogtreecommitdiff
path: root/scripts/debug_communications.sh
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/debug_communications.sh')
-rwxr-xr-xscripts/debug_communications.sh78
1 files changed, 78 insertions, 0 deletions
diff --git a/scripts/debug_communications.sh b/scripts/debug_communications.sh
new file mode 100755
index 0000000..23f97ee
--- /dev/null
+++ b/scripts/debug_communications.sh
@@ -0,0 +1,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