OmniSharp / omnisharp-vim

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

Recognize changed project structure. #723

Closed DasOhmoff closed 3 years ago

DasOhmoff commented 3 years ago

Hello, thank you for your help.

When I work within vim on a cs file, everything works great and fine. But when I then switch to Visual Studio f.e. and change some things, such as adding a file to the project f.e., then vim stops working correctly. It shows errors that are not there and also cannot find the types in the new files. After restarting the servers everything works fine again.

Is there a way omnisharp recognize the changed project structure or files, and to update accordingly?

nickspoons commented 3 years ago

Not really. There are no file watchers in OmniSharp-vim, and I don't think it would make sense for there to be. To me it would kind of make sense to have some file watchers on the server side, OmniSharp-roslyn, but I suspect if they were interested in automatically detecting changes they would have done it already.

When I make multi-file changes, I just restart the server. For individual file changes, you can tell OmniSharp-roslyn about the changes by just opening the modified file in your Vim session. The new state of the file will be sent to OmniSharp-roslyn.

DasOhmoff commented 3 years ago

I see. Well I guess there is nothing that can be done here. If any one finds some kind of solution for this, please post it here.

DasOhmoff commented 3 years ago

Hello. I stumbled upon the endpoint /reanalyze in OmniSharp-roslyns directory src/OmniSharp.Abstractions/OmniSharpEndpoints.cs. Also upon the function WhenProjectIsRestoredThenReanalyzeProject() in tests/OmniSharp.MSBuild.Tests/ProjectWithAnalyzersTests.cs. And WhenReAnalyzeIsExecutedForAll_ThenReanalyzeAllFiles() in tests/OmniSharp.Roslyn.CSharp.Tests/ReAnalysisFacts.cs.

I remembered this issue and thought that maybe these can be used in some way to solve the problem. It would be nice to trigger this endpoint via omnisharp-vim, so that one does not have to restart the whole server again, as this takes quite a while.

nickspoons commented 3 years ago

Hi @DasOhmoff,

That endpoint was added in this PR. Reading the description, it appears to be about running roslyn analyzers. I don't think this endpoint triggers reading modified files from disk.

DasOhmoff commented 3 years ago

Ah I see. But could we not at least trigger this endpoint manually when needed via omnisharp-vim? Then one would not have to restart the whole server again.

nickspoons commented 3 years ago

Well yeah we can trigger the endpoint but what for? You still need to restart the server to have the external changes you've made read in.

DasOhmoff commented 3 years ago

Does it not reanalize the whole project when we trigger the endpoint? In that case would the the server not read in the external changes itself, and afterwards notify vim about it? Maybe I misunderstood.

nickspoons commented 3 years ago

I don't think so. Looking at the PR I think it just tells all analysers to restart. To start analysing the code that is in memory. If it reloads all files from disk, what would be the difference between this endpoint, and restarting the server?

Give it a try if you want, I just can't imagine that this endpoint will solve the original issue.