Trouble Launching Language Server Jar in VSCode Extension [message #1860967] |
Tue, 12 September 2023 12:47 |
Brandon Lewis Messages: 268 Registered: May 2012 |
Senior Member |
|
|
I'm closer than I've ever been to getting a basic VSCode extension working with the LSP support, but I'm still a failure. :-(
I've built a LS that appears to work. I've built it from the Xtext example project - mydsl. Built in Eclipse 2022-06 using Xtext 27.0 using maven install. I've been able to launch that server and prove that it works by launching a Generic Text Editor in my 2022-06 Eclipse (notwithstanding the bugs in the packaged LSP4J that don't highlight errors, but I get content suggestions so I know it works.)
Troubles I'm still having:
I package the extension using vsce on my Windows machine (it's not easy for me to install stuff on the company's load share linux systems, so I have to do some things on Windows). The packaging is invoked on Windows but pointing to the mounted linux disk.
These next questions are client/node based - which I know aren't directly xtext questions, but they are things it seems people must've struggled with in creating these extensions.
vsce changes permissions of my launch scripts in src/bin/mydsl-standalone and makes it not executable. Which means I have to manually change permissions on this script once the extension is installed within VSCode. Bizarre. Why does it do this?
Second problem - and the show stopper - no matter what I do, when I load a file with the *.mydsl extension, my launcher script runs, but the server will not start. I get the message:
Quote:Error: Unable to access jarfile org.xtext.example.mydsl.ide-1.0.0-SNAPSHOT-ls.jar
[Error - 5:29:04 AM] Server initialization failed.
Message: Cannot call write after a stream was destroyed
Code: -32099
I can execute this launcher and access the jar only if I'm in the src/bin/ directory where it is located. I get the same message if I invoke the launcher manually from another directory. I'm spelling it correctly. I an invoke from that directory but not from another directory.
But VSCode _must_ be able to use the relative path to the jar right? It has to because it can't know where the user's extension will be stored.
script contents:
/usr/lib/jvm/jre-11/bin/java -jar org.xtext.example.mydsl.ide-1.0.0-SNAPSHOT-ls.jar
note that "java" defaults to Java 1.8 on these machines and to run Java 11, I have to point to a specific Java 11 jvm. I have not aliased "java" or changed env var JAVA_HOME.
Any ideas on what dumb thing I'm doing? This seems like it obviously must work like this as every example I can find specifies this launcher script. I've debugged that the server works in Eclipse. Why can't VSCode "access" this jar? I've double checked all the "file not found" type problems and it's not that.
[Updated on: Tue, 12 September 2023 12:49] Report message to a moderator
|
|
|
|
|
|
|
Re: Trouble Launching Language Server Jar in VSCode Extension [message #1860974 is a reply to message #1860972] |
Tue, 12 September 2023 17:45 |
Brandon Lewis Messages: 268 Registered: May 2012 |
Senior Member |
|
|
Okay. I think I've figured out the "unable to access jar" problem. Basically it was a relative file pathing problem. Discovered this by reading about the strange characters in the mydsl-standalon.bat file I copied from somewhere else that contains the folllwing special string "%~dp0"
java -jar %~dp0\org.xtext.example.mydsl.ide-1.0.0-SNAPSHOT-ls.jar
The special "%~dp0" string gets translated to "the directory where this batch file exists". Figuring that out, I changed my unix side mydsl-standalone script to be:
#!/bin/bash
THIS_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
/usr/lib/jvm/jre-11/bin/java -jar $THIS_SCRIPT_DIR/org.xtext.example.mydsl.ide-1.0.0-SNAPSHOT-ls.jar
Now I can actually see the server being launched on linux. Unfortunately, I'm onto the next problem now - the client won't connect to it:
Quote:[Error - 10:38:38 AM] Client Xtext Server: connection to server is erroring. Shutting down server.
[Error - 10:38:38 AM] Stopping server failed
Error: Client is not running and can't be stopped. It's current state is: starting
at LanguageClient.shutdown (/home/bralewis/.vscode/extensions/xtext.xtext-vscode-example-0.0.335/node_modules/vscode-languageclient/lib/common/client.js:914:19)
at LanguageClient.stop (/home/bralewis/.vscode/extensions/xtext.xtext-vscode-example-0.0.335/node_modules/vscode-languageclient/lib/common/client.js:885:21)
at LanguageClient.stop (/home/bralewis/.vscode/extensions/xtext.xtext-vscode-example-0.0.335/node_modules/vscode-languageclient/lib/node/main.js:150:22)
at LanguageClient.handleConnectionError (/home/bralewis/.vscode/extensions/xtext.xtext-vscode-example-0.0.335/node_modules/vscode-languageclient/lib/common/client.js:1146:18)
at process.processTicksAndRejections (node:internal/process/task_queues:96:5)
Even less helpful/stranger behavior on windows, I can see the Java being started (the JVM runs in Task Manager), but I get no error messages, but I also don't get any code errors, code completion - only textmate highlighting which is client side. The textmate highlighting and Select Language Mode at least tell me that my VSCode extension code is recognizing the file extension etc.
[Updated on: Tue, 12 September 2023 17:47] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.03332 seconds