emacs-lsp / lsp-mode

Emacs client/library for the Language Server Protocol
https://emacs-lsp.github.io/lsp-mode
GNU General Public License v3.0
4.8k stars 892 forks source link

`csharp-ls` can not be found #4365

Closed Hi-Angel closed 8 months ago

Hi-Angel commented 8 months ago

Thank you for the bug report

Bug description

I installed csharp-ls and it is in $PATH. However if I open a .cs file and execute lsp, I get a Unable to find installed server supporting this file error. It suggests to install omnisharp or csharp-ls, but the latter is already installed.

lsp-servers for C, python and bash work fine, so it is specific to just this one.

Steps to reproduce

  1. Install csharp-ls
  2. Start emacs and execute lsp-start-plain
  3. Open a file test.cs that has the following content:
    namespace HelloWorld
    {
        class Hello {
            static void Main(string[] args)
            {
                System.Console.WriteLine("Hello World!");
            }
        }
    }
  4. Execute in Emacs lsp

Expected behavior

csharp-ls gets started

Which Language Server did you use?

csharp-ls

OS

Linux

Error callstack

Command "semgrep lsp" is not present on the path.
Hi-Angel commented 8 months ago

Ha! I couldn't figure out by code of lsp-mode, it's quite complicated. But I executed a bpftrace to print new processes while executing a lsp and found this:

pid: 40505, comm: emacs, args: /bin/zsh -c dotnet tool list -g
pid: 40505, comm: zsh, args: dotnet tool list -g

so lsp is starting this tool. Apparently it assumes the tool will print if csharp-ls exists, but that doesn't happen, its output is empty. Even though csharp-ls does exist 😊 Looking at lsp-csharp.el it seems like the test for just checking if csharp-ls binary is present is missing. So that needs to be fixed.

psibi commented 8 months ago

This looks suspicious:

Command "semgrep lsp" is not present on the path.

Can you try setting this configuration and try again:

(setq lsp-disabled-clients '(semgrep-ls))
Hi-Angel commented 8 months ago

Can you try setting this configuration and try again:

(setq lsp-disabled-clients '(semgrep-ls))

Didn't help, lsp still says csharp-ls is not installed and asks if I want it to be installed

psibi commented 8 months ago

What is the output of which csharp-ls ?

And can you check the variable exec-path and see the directory where csharp-ls is present exists in this variable.

Hi-Angel commented 8 months ago

What is the output of which csharp-ls ?

/usr/bin/csharp-ls

And can you check the variable exec-path and see the directory where csharp-ls is present exists in this variable.

Yes, it enlists /usr/bin


As I mentioned in my comment above, I think the problem simply comes down to lsp-csharp.el lacking the search by the name of csharp-ls (and omnisharp for that matter).

psibi commented 8 months ago

Ah, I missed that comment. I see what you mean.

Hi-Angel commented 8 months ago

It seems that there is actually a code that supposed to search it by name, it's in the function lsp-csharp--cls-make-launch-cmd. However adding a (print "here") inside it and evaluating the function and then trying to run lsp on C# file does not show a print "hello" in the *Messages* buffer. So for some reason this function simply does not get run.

Hi-Angel commented 8 months ago

So, I am not good in lsp-mode internals, but I would seem to me there is a bug on this line.

It would seem that the original author assumed that function (lsp-stdio-connection) tests its args in order to find executable. But it works a bit different way. All in all, the first function that is actually supposed to return /usr/bin/csharp-ls does not get run.

At least that's my interpretation of the situation.

Hi-Angel commented 8 months ago

The regression was introduced in 9b3a9215807af0727b514e8c7cf440bcc0bdad44

CC: @razzmatazz the author of the commit

UPD: reverting the commit fixes the problem