csharp-language-server icon indicating copy to clipboard operation
csharp-language-server copied to clipboard

--solution command line option not honoured when multiple solutions available in project

Open lem102 opened this issue 2 years ago • 1 comments

Hi,

First of all, thanks for csharp-ls :pray:.

When I start csharp-ls in a directory that contains multiple solutions like this:

$ ls
solution1.sln solution2.sln xyz.csproj Program.cs ...
$ csharp-ls --solution solution2.sln

I can see from the output in emacs that despite providing a solution to load, the code will still attempt to load all the projects in the directory one at a time. This works, but if you have a directory that contains 100+ projects, the startup time can get a little long :sweat_smile:.

[eglot] Connected! Server `EGLOT (csharpLsTestSolution/(csharp-ts-mode csharp-mode))' now managing `(csharp-ts-mode csharp-mode)' buffers in project `csharpLsTestSolution'.
[eglot] Server reports (type=4): csharp-ls: attempting to find and load solution based on root path ("/home/jacobl/dev/csharpLsTestSolution")..
[eglot] Server reports (type=4): csharp-ls: 2 solution(s) found: [/home/jacobl/dev/csharpLsTestSolution/csharpLsTestSolution2.sln, /home/jacobl/dev/csharpLsTestSolution/csharpLsTestSolution.sln]
[eglot] Server reports (type=4): csharp-ls: no or multiple .sln files found on /home/jacobl/dev/csharpLsTestSolution
[eglot] Server reports (type=4): csharp-ls: looking for .csproj/fsproj files on /home/jacobl/dev/csharpLsTestSolution..
[eglot] Server reports (type=4): csharp-ls: OK, 1 project files loaded

This seems like it should be a simple problem to fix (if it is indeed a problem), but I've never coded F# before :cry: so it'll take me a while before I can submit a PR.

lem102 avatar Sep 18 '23 19:09 lem102

I am facing a similar issue, I wrote some code to display a project selector, I have been trying to get it to work but it seems like the solution parameter is ignored.

Here is my code in case someone needs it, because I think lsp-code shows a selector somehow but eglot doesn't. Were you able to figure out why it's ignoring the solution provided?

  (defun eglot-csharp-ls-select-solution ()
    (let* ((project (project-current t))
           (files (project-files project))
           (solutions (seq-filter
                       (lambda (file)
                         (string-suffix-p ".sln" file)) files)))
      (if (length> solutions 1)
          (list "-s" (completing-read "Select a solution: " solutions))
        '())))

  (setq eglot-server-programs
        (remove (assoc '(csharp-mode csharp-ts-mode)
                       eglot-server-programs) eglot-server-programs))
  (add-to-list 'eglot-server-programs
               `((csharp-mode csharp-ts-mode)
                 . ,(append '("csharp-ls")
                            (eglot-csharp-ls-select-solution))))

ebeem avatar Sep 22 '24 05:09 ebeem