From 90fdf58b3a206e19f34ca7fd2ebaff8367bf3525 Mon Sep 17 00:00:00 2001 From: cos Date: Wed, 3 Apr 2019 15:17:35 +0200 Subject: Initial addition of scripts/debug_communications.sh --- README.md | 6 +++- scripts/debug_communications.sh | 78 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 1 deletion(-) create mode 100755 scripts/debug_communications.sh diff --git a/README.md b/README.md index da5f645..e6bb222 100644 --- a/README.md +++ b/README.md @@ -167,6 +167,10 @@ For most requests, the vast majority of code can be erased, dramatically speedin The java service process will output a log file to stderr, which is visible in VSCode using View / Output, under "Java". +## Debugging protocol + +When having problems connecting with your (non-VS Code) editor and nothing else helps, `scripts/debug_communications.sh` might help you verify whether the issue is with the language-server or elsewhere. + ## Contributing If you have npm and maven installed, you should be able to install locally using @@ -175,4 +179,4 @@ If you have npm and maven installed, you should be able to install locally using npm install ./scripts/build.sh -At the time of this writing, the build only works on Mac, because of the way it uses JLink. However, it would be straightforward to fix this by changing `scripts/link_mac.sh` to be more like `scripts/link_windows.sh`. \ No newline at end of file +At the time of this writing, the build only works on Mac, because of the way it uses JLink. However, it would be straightforward to fix this by changing `scripts/link_mac.sh` to be more like `scripts/link_windows.sh`. 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 -- cgit v1.2.3