OmniSharp / omnisharp-vim

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

[Feature request] Allow Find Type and Find Symbol regardless of file type #822

Closed starteleport closed 1 year ago

starteleport commented 1 year ago

I want to be able to navigate to type when I've just opened the workspace.

I suggest adding the option to automatically start server when there is solution file in global working dir and enable :OmniSharpFindType and :OmniSharpFindSymbol.

starteleport commented 1 year ago

I could actually submit a PR for that, but I'm new to vim. If it works for you, let me know.

nickspoons commented 1 year ago

It's too invasive for a language server plugin to start a server automatically when it hasn't even opened an associated code file. Is that what you're suggesting, that a server is started even when vim is in e.g. a .html file?

starteleport commented 1 year ago

I put it this way: if vim is opened without file argument in a directory where exists a solution file, then we could assume that the sever will be eventually started anyway. It could be an opt-in behavior via some option.

starteleport commented 1 year ago

btw I understand that the exact condition for starting a server could be user-chosen, I just wanted to know if you are interested in having some option to do so and enabling some solution-wide commands in this case.

nickspoons commented 1 year ago

Not an option to do it automatically, I don't think that's a good way to go, it'll be too big a load on a vim instance, constantly searching for solution files up the directory tree every time a buffer is opened.

But making the :OmniSharpStartServer and :OmniSharpFindType commands global could be doable. It's just going to be a bit involved because all of the current server-management logic is buffer based. Each .cs buffer knows which server is it running under etc.

starteleport commented 1 year ago

It looks like even if we ask user to choose a solution file manually, we end up with a single server running that will be reused for all subsequent buffers created. Am I right?

nickspoons commented 1 year ago

No, that shouldn't be the case, unless there actually is no .sln above the current buffer.

nickspoons commented 1 year ago

So currently with .cs files, when the buffer is opened OmniSharp-vim searches up the directory tree for a .sln (or .csproj, if no .sln is found). It checks to see if that .sln already has a server running. If it does, it attaches to that server, otherwise it starts a server.

nickspoons commented 1 year ago

By the way @starteleport, although the commands aren't available from non-csharp buffers, the functions that they call are. So you can already do this from any buffer:

:call OmniSharp#StartServer()              " :OmniSharpStartServer
:call OmniSharp#actions#symbols#Find()     " :OmniSharpFindSymbol
:call OmniSharp#actions#symbols#FindType() " :OmniSharpFindType
starteleport commented 1 year ago

Thanks, that's the solution I've ended up with!