OmniSharp / omnisharp-roslyn

OmniSharp server (HTTP, STDIO) based on Roslyn workspaces
MIT License
1.79k stars 420 forks source link

omnisharp in wsl doesn't resolve Windows paths #2545

Open reaz1995 opened 1 year ago

reaz1995 commented 1 year ago
My set-up:
wsl2 with Ubuntu 22.04.2 LTS
nvim with omnisharp-roslyn 

I would like use it for unity projects, but omnisharp can't resolve Windows paths of Unity and VS assemblies. Unity generate Assembly-CSharp.csproj file with paths for Unity assemblies

C:\Program Files\Unity\Hub\Editor\2021.3.26f1\Editor\Data\Managed\UnityEngine\UnityEngine.dll

and VS assemblies

C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\Extensions\Microsoft\Visual Studio Tools for Unity\Analyzers\Microsoft.Unity.Analyzers.dll

After manually converting to wsl paths, omnisharp load quick and provide all of its features. image image

Autocheck every path and translate would solve this problem.

@@ edit First fails the analyzer

https://github.com/OmniSharp/omnisharp-roslyn/blob/0f526554c1488891ec524629c031d1c2782bef1f/src/OmniSharp.MSBuild/ProjectManager.cs#L374

[ERROR][2023-06-21 14:16:40] ...lsp/handlers.lua:535    "OmniSharp.MSBuild.ProjectManager: Failure while loading the analyzer reference 'Microsoft.Unity.Analyzers': Could not find a part of the path 'C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/Extensions/Microsoft/Visual Studio Tools for Unity/Analyzers/Microsoft.Unity.Analyzers.dll'. | "

then other assemblies fails silently without logging https://github.com/OmniSharp/omnisharp-roslyn/blob/0f526554c1488891ec524629c031d1c2782bef1f/src/OmniSharp.Host/Services/AssemblyLoader.cs#LL79C25-L79C25

Hows about to add another check for os platform then check if assemblies exist under translated path?

reaz1995 commented 3 months ago

Omnisharp-roslyn runs in wsl (Ubuntu) The assembly files of Unity are located on Windows. There no way to bypass unity auto generate csproj file with windows paths. So the only way to make it works is to update omnisharp-roslyn.

Please make omnisharp-roslyn to look up for wsl paths if it can't resolve windows paths, or check for platform then translate paths to look up for assemblies.

Thats how the error loks like:

[ERROR][2024-08-13 12:50:45] ...lsp/handlers.lua:535    "OmniSharp.MSBuild.ProjectManager: Failure while loading the analyzer reference 'Microsoft.Unity.Analyzers': Could not find a part of the path '/mnt/c/Users/User/Desktop/Unity_Projects/Game/C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/Extensions/Microsoft/Visual Studio Tools for Unity/Analyzers/Microsoft.Unity.Analyzers.dll'. | "

it does stack up the local path(in wsl format) of project with the reference path to assemblies(in windows format)

When manually change path from Windows path to wsl path, like so:

<Reference Include="UnityEngine">
<HintPath>/mnt/c/Program Files/Unity/Hub/Editor/2021.3.26f1/Editor/Data/Managed/UnityEngine/UnityEngine.dll</HintPath>
    </Reference>

Omnisharp-roslyn starts to works correctly.

reaz1995 commented 1 month ago

if anyone wonders how to make nvim lsp omnisharp works with Unity, here the solution: https://github.com/reaz1995/UnityNvimSupport