Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Language Server Protocol support #31

Merged
merged 1 commit into from Oct 17, 2017
Merged

Conversation

kubawolanin
Copy link
Collaborator

So here we go :-)
Currently don't have a way to test this since there's no Xtext with LSP available on ESH yet.
Closes #3

CC: @kaikreuzer @SJKA

Signed-off-by: Kuba Wolanin hi@kubawolanin.com (github: kubawolanin)

@sjsf
Copy link
Contributor

sjsf commented Aug 17, 2017

Wow, that was quicky! I guess it somehow backfired, the ball is in our field now 😄
I will see what I can do wrt getting the LSP stuff going in ESH. It needs an Xtext upgrade first - I started on that already...

@Confectrician
Copy link
Collaborator

I will try to test it out a bit during the next days. :)

@kubawolanin
Copy link
Collaborator Author

kubawolanin commented Aug 21, 2017

This is how it looks like right now:
lsp

It's not connected anywhere, thus these errors :-)

In order to display the Output tab simply hit Ctrl/Cmd + Shift + U
Then in the dropdown on the right hand side choose 'openHAB Server'.

Quick question to @SJKA - my current implementation assumes that LSP will be hosted on 5007 port. Is this a correct port? I will most probably make it configurable in the VSCode user/workspace settings anyways. Just wanted to make sure what's the default one.

Cheers!

@sjsf
Copy link
Contributor

sjsf commented Aug 23, 2017

You're way to quick for me 😄

I just finished eclipse-archived/smarthome#4100. Once it's merged I will look into how the LSP bindings can be generated and how we can expose them within the server. I will try to use 5007 port then. However, I'm not even sure if we will be able to use the same port for all DSLs, or if we will have to use different ones per language.

@kubawolanin
Copy link
Collaborator Author

Hey @SJKA 👋

Since OH distro 1048, there's your Language Server PR available.
Could you tell me how can I run it locally so I can test it?
I have OH2 on Raspberry PI 3. I see that there's no 5007 port active on my machine.
Do I need to enable/activate some Karaf feature in order to make LSP work?
Or should I rather build ESH from sources?

Thanks in advance!

@kubawolanin
Copy link
Collaborator Author

I struggle with getting any response from the LSP on my RPi3 environment (wrt openhab/openhab-distro#547 (comment))
@SJKA would you mind taking a look?

Logs are telling me that I'm successfully connecting to the server:

==> /var/log/openhab2/openhab.log <==
2017-10-02 18:22:34.723 [DEBUG] [thome.model.lsp.internal.ModelServer] - Going to wait for a client to connect
2017-10-02 18:22:34.723 [DEBUG] [thome.model.lsp.internal.ModelServer] - Client /192.168.0.YYY:50506 connected

And here's the proof that 5007 port is indeed open:

[18:26:40] myusername@myraspberry:~$ sudo netstat -pln | grep 5007
tcp6       0      0 :::5007                 :::*                    LISTEN      3194/java

But I get no output on vscode whatsoever 🤔
lsp

My vscode workspace settings:

    "openhab.host": "192.168.0.XXX",
    "openhab.port": "8080",
    "openhab.lspPort": 5007,

In Karaf I've also set lsp logging level to debug:

openhab> log:set debug org.eclipse.smarthome.model.lsp
openhab> log:display org.eclipse.smarthome.model.lsp

Thanks in advance!

@kubawolanin
Copy link
Collaborator Author

kubawolanin commented Oct 13, 2017

@kaikreuzer @SJKA I really need your help here in order to make it work :-)
I'm facing an issue with connectivity and couldn't successfully test the language server.

I have this very branch unchanged connecting to my remote OH instance ("openhab.host": "home" but tried an IP address too).
Even though the logs are saying that the client is connected to LSP:

==> /var/log/openhab2/openhab.log <==
2017-10-13 18:43:42.868 [DEBUG] [thome.model.lsp.internal.ModelServer] - Going to wait for a client to connect
2017-10-13 18:43:42.868 [DEBUG] [thome.model.lsp.internal.ModelServer] - Client /192.168.0.XXX:50684 connected

VSCode throws an error after a while:
vscode

On the OH side, lsp add-on is installed from within addons.cfg file:

# A comma-separated list of miscellaneous services to install (e.g. "myopenhab")
misc = gcal1,openhabcloud,restdocs,market,ruleengine,hueemulation,lsp
openhab> bundle:list | grep Language
212 │ Active    │  80 │ 0.9.0.201709260841     │ Eclipse SmartHome Language Server

Am I missing something there?

@SJKA I would really appreciate if you could test the scenario again like you did here: eclipse-archived/smarthome#4148 (comment).

I'm really close to have this completed :)

Cheers and thanks in advance! 👍

@kaikreuzer
Copy link
Member

Hey @kubawolanin, I am sorry, but I myself have no clue about how the LSP stuff works - I very much hope that @SJKA will respond soon and help you out on it!

@sjsf
Copy link
Contributor

sjsf commented Oct 16, 2017

I have no idea why I didn't receive these notifications, but nowI have seen it. Sorry!

I'll follow your traces and try figuring out what's needed in order to make it work initially. Keep you posted!

@sjsf
Copy link
Contributor

sjsf commented Oct 16, 2017

hmmm, looks like I somehow screwed up the OSGi service injection into the guice module 😩 .
I created eclipse-archived/smarthome#4422 to fix this.

@kaikreuzer
Copy link
Member

@kubawolanin Latest distro 1063 should already contain that fix!

@kubawolanin
Copy link
Collaborator Author

Thanks @kaikreuzer! @SJKA thank you so much for the quick fix!

@kubawolanin
Copy link
Collaborator Author

@SJKA sorry to tell you but it still doesn't work on distro 1063 :(

2017-10-16 20:59:29.754 [DEBUG] [thome.model.lsp.internal.ModelServer] - Going to wait for a client to connect
2017-10-16 20:59:29.754 [DEBUG] [thome.model.lsp.internal.ModelServer] - Client /192.168.0.6:52064 connected

VSCode output after a while:

[Error - 21:00:54] Connection to server is erroring. Shutting down server.
[Error - 21:00:54] Connection to server is erroring. Shutting down server.
[Error - 21:00:54] Connection to server is erroring. Shutting down server.
[Error - 21:00:54] Connection to server is erroring. Shutting down server.
[Error - 21:00:54] Connection to server is erroring. Shutting down server.
[Error - 21:00:54] Connection to server is erroring. Shutting down server.

Do you have any specific environment that I can reproduce to successfully test it?

Here's a zipped, packaged extension so you don't need to build it yourself.
openhab-0.1.0.vsix.zip

Just hit Ctrl/Cmd + Shift + X to go to Extensions pane and click on ... icon. After that hit 'Install from VSIX...' and select unzipped file.

Thank you.

@sjsf
Copy link
Contributor

sjsf commented Oct 17, 2017

Indeed, I have the following in the logs:

1) Error injecting constructor, java.lang.NoSuchMethodError: org.eclipse.xtext.xbase.lib.CollectionLiterals.newHashMap()Ljava/util/HashMap;
  at org.eclipse.xtext.ide.server.WorkspaceManager.<init>(Unknown Source)
  while locating org.eclipse.xtext.ide.server.WorkspaceManager
    for parameter 0 at org.eclipse.xtext.ide.server.LanguageServerImpl.setWorkspaceManager(Unknown Source)
  while locating org.eclipse.xtext.ide.server.LanguageServerImpl

1 error
	at com.google.inject.internal.InjectorImpl$4.get(InjectorImpl.java:987)
	at com.google.inject.internal.InjectorImpl.getInstance(InjectorImpl.java:1013)
	at org.eclipse.smarthome.model.lsp.internal.ModelServer.handleConnection(ModelServer.java:90)
	at org.eclipse.smarthome.model.lsp.internal.ModelServer.lambda$1(ModelServer.java:74)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NoSuchMethodError: org.eclipse.xtext.xbase.lib.CollectionLiterals.newHashMap()Ljava/util/HashMap;
	at org.eclipse.xtext.ide.server.WorkspaceManager.<init>(WorkspaceManager.java:64)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at com.google.inject.internal.DefaultConstructionProxyFactory$1.newInstance(DefaultConstructionProxyFactory.java:85)
	at com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:85)
	at com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:254)
	at com.google.inject.internal.SingleParameterInjector.inject(SingleParameterInjector.java:38)
	at com.google.inject.internal.SingleParameterInjector.getAll(SingleParameterInjector.java:62)
	at com.google.inject.internal.SingleMethodInjector.inject(SingleMethodInjector.java:83)
	at com.google.inject.internal.MembersInjectorImpl.injectMembers(MembersInjectorImpl.java:110)
	at com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:94)
	at com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:254)
	at com.google.inject.internal.InjectorImpl$4$1.call(InjectorImpl.java:978)
	at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1024)
	at com.google.inject.internal.InjectorImpl$4.get(InjectorImpl.java:974)
	... 4 more

The xtext/xbase bundle versions are exactly the same as in the IDE. I will try to make sense of this...

@sjsf
Copy link
Contributor

sjsf commented Oct 17, 2017

@maggu2810 could it be that the o.e.xtext.ide bundle which you recompiled in order to get rid of the equinox dependency was compiled agains a o.e.xtext.xbase.lib version other than 2.12.0.v20170518-0757?

@sjsf
Copy link
Contributor

sjsf commented Oct 17, 2017

To answer my previous question: The build indeed drags in org.eclipse.xtext.xbase.lib-2.13.0.RC1.jar, which would explain the troubles...

Now I "only" need to figure out how to nail this version down in the xtext-core gradle build.

@sjsf
Copy link
Contributor

sjsf commented Oct 17, 2017

I found a way to solve the issue, but it might take a little to get it uploaded and run it through the build chain.

So here is a quick workaround for you. Assuming you already have openHAB running with the Language Server extension installed. Via the Karaf OSGi console, run

bundle:list

and identify the "Xtext IDE Code" entry. Should be something like this:

214 │ Active    │  80 │ 2.12.0.v20170921-1347  │ Xtext IDE Core

Remember its number and stop & uninstall it (using the number it has in your system, of course):

stop 214
uninstall 214

Then download this file and unzip it somewhere (github doesn't allow JARs, but ZIPped JARs are okay 😉 ): org.eclipse.xtext.ide-2.12.0.sp1.jar.zip

Install it from the Karaf OSGi console with

bundle:install file:///Users/kuba/somewhere/org.eclipse.xtext.ide-2.12.0.sp1.jar

It gave me an error about the same singleton bundle already being used - a restart of openHAB will be sufficient to fix this.

@sjsf
Copy link
Contributor

sjsf commented Oct 17, 2017

PS: I just fixed the download link as I noticed it was broken. Not sure if you saw it...

In any case, this is pretty cool:

image

@kubawolanin
Copy link
Collaborator Author

Hey @SJKA big thanks for helping me out with this! :)

Just checked it on a fresh machine. Installed openhab-2.2.0-SNAPSHOT lastSuccessfulBuild from Cloudbees + LSP add-on along with JAR you provided.

At first I had some weird issues:

2017-10-17 14:17:35.008 [INFO ] [thome.model.lsp.internal.ModelServer] - Language Server started on port 5007
2017-10-17 14:17:35.090 [INFO ] [panel.internal.HABPanelDashboardTile] - Started HABPanel at /habpanel
2017-10-17 14:17:35.484 [INFO ] [basic.internal.servlet.WebAppServlet] - Started Basic UI at /basicui/app
2017-10-17 14:17:35.541 [INFO ] [arthome.ui.paper.internal.PaperUIApp] - Started Paper UI at /paperui
2017-10-17 14:17:38.002 [INFO ] [panel.internal.HABPanelDashboardTile] - Stopped HABPanel
2017-10-17 14:17:38.289 [INFO ] [arthome.ui.paper.internal.PaperUIApp] - Stopped Paper UI
2017-10-17 14:17:38.308 [ERROR] [thome.model.lsp.internal.ModelServer] - Error accepting the client connection
java.net.SocketException: socket closed
	at java.net.DualStackPlainSocketImpl.accept0(Native Method) ~[?:?]
	at java.net.DualStackPlainSocketImpl.socketAccept(DualStackPlainSocketImpl.java:131) ~[?:?]
	at java.net.AbstractPlainSocketImpl.accept(AbstractPlainSocketImpl.java:409) ~[?:?]
	at java.net.PlainSocketImpl.accept(PlainSocketImpl.java:199) ~[?:?]
	at java.net.ServerSocket.implAccept(ServerSocket.java:545) ~[?:?]
	at java.net.ServerSocket.accept(ServerSocket.java:513) ~[?:?]
	at org.eclipse.smarthome.model.lsp.internal.ModelServer.listen(ModelServer.java:72) ~[?:?]
	at org.eclipse.smarthome.model.lsp.internal.ModelServer.lambda$0(ModelServer.java:50) ~[?:?]
	at java.lang.Thread.run(Thread.java:748) [?:?]
2017-10-17 14:17:38.395 [INFO ] [basic.internal.servlet.WebAppServlet] - Stopped Basic UI

But started again on a fresh OH instance and I've managed to get it work :-)

it-works
(The font with this fancy ligature is https://github.com/tonsky/FiraCode) ;-)

Thank you so much!

@sjsf
Copy link
Contributor

sjsf commented Oct 17, 2017

Don't get confused by the error message in the log - maybe it is a normal case which happens when the client closes the connection and it is just a mistake to log it as an error. Fine tuning 😉

Glad to see it's working!!! I will take care to get the correctly patched xtext file into ESH and then into openHAB as quickly as possible (before the weekend in any case...). Let me know if there is anything else where I can help.

LSP cleanup, final touches

Signed-off-by: Kuba Wolanin <hi@kubawolanin.com>
@kubawolanin kubawolanin changed the title [WIP] Language Server Protocol support Language Server Protocol support Oct 17, 2017
@kubawolanin kubawolanin merged commit aa64c9f into openhab:master Oct 17, 2017
@kubawolanin kubawolanin deleted the lsp branch October 17, 2017 18:04
@Confectrician
Copy link
Collaborator

Great improvement!
Thank you all for your effort. :)

@kaikreuzer
Copy link
Member

@kubawolanin distro 1065 is ready for testing!

@kubawolanin
Copy link
Collaborator Author

@kaikreuzer much appreciated! :)

@kubawolanin
Copy link
Collaborator Author

@kaikreuzer @SJKA distro 1065 is giving me the following stack trace:

==> /var/log/openhab2/openhab.log <==
2017-10-18 20:02:25.580 [DEBUG] [thome.model.lsp.internal.ModelServer] - Going to wait for a client to connect
2017-10-18 20:02:25.586 [DEBUG] [thome.model.lsp.internal.ModelServer] - Client /192.168.0.XXX:50669 connected
2017-10-18 20:02:28.533 [ERROR] [eclipse.lsp4j.jsonrpc.RemoteEndpoint] - Internal error: java.lang.reflect.InvocationTargetException
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
	at org.eclipse.lsp4j.jsonrpc.services.GenericEndpoint.lambda$null$0(GenericEndpoint.java:53) ~[262:org.eclipse.lsp4j.jsonrpc:0.2.1.v20170706-0855]
	at org.eclipse.lsp4j.jsonrpc.services.GenericEndpoint.request(GenericEndpoint.java:105) [262:org.eclipse.lsp4j.jsonrpc:0.2.1.v20170706-0855]
	at org.eclipse.lsp4j.jsonrpc.RemoteEndpoint.handleRequest(RemoteEndpoint.java:203) [262:org.eclipse.lsp4j.jsonrpc:0.2.1.v20170706-0855]
	at org.eclipse.lsp4j.jsonrpc.RemoteEndpoint.consume(RemoteEndpoint.java:139) [262:org.eclipse.lsp4j.jsonrpc:0.2.1.v20170706-0855]
	at org.eclipse.lsp4j.jsonrpc.json.StreamMessageProducer.handleMessage(StreamMessageProducer.java:149) [262:org.eclipse.lsp4j.jsonrpc:0.2.1.v20170706-0855]
	at org.eclipse.lsp4j.jsonrpc.json.StreamMessageProducer.listen(StreamMessageProducer.java:77) [262:org.eclipse.lsp4j.jsonrpc:0.2.1.v20170706-0855]
	at org.eclipse.lsp4j.jsonrpc.json.ConcurrentMessageProcessor.run(ConcurrentMessageProcessor.java:84) [262:org.eclipse.lsp4j.jsonrpc:0.2.1.v20170706-0855]
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:?]
	at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:?]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [?:?]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [?:?]
	at java.lang.Thread.run(Thread.java:745) [?:?]
Caused by: java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:?]
	at org.eclipse.lsp4j.jsonrpc.services.GenericEndpoint.lambda$null$0(GenericEndpoint.java:51) ~[?:?]
	... 11 more
Caused by: java.lang.IllegalArgumentException: Missing scheme
	at java.nio.file.Paths.get(Paths.java:134) ~[?:?]
	at org.eclipse.xtext.ide.server.UriExtensions.toPath(UriExtensions.java:36) ~[?:?]
	at org.eclipse.xtext.ide.server.UriExtensions.toPath(UriExtensions.java:31) ~[?:?]
	at org.eclipse.xtext.ide.server.LanguageServerImpl.getBaseDir(LanguageServerImpl.java:230) ~[?:?]
	at org.eclipse.xtext.ide.server.LanguageServerImpl.initialize(LanguageServerImpl.java:176) ~[?:?]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:?]
	at org.eclipse.lsp4j.jsonrpc.services.GenericEndpoint.lambda$null$0(GenericEndpoint.java:51) ~[?:?]
	... 11 more

I've updated the distro and restarted my OH several times.
Also, seems that Xtext IDE Core didn't update.

openhab> bundle:list |grep IDE
263 │ Active    │  80 │ 0.9.0.201710180819     │ Eclipse SmartHome Item Model IDE
265 │ Active    │  80 │ 0.9.0.201710180819     │ Eclipse SmartHome Persistence Model IDE
266 │ Active    │  80 │ 0.9.0.201710180819     │ Eclipse SmartHome Rule Model IDE
267 │ Active    │  80 │ 0.9.0.201710180819     │ Eclipse SmartHome Script Model IDE
268 │ Active    │  80 │ 0.9.0.201710180819     │ Eclipse SmartHome Sitemap Model IDE
269 │ Active    │  80 │ 0.9.0.201710180819     │ Eclipse SmartHome Thing Model IDE
270 │ Active    │  80 │ 2.12.0.v20171017-1700  │ Xtext IDE Core
271 │ Active    │  80 │ 2.12.0.v20170519-0752  │ Xbase Generic IDE Services

I'll stick with the previous build for the demo on Sunday ;-)

Thank you!

@sjsf
Copy link
Contributor

sjsf commented Oct 19, 2017

Xtext IDE Core version "2.12.0.v20171017-1700" is correct. However, I couldn't reproduce this error. I downloaded the distro from here, using the "demo" setup and installed the LSP extension. Works like a charm.

As you said you updated your distro - did you delete the cache and tmp folders? In any case, good that you have a working setup for the weekend.

ghys pushed a commit to ghys/smarthome that referenced this pull request Oct 2, 2018
…ived#4422)

...doing it in a similar way as in eclipse-archived#4278

relates to #openhab/openhab-vscode#31
Signed-off-by: Simon Kaufmann <simon.kfm@googlemail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants