richterger / Perl-LanguageServer

Language Server for Perl
Other
220 stars 53 forks source link

Language server crashes if two VS Code projects are opened #116

Closed izderadicka closed 2 years ago

izderadicka commented 2 years ago

Hi,

when I open two Perl projects in VS Code, in both Perl language server crashes with this message:

The Perl Language Server server crashed 5 times in the last 3 minutes. The server will not be restarted.

I'm on windows 10, but using WSL 2 - so project and language server in running in Linux - Ubuntu 20.04 (perl v5.30.0).

I was scanning through output of lang. server and found this repeating on second project/window:

[Info  - 9:28:34 AM] Connection to server got closed. Server will restart.
tcp server start listen on port 13603
tcp_bind: Address already in use at /usr/local/share/perl/5.30.0/Perl/LanguageServer.pm line 497.

and this on first project/window:

DAx: connect from 127.0.0.1:33036
DAx: got quit signal
[Info  - 9:28:32 AM] Connection to server got closed. Server will restart.

Full logs for both projects are attached first_project.txt second_project.txt .

ecos-ps commented 2 years ago

The Perl Language Server binds on a local port (see Debug Adapter Protocol). You are trying to open two projects that are bound to the same port. (See first line of your logs) That is not possible atm. If someone knows how to do this, feel free to contribute. For now you can set the local port in your workspace settings for your two projects to different ones. Open your settings with Ctrl + , and go to your workspace of each project. Insert into settings of one of your workspaces


"settings": {
    "perl.debugAdapterPort" : "13604", # another port than 13603
}
dliakh commented 2 years ago

Would it be possible to assign a random available port for every new running instance of the VS Code ?

ecos-ps commented 2 years ago

I don't think that this is a good idea. You should always set the port on your own.

dseynhae commented 2 years ago

The current behavior is that the Language Server pretty much crashes and burns... At least we could check if the requested port is available, and report if it is not.

💡 But as long as we have the OPTION to declare a range where the LanguageServer can open a port, I'm not sure why we would oppose automatic assignment, within the specified range?

👉 And a range of 1 port corresponds to the current behavior...

dliakh commented 2 years ago

Totally agree (and I'd say that may be a range starting from 1025 to 65534 by default) I tried changing the extension so that it would try assigning a random available port with get-port (https://github.com/sindresorhus/get-port) during the extension startup but didn't manage to build the resulting extention package to check whether it works or not (yet).

I realise that using get-port may cause a race condition but I tried checking the concept (if that works then maybe it may be improved then)

Ok, maybe somebody who knows how to build extensions properly, may try that: that looks like a simple change: adding get-port to the list of dependencies and using it to get a random available port (for example, when the port is set to some special value in the extension configuration, say 0 ( what is done now is it either reads a fixed value from the configuration or defaults to the fixed value 13603)

ecos-ps commented 2 years ago

I think you both got a point. I've tried building it with your suggestion. The module get-port looks promising (pun intended!) but i got problems building the extension. get-port has a dependency (node:net) that can't be resolved by now. I am a little bit confused why nodejs doesnt find one of its own core librarys... I am trying to get it working, but i am not a pro in Typescript and nodeJS, nevertheless i am optimistic.

ecos-ps commented 2 years ago

I tried several times but failed by now. I added some lines and my builds are successfull, but i can't activate the Extension in VSCode due to different errors. I think that get-port and VSCode Extensions are incompatible in the way I am trying to build them together in a VSCode Extension. Does anybody of you have more experience in NodeJS, Typescript and VSCode Extension? I think my mistake is somewhere in the Typescript or NodeJS Build Configuration.

FYI or if you wanna try on your own:

  1. git clone https://github.com/richterger/Perl-LanguageServer.git
  2. cd Perl-LanguageServer/clients/vscode/perl
  3. npm i get-port
  4. 
    import getPort from 'get-port' ;

export async function activate(context: vscode.ExtensionContext) { ...

let debug_adapter_port : string = await getPort({port: ( config.get('debugAdapterPort') || 13603 )}).toString() ; }


5. `npm i vsce -g` (see https://code.visualstudio.com/api/working-with-extensions/publishing-extension)
6. `vsce package` (to build extension, will create a .vsix-File)
7. Install Extension by going to "Extension"-Tab, click the three small points on the upper side of the extension modal, and click "Install from VSIX..."
sdondley commented 2 years ago

Hi, I'm totally new to LSP's and have never used vscode in my life. But I got it up and running fairly easily by installing Perl-LanguageServer and using using coc-nvim and coc-perl plugins in neovim.

However, if I open more than one perl file at a time, the LSP crashes.

I see the help above says to set a different port but the instructions are for vscode. Should I set those using :CocConfig instead?

Or maybe I should abandon coc and use neovim's lspconfig plugin?

Feeling a little lost.

ecos-ps commented 2 years ago

coc-perl plugins

Let's have a look at https://github.com/bmeneg/coc-perl :

The options are placed in the coc-settings.json (which can be opened directly issuing :CocConfig) and has the following format:

 {
     "perl": {
         "enable": true,
         "debugAdapterPort": "13604"
         "logLevel": 1,
     }
 }

The available options are exactly the same exposed by the language server.

sdondley commented 2 years ago

Thanks @ecos-ps. But what I don't understand is that if I open two files in the same directory, the server crashes. I assume the two files in the same directory will share the same coc-settings.json file which gets saved in the nvim directory. So if they are sharing the same coc-settings.json file, won't they still be using the same port?

Also, even if it is possible to set a different port for each file, it seems like a huge hassle to set up a new port every time I want to open a new perl file. Am I missing some basic knowledge here?

ecos-ps commented 2 years ago

@sdondley The Perl Language Server is built generic and for standalone use of the LSP (Language Server Procotol) and DAP (Debug Adapter Protocol). We offer a VSCode Extension since we are using it in everyday business, but I can't say anything about other IDEs.

Every IDE that implement LSP and DAP is capable of using it, but since i am not aware of all IDEs and their specific implementation, it is hard to help you. I think your questions are better suited in https://github.com/bmeneg/coc-perl because they state that they are using Perl Language Server with nvim and i am sure they can help! When they can't, nobody can by now.

sdondley commented 2 years ago

OK, thanks. I've asked for help at coc-perl. Thanks for your response and being helpful.

sdondley commented 2 years ago

I ended up ditching the coc plugin and just went with the nvim-lspconfig plugin. Seems to work well now.

ecos-ps commented 2 years ago

@sdondley Please feel free to write a short summary / introduction / tutorial for using Perl Language Server in nvim and push it to README.md in the repo and in https://github.com/bmeneg/coc-perl as well. This will help other people to work with it properly, contributions are welcome!

sdondley commented 2 years ago

@ecos-ps OK, but I could not get completion working at all. Any ideas what the problem might be?

I spent a lot of time trying to get P::LS and PLS working. Posted something to Reddit: https://www.reddit.com/r/neovim/comments/t37alb/anyone_out_there_have_nvimlspconfig_working_100/

I managed to get PLS working 100% after discovering an undocumented config setting for syntax checking but I have had not luck getting completion working with P::LS.

richterger commented 2 years ago

Perl::LanguageServer does not support completion (yet). Perl::LanguageServer has a debugger, which PLS doesn't have, on the other side PLS has some few features that Perl::LanguageServer does not have.

hakonhagland commented 2 years ago

I think that get-port and VSCode Extensions are incompatible in the way I am trying to build them together in a VSCode Extension.

@ecos-ps I investigated this a little bit. I do not know typescript, but it seems to be easy to understand with the help of google. I think we have run into these issues: https://github.com/microsoft/vscode/issues/130367, and https://github.com/electron/electron/issues/21457. I have added a possible workaround in #140 which currently does not work for me, so this is to be considered as work-in-progress.

richterger commented 2 years ago

Fixed with commit 0fabd96215814f0aad18cc7bbea84dc10a83d67b