razzmatazz / csharp-language-server

Roslyn-based LSP language server for C#
MIT License
597 stars 37 forks source link

Use Mono SDKS? #34

Open timshannon opened 2 years ago

timshannon commented 2 years ago

I'm trying to use coc.nvim with C#, and this appears to be new only supported LSP.

I'm on linux and I have the latest Mono SDKs and .NET core 5 & 6 installed, but I'm getting this when trying to use csharp-ls:

lies for .NETFramework,Version=v4.7.2 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at https://aka.ms/msbuild/developerpack
Loaded server for /home/tshannon/workspace/cold/cold.sln in 4.9s

So csharp-ls is running via .net 6, but the solution needs .net 4.7.2 which is supplied via mono. Anyone know how I work around this?

razzmatazz commented 2 years ago

hi @timshannon

csharp-ls does not use mono itself, but roslyn libraries that we use are probably trying to find .net fx lib reference dlls and fail for you..

so to confirm, csharp-ls is actually running on dotnet-6 runtime -- but runtime for running csharp-ls should not be related to the actual ability to parse older projects, as was verified by @josteink, I think..

I don't think you need mono for this, but maybe, not sure if roslyn picks up mono reference dlls automatically? -- refering to @josteink for confirmation again..

razzmatazz commented 2 years ago

btw, what is the functionality that you're missing? does autocomplete work? do you get diagnostics/errors? which editor/client are you running on?

josteink commented 2 years ago

Since I was name-dropped I'll be polite enough to answer as best as I can, but really all I did was apt install mono-complete and nothing more than that. 🥹

The .NET Framework projects I tested with was class-libraries and console-apps originally written for Windows, but which still built and ran cleanly with mono.

For those projects csharp-ls worked fine for me.

timshannon commented 2 years ago

I'm using Vim 8 with coc.nvim. I think it's likely an issue with the Godot SDK which is what I'm trying to work with. I'm still investigating. I was more looking for confirmation that it should work with Mono, which you given me.

It's likely an issue on my side, but I'll update this issue as I look into it.

Thanks,

ShooTeX commented 2 years ago

I have a similar issue with nvim lsp, this is a unity project with generated files on windows, I'm using WSL2 to edit the files on windows with nvim. Mono and .NET 6 is installed (in wsl). This is the first time working with C# so I have no idea what I'm doing wrong 😅

this is part of the log, sorry for the image.

image

my .cs file looks like this:

image

josteink commented 2 years ago

The way I read those errors, it says that the mono reference-assmeblies are not installed. Could that be right?

How you get those installed in your setup, I have no idea :smile:

timshannon commented 2 years ago

For me the mono assemblies / SDK are installed, just not where they are expected to be possibly?

The error references looking for them in at /usr/share/dotnet when they are actually at /usr/lib/mono/.

ShooTeX commented 2 years ago

using export FrameworkPathOverride=/etc/mono/4.5 fixes my mono problem.

but i still have the error Found project reference without a matching metadata reference, does that have something to do with this languageserver? I still have the same diagnostic errors like in the screenshot above

timshannon commented 2 years ago

FWIW, I have no issues with a barbones project referencing the same framework version as my Godot project (4.7.2), so even without exporting the FrameworkPathOverride, it seems to be finding the mono framework fine on my machine.

I think the "Godot SDK" is what it's stumbling over.

razzmatazz commented 2 years ago

Does omnisharp fare better here? Maybe we could port over some fixes?

timshannon commented 2 years ago

No idea what I did to change things, but it all appears to be working now.

josteink commented 2 years ago

Great. Now this project contains voodoo as well 😅

razzmatazz commented 2 years ago

A hack is a hack 😂

omercsp commented 2 years ago

Sorry for (somewhat) hijacking the discussion, but I have a similar issue I'm trying to resolve - I have a windows based .net FW (4.7.2) project (solution) that resides on a windows partition as usual. I'm trying to setup a WSL2 based vim configuration to code in it using using coc-nvim.

I was able the setup the coc-nvim plugin as described here https://github.com/coc-extensions/coc-omnisharp. However - while the plugin seems to find all symbols within the solution projects, the SDK symbols are unavailable (e.g. 'system', or whatever).

They are, of course available somewhere in through WSL's '/mnt/c.../ mount (in fact msbuild runs successfully from within WSL), but csharp-language-server doesn't know where to locate these symbols.

Hence the question - is there anyway to configure the server references lookup and so?

KohlJary commented 1 year ago

For anyone in a similar situation to me having spent the better part of like a day and a half trying to figure out what's going on with this, I think you need to use export FrameworkPathOverride=/etc/mono/4.7.1-api or whichever version you need, then be sure to reboot. I thought I'd refreshed my environment sufficiently but after a reboot everything literally just started working so that's the best guess I've got on the issue.