OmniSharp / omnisharp-vim

Vim omnicompletion (intellisense) and more for C#
http://www.omnisharp.net
MIT License
1.7k stars 169 forks source link

OmniSharp uses csproj as project instead of solution #823

Closed ikirkpat closed 1 year ago

ikirkpat commented 1 year ago

I have a project where the structure is like so:

Root/
    - backend/
        - MyApp.sln
        - Project1/
            - Project1.csproj
    - OtherProjects/
        - Project2/
            - Project2.csproj

The solution file includes both Project1 and Project2. Project1 references Project2. When I open a class in Project2, it seems to be using Project2.csproj as the current project instead of the solution file. This means that I can't do things like FindUsage reliably cause it only looks in Project2.

I think it's getting tripped up cause the solution file isn't in a direct parent directory of Project2.

I've tried to look online to see how to select the solution file manually as the project but it just always uses the project file. In VSCode, there's a command to select the project (see attached screenshot). I need something like that. I've looked at https://github.com/OmniSharp/omnisharp-vim/issues/545 but I can't seem to get it to prompt me to choose the project.

Screenshot from 2022-11-14 10-10-51

How can I get OmniSharp to use my solution file even if it's in a different path on my computer?

nickspoons commented 1 year ago

545 is a slightly different situation where I think they had multiple .sln files at the top level.

When you open any .cs file, whether or not a server is running already, omnisharp-vim searches up the directory tree for a .sln, and if none are found, it searches for a .csproj. This way a single vim session can have many omnisharp servers running simultaneously.

One option for you might be to set let g:OmniSharp_start_server = 0 in your .vimrc, and then manually start the server with OmniSharpStartServer path/to/.sln (with tab-completion for the .sln filename).

The more correct way to resolve this, which has been discussed before but never implemented properly, is a setting to allow a custom function to be used to find the .sln file. This way users with unusual solution structures like yours can have some logic that says "if I'm under path Root/OtherProjects use Root/backend/MyApp.sln, otherwise continue as per usual". But I don't have time to add this kind of option right now. PRs welcome.

ikirkpat commented 1 year ago

That's actually exactly what I was looking for. I didn't realize OmniSharpStartServer took an explicit argument. Though it just auto found the solution. Thanks!