superbol-studio-oss icon indicating copy to clipboard operation
superbol-studio-oss copied to clipboard

Allowing remote LSP connection in vscode API

Open Stevendeo opened this issue 2 years ago • 8 comments

This PR adds the required utils for connecting vscode editor to a remote LSP.

Stevendeo avatar Oct 30 '23 15:10 Stevendeo

@Stevendeo we you say "remote", do you mean the LSP has no longer access to the file-system where the project source code is? If that's the case, I think quite a bit of work is needed, and we should schedule for a much later milestone.

In particular, we should first handle some of the workspace-related requests.

nberth avatar Oct 30 '23 15:10 nberth

@Stevendeo we you say "remote", do you mean the LSP has no longer access to the file-system where the project source code is? If that's the case, I think quite a bit of work is needed, and we should schedule for a much later milestone.

In particular, we should first handle some of the workspace-related requests.

We discussed this particular issue with Fabrice the other day, so I was making a few tests. This PR is still in draft and should not have impact on the project anyway.

Stevendeo avatar Oct 30 '23 16:10 Stevendeo

@Stevendeo we you say "remote", do you mean the LSP has no longer access to the file-system where the project source code is? If that's the case, I think quite a bit of work is needed, and we should schedule for a much later milestone.

In particular, we should first handle some of the workspace-related requests.

Oh, and no I am just talking about the lsp being accessible through a specific address & port. I think this step is necessary before having the whole project in remote.

Stevendeo avatar Oct 30 '23 16:10 Stevendeo

Ok now I start seeing what development with jsoo looks like ;-)

To be fair, it should and could probably be cleaner. The problem is here that I did not find the interface between js of ocaml and the library used in the project, nor a module for websockets. I'm pretty sure there is one, but for testing I don't need it and I can do dirty things (until it breaks, because it will).

Stevendeo avatar Nov 15 '23 09:11 Stevendeo

I did not test it yet, I did not manage to find the proper combination to make it work, as superbol expects to receive something directly from stdin and not as an argument. Is there a way to call something like superbol-free lsp file.json ?

EDIT: nevermind, by writing this message I found how to.

Stevendeo avatar Nov 15 '23 13:11 Stevendeo

Okay, so it manages to establish a connection, but I think something is wrong when actually sending the data.

Stevendeo avatar Nov 15 '23 13:11 Stevendeo

I added a script to simulate a remote LSP in local. For now it only allows to receive data and give it to the LSP, which seems to have some trouble to decode the request.

Stevendeo avatar Nov 15 '23 14:11 Stevendeo

So this "just" needs a move + adjustment of the docs + rebase to be merged?

GitMensch avatar Aug 13 '24 10:08 GitMensch

Doc updated & branch rebased!

Stevendego avatar Aug 23 '24 11:08 Stevendego

While trying to build the VSIX, I get an error like:

✘ [ERROR] Could not resolve "ws"

    _build/default/src/vscode/superbol-vscode-platform/superbol_vscode_platform.bc.js:50:41:
      50 │    joo_global_object.webSocket = require("ws");
         ╵                                          ~~~~

  You can mark the path "ws" as external to exclude it from the bundle, which will remove this
  error. You can also surround this "require" call with a try/catch block to handle this failure at
  run-time instead of bundle-time.

Do you also get such an error?

nberth avatar Aug 23 '24 13:08 nberth

I'd say there is a missing dependency somewhere, I don't have any error

EDIT : $ npm install ws?

Stevendego avatar Aug 23 '24 14:08 Stevendego

I'd say there is a missing dependency somewhere, I don't have any error

EDIT : $ npm install ws?

Yes I think that should be a dependency to declare in package.json. This file is actually generated from data in src/lsp/superbol_free_lib/vscode_extension.ml. I would add something like "ws", "^8" in the ~dependencies list there.

Edit: What version of ws do you have?

nberth avatar Aug 23 '24 14:08 nberth

What version of ws do you have?

[email protected] (probably not the latest version, I did not update anything since a looooong time)

Stevendego avatar Aug 23 '24 14:08 Stevendego

Ok thanks. Note, though: you need to make package.json and then amend the last commit with the generated package.json (the CI checks the generated file does not differ from the package.json in the commit).

nberth avatar Aug 23 '24 14:08 nberth

Ouch…

[Error - 4:51:07 PM] SuperBOL Language Server client: couldn't create connection to server.
ReferenceError: joo_global_object is not defined
	at eval (eval at caml_js_eval_string (/tmp/vscode-exts/ocamlpro.superbol-0.1.4/_dist/superbol-vscode-platform-bundle.js:24526:16), <anonymous>:1:1)
	at caml_js_eval_string (/tmp/vscode-exts/ocamlpro.superbol-0.1.4/_dist/superbol-vscode-platform-bundle.js:24526:16)
	at caml_call1 (/tmp/vscode-exts/ocamlpro.superbol-0.1.4/_dist/superbol-vscode-platform-bundle.js:44842:57)
	at k$0 (/tmp/vscode-exts/ocamlpro.superbol-0.1.4/_dist/superbol-vscode-platform-bundle.js:46114:18)
	at caml_call1 (/tmp/vscode-exts/ocamlpro.superbol-0.1.4/_dist/superbol-vscode-platform-bundle.js:38481:57)
	at make_printf$0 (/tmp/vscode-exts/ocamlpro.superbol-0.1.4/_dist/superbol-vscode-platform-bundle.js:40953:20)
	at make_printf (/tmp/vscode-exts/ocamlpro.superbol-0.1.4/_dist/superbol-vscode-platform-bundle.js:41330:33)
	at width (/tmp/vscode-exts/ocamlpro.superbol-0.1.4/_dist/superbol-vscode-platform-bundle.js:40934:20)
	at caml_call_gen (/tmp/vscode-exts/ocamlpro.superbol-0.1.4/_dist/superbol-vscode-platform-bundle.js:23284:20)
	at Object.caml_call_gen (/tmp/vscode-exts/ocamlpro.superbol-0.1.4/_dist/superbol-vscode-platform-bundle.js:23289:18)
	at caml_call3 (/tmp/vscode-exts/ocamlpro.superbol-0.1.4/_dist/superbol-vscode-platform-bundle.js:54533:81)
	at njs_stream_of_string (/tmp/vscode-exts/ocamlpro.superbol-0.1.4/_dist/superbol-vscode-platform-bundle.js:54833:16)
	at caml_call1 (/tmp/vscode-exts/ocamlpro.superbol-0.1.4/_dist/superbol-vscode-platform-bundle.js:57328:57)
	at _t_ (/tmp/vscode-exts/ocamlpro.superbol-0.1.4/_dist/superbol-vscode-platform-bundle.js:57363:32)
	at caml_call1 (/tmp/vscode-exts/ocamlpro.superbol-0.1.4/_dist/superbol-vscode-platform-bundle.js:54527:57)
	at /tmp/vscode-exts/ocamlpro.superbol-0.1.4/_dist/superbol-vscode-platform-bundle.js:54881:23
	at caml_call_gen (/tmp/vscode-exts/ocamlpro.superbol-0.1.4/_dist/superbol-vscode-platform-bundle.js:23284:20)
	at /tmp/vscode-exts/ocamlpro.superbol-0.1.4/_dist/superbol-vscode-platform-bundle.js:28257:18
	at LanguageClient.createMessageTransports (/tmp/vscode-exts/ocamlpro.superbol-0.1.4/_dist/superbol-vscode-platform-bundle.js:17297:18)
	at LanguageClient.<anonymous> (/tmp/vscode-exts/ocamlpro.superbol-0.1.4/_dist/superbol-vscode-platform-bundle.js:15499:41)
	at Generator.next (<anonymous>)
	at /tmp/vscode-exts/ocamlpro.superbol-0.1.4/_dist/superbol-vscode-platform-bundle.js:61:61
	at new Promise (<anonymous>)
	at __async (/tmp/vscode-exts/ocamlpro.superbol-0.1.4/_dist/superbol-vscode-platform-bundle.js:45:10)
	at LanguageClient.createConnection (/tmp/vscode-exts/ocamlpro.superbol-0.1.4/_dist/superbol-vscode-platform-bundle.js:15492:16)
	at LanguageClient.<anonymous> (/tmp/vscode-exts/ocamlpro.superbol-0.1.4/_dist/superbol-vscode-platform-bundle.js:15083:43)
	at Generator.next (<anonymous>)
	at /tmp/vscode-exts/ocamlpro.superbol-0.1.4/_dist/superbol-vscode-platform-bundle.js:61:61
	at new Promise (<anonymous>)
	at __async (/tmp/vscode-exts/ocamlpro.superbol-0.1.4/_dist/superbol-vscode-platform-bundle.js:45:10)
	at LanguageClient.start (/tmp/vscode-exts/ocamlpro.superbol-0.1.4/_dist/superbol-vscode-platform-bundle.js:15051:16)
	at start (/tmp/vscode-exts/ocamlpro.superbol-0.1.4/_dist/superbol-vscode-platform-bundle.js:54891:48)
	at caml_call1 (/tmp/vscode-exts/ocamlpro.superbol-0.1.4/_dist/superbol-vscode-platform-bundle.js:57328:57)
	at _r_ (/tmp/vscode-exts/ocamlpro.superbol-0.1.4/_dist/superbol-vscode-platform-bundle.js:57380:21)
	at caml_call1 (/tmp/vscode-exts/ocamlpro.superbol-0.1.4/_dist/superbol-vscode-platform-bundle.js:47696:57)
	at fulfilled_safe (/tmp/vscode-exts/ocamlpro.superbol-0.1.4/_dist/superbol-vscode-platform-bundle.js:47728:18)
	at caml_call_gen (/tmp/vscode-exts/ocamlpro.superbol-0.1.4/_dist/superbol-vscode-platform-bundle.js:23284:20)
	at /tmp/vscode-exts/ocamlpro.superbol-0.1.4/_dist/superbol-vscode-platform-bundle.js:25313:21

nberth avatar Aug 23 '24 14:08 nberth

@nberth Is there anything missing apart from the Changelog entry? Would it be reasonable to pull that in soon?

GitMensch avatar Sep 01 '24 14:09 GitMensch

@nberth Is there anything missing apart from the Changelog entry? Would it be reasonable to pull that in soon?

I think a better error reporting might be relevant still. At the moment if the TCP connection fails VSCode reports a lot of errors to the user, none of which seeming to indicate the root cause of the issue. Fixing that may be delayed though, as otherwise remote connection over TCP is operational (a more secure option, e.g with TLS, could be better — but that's definitely for later).

@Stevendeo I think parts of the new code is not in the proper module. I have a commit ready to move it (did it when I tried to fix error reporting … to no avail alas) ; may I push directly on your branch?

nberth avatar Sep 02 '24 07:09 nberth

may I push directly on your branch?

Yes of course; tell me when you're done so I can push a few last updates (Changelog + doc)

Stevendeo avatar Sep 02 '24 12:09 Stevendeo

may I push directly on your branch?

Yes of course; tell me when you're done so I can push a few last updates (Changelog + doc)

Actually I opened a PR on your repository so you can see the changes first.

nberth avatar Sep 02 '24 13:09 nberth

We can merge after the forgotten comment has been removed.

Done and ready to merge!

Stevendeo avatar Sep 03 '24 12:09 Stevendeo