-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question: How to use in combination with Godot? ("The type or namespace name 'Godot' could not be found") #39
Comments
Omnisharp requires a proper *.csproj file with references to all used assemblies. A minimal project with a
|
@deathaxe I do have a csproj file in my project directory. It didn't originally have the The contents of my <Project Sdk="Godot.NET.Sdk/4.2.2">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework Condition=" '$(GodotTargetPlatform)' == 'android' ">net7.0</TargetFramework>
<TargetFramework Condition=" '$(GodotTargetPlatform)' == 'ios' ">net8.0</TargetFramework>
<EnableDynamicLoading>true</EnableDynamicLoading>
<RootNamespace>Monster</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="cmstar.Serialization.Json" Version="1.0.0" />
<PackageReference Include="YamlDotNet" Version="13.7.1" />
</ItemGroup>
<ItemGroup>
<Compile Remove="scratch\**" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Remove="scratch\**" />
</ItemGroup>
<ItemGroup>
<Folder Include="src\cs\" />
<Folder Include="addons\Gui\src\" />
</ItemGroup>
<ItemGroup>
<Reference Include="Godot">
<HintPath>C:\apps\godot-4.2.2\GodotSharp\Api\Release\GodotSharp.dll</HintPath>
</Reference>
</ItemGroup>
</Project> |
Downloading Godot, adding the reference and restarting Omnisharp was the only steps I needed to do to fix it on my end. |
I have tried restarting OmniSharp, after making the change to the csproj file, but that hasn't resolved the issue for me. It seems unlikely to be related, but I have noticed that after adding this line to my plugin settings: "csharp.referencesCodeLens.enabled": false, I still have references showing in Sublime Text (which I would rather they didn't), and also the counts often seem to be incorrect. I think what's happening is sometimes the counts are scrambled and not on the lines they should be? |
Yes, settings actually don't work. See #28 for given code lense setting in particular or #44 for the reason why. You can however control omnisharp settings by placing an omnisharp.json next to your project file. See https://github.com/OmniSharp/omnisharp-roslyn/wiki/Configuration-Options for details. Is the project file located in the root of that folder, which is also added to sidebar in ST? The only explanation I'd have for it not working is Omnisharp not having resolved or selected your project as the active one. It providing code lenses however indicates it basically working. |
The csproj file is located in the project root directory, same as where Godot originally generated it. Can you be more specific about what you mean by adding a project file to the sidebar? I don't use the sidebar. Mine is always set to hidden and I don't interact with it. (I use a (And thank you for clarifying the configuration issue.) |
sublime-project file is not important. Some language servers just require the main project folder to be the first folder in ST's sidebar. It may not be the case for Omnisharp, just wanted to rule out some possible reasons for file not being found. You could try to override the "env" setting, which points to invalid path. see d5cea1f Maybe this helps finding required binaries. |
Changing my plugin settings file to this does hide the references, but it doesn't change the behavior otherwise: {
"settings": {
"csharp.format.enable": false,
"omnisharp.useEditorFormattingSettings": false,
"razor.format.enable": false,
"csharp.referencesCodeLens.enabled": false,
},
"env": {},
"disabled_capabilities": {
"codeLensProvider": true,
},
} I also tried setting "env": {
"FrameworkPathOverride": "C:/apps/godot-4.2.2/GodotSharp/Api/Release",
}, Another thing I tried was navigating in the Sublime menu to "Project" -> "Add Folder to Project" and then selecting the Godot root project directory (the one containing the csproj file). This also didn't have any effect. |
The only idea left is checking LSP Log Panel for some useful hints printed by OmniSharp language server. Maybe it tells us, what's missing. Loading your project on my end causes various "invalid project file" messages, but I guess they are caused by godot not being properly installed and registerd. I don't have interest in learning godot or digging into that engine deeper though. |
To be clear in advance of all this, I do have the .NET SDK installed, and Rider and Godot are both working and handling C# code without issue. So whatever is happening is seemingly a configuration issue specific to OmniSharp and shouldn't be a general issue with my .NET SDK installation. Originally I was seeing this error in the LSP log panel:
I followed a troubleshooting step I found here and added a new environment variable After that I got a different error regarding failing to load the project file, which seems to be the same as was encountered here dotnet/vscode-csharp#5685:
...And then as I was trying to troubleshoot further and restarted Sublime Text for the severalth time in this process, I got a package control message that LSP-OmniSharp has just been updated. And now it seems to be working?
Here's the contents of my csproj file at the time that this seems to be working now: <Project Sdk="Godot.NET.Sdk/4.2.2">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework Condition=" '$(GodotTargetPlatform)' == 'android' ">net7.0</TargetFramework>
<TargetFramework Condition=" '$(GodotTargetPlatform)' == 'ios' ">net8.0</TargetFramework>
<EnableDynamicLoading>true</EnableDynamicLoading>
<RootNamespace>Monster</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="cmstar.Serialization.Json" Version="1.0.0" />
<PackageReference Include="YamlDotNet" Version="13.7.1" />
</ItemGroup>
<ItemGroup>
<Compile Remove="scratch\**" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Remove="scratch\**" />
</ItemGroup>
<!-- <ItemGroup>
<Folder Include="src\cs\" />
<Folder Include="addons\Gui\src\" />
</ItemGroup> -->
<ItemGroup>
<Reference Include="Godot">
<HintPath>C:\apps\godot-4.2.2\GodotSharp\Api\Release\GodotSharp.dll</HintPath>
</Reference>
</ItemGroup>
</Project> |
I assumed you got that update already. It may indeed make a difference as previous release shipped Omnisharp based on net471, which may not be fully compatible with .NET6+ and is known to suffer from various limitations with regards to resolving project/framework resources. Maybe it now also runs without the explicit godot reference as - I guess - |
I installed this plugin hoping to use it with C# code for Godot. I think I must be missing some setup step, though, because the line
using Godot;
is currently producing an error. The same source file shows as having no errors when viewed in JetBrains Rider, configured for Godot C#.Here are my LSP-OmniSharp settings:
I have not added any C#-specific settings to my LSP plugin settings, since this wasn't mentioned in the LSP-OmniSharp readme?
The text was updated successfully, but these errors were encountered: