Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Trouble Launching Language Server Jar in VSCode Extension
Trouble Launching Language Server Jar in VSCode Extension [message #1860967] Tue, 12 September 2023 12:47 Go to next message
Brandon Lewis is currently offline Brandon LewisFriend
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 #1860969 is a reply to message #1860967] Tue, 12 September 2023 12:56 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14736
Registered: July 2009
Senior Member
did you check the samples?

https://github.com/xtext/xtext-languageserver-example/blob/master/vscode-extension-self-contained/src/extension.ts

do you see the problem on windows or on linux?
there are two scripts created, at least by gradle

are you sure it is vscode that makes them not executable?
does the example work for you?
what command do you exactly execute when it fails locally?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com

[Updated on: Tue, 12 September 2023 13:00]

Report message to a moderator

Re: Trouble Launching Language Server Jar in VSCode Extension [message #1860970 is a reply to message #1860969] Tue, 12 September 2023 13:04 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14736
Registered: July 2009
Senior Member
here is what it looks like on the extension of the example built on mac

-rwxr-xr-x  1 dietrich  staff  9759 12 Sep 15:02 mydsl-socket
-rwxr-xr-x  1 dietrich  staff  4163 12 Sep 15:02 mydsl-socket.bat
-rwxr-xr-x  1 dietrich  staff  9793 12 Sep 15:02 mydsl-standalone
-rwxr-xr-x  1 dietrich  staff  4193 12 Sep 15:02 mydsl-standalone.bat


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: Trouble Launching Language Server Jar in VSCode Extension [message #1860971 is a reply to message #1860970] Tue, 12 September 2023 13:09 Go to previous messageGo to next message
Brandon Lewis is currently offline Brandon LewisFriend
Messages: 268
Registered: May 2012
Senior Member
Unfortunately, I can't run the gradlew command. It immediately complains that some items are Java 8 and some are Java 11 and it stops and does not complete. Since those items are not checked in - I can't see them because I can't get the gradle build to work.
Re: Trouble Launching Language Server Jar in VSCode Extension [message #1860972 is a reply to message #1860971] Tue, 12 September 2023 13:11 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14736
Registered: July 2009
Senior Member
do you use cmd? powershell? git bash? is JAVA_HOME set etc? (to 11 or 17)

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com

[Updated on: Tue, 12 September 2023 13:13]

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 Go to previous messageGo to next message
Brandon Lewis is currently offline Brandon LewisFriend
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

Re: Trouble Launching Language Server Jar in VSCode Extension [message #1860977 is a reply to message #1860974] Tue, 12 September 2023 18:24 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14736
Registered: July 2009
Senior Member
did you consider to change the launch script to start java with remote debugging. then you can check if anything arrives

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Previous Topic:New Xpand free Xpect version.
Next Topic:How can I prevent my Xtext Maven build from breaking every 3 months?
Goto Forum:
  


Current Time: Mon Dec 09 12:55:50 GMT 2024

Powered by FUDForum. Page generated in 0.03332 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top