godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
89.98k stars 21.08k forks source link

C# autocomplete in built-in script editor #24947

Closed magarcan closed 4 years ago

magarcan commented 5 years ago

Autocomplete isn't working when you create a new C# script with the editor. Don't know if this is a issue or a missing feature.

piratesephiroth commented 5 years ago

There never was autocomplete for c# scripts. You have to use an external editor if you want that.

magarcan commented 5 years ago

There never was autocomplete for c# scripts. You have to use an external editor if you want that.

Are there any reson for that? I've also tried using VS Code and there are some problems with autocompletion too.

piratesephiroth commented 5 years ago

There never was autocomplete for c# scripts. You have to use an external editor if you want that.

Are there any reson for that?

Perhaps it's because c# support is still considered alpha, so autocomplete is not a priority.

NathanWarden commented 5 years ago

I agree, it's extremely low priority since there are several IDE's that already do this and pretty much guaranteed do it far better than Godot will be able to do anytime soon, including the fact that they have refactoring tools.

There are major things missing with C# like Android and iOS support.

With that said, anybody who has the time and ability to implement C# autocomplete can go ahead and implement it. It just won't be done by the core team unless it becomes much higher priority :)

Chaosus commented 5 years ago

I've also tried using VS Code and there are some problems with autocompletion too.

Did you install a C# plugin ?

MordragT commented 5 years ago

A Addon for Visual Studio Code with AutoComplete for Godot commands would be nice

aqez commented 5 years ago

Visual Studio Code already handles this, if you have the c# extensions installed and have the folder open (the folder for your project which includes your .sln and .csproj files): image

giulianob commented 5 years ago

FYI if there's ever any interest on implementing this, the C# language server is open source and is what pretty much all of the editors use to do the heavy lifting: https://github.com/OmniSharp/csharp-language-server-protocol

MightyPrinny commented 4 years ago

Realistically even if godot had a built in editor it wouldn't be as good as vscode,visual studio, monodevelop,rider ,etc. Which means not much people will use it, only beginners and gdscript is probably better for beginners anyways.

dreamsComeTrue commented 4 years ago

I also concur the idea of leaving as it is - it would add unnecessary complexity to editor itself - even unity or ue4 left that job for more specialized tools. There is no need to replicate EVERY gamedev tool inside of godot - similar problem is - should we include 'paint-like' application (like game maker does) or just leave it for Krita/GIMP/Aseprite/etc ? Or what about - audio editing - Audacity is the best and the beast in that regard - we do not need to clamp that functionality inside Godot.

We should put more focus on enhancing GDscript support instead - as it is native to the engine itself.

Shadowblitz16 commented 4 years ago

I disagree. I think as long as there was C# syntax highlighting, and auto complete for members and arguments it would be fine.

noone is going to use another code editor if the built in one has this stuff. its a pain in the butt to load another text editor and switch back and forth between it and godot.

I think as long as it worked just as well as the gdscript one it would be fine

interpol-kun commented 4 years ago

+1 on leaving that for the IDE. Lang server could bring unnecessary performance and memory impact.

neikeq commented 4 years ago

While I think this would be nice (even though most people would probably use an IDE), I have too many higher priority tasks to focus on.

If any one is interested in adding support for C#'s LSP in Godot, the right place would be in: https://github.com/godotengine/godot/tree/master/modules/mono/editor/GodotTools/GodotTools

Godot's callback for providing code completion is: https://github.com/godotengine/godot/blob/e0a9879ce473049995d21930179699ac5753edee/core/script_language.h#L320

Which needs to be overridden here: https://github.com/godotengine/godot/blob/e0a9879ce473049995d21930179699ac5753edee/modules/mono/csharp_script.h#L343

There you could make it call into your C# method in GodotTools where most of your code would be.

jammy3662 commented 4 years ago

Visual Studio Code already handles this, if you have the c# extensions installed and have the folder open (the folder for your project which includes your .sln and .csproj files)

Which C# extensions do you need installed? I tried this and the autocomplete still only showed me things that were already in the cs file

aqez commented 4 years ago

Visual Studio Code already handles this, if you have the c# extensions installed and have the folder open (the folder for your project which includes your .sln and .csproj files)

Which C# extensions do you need installed? I tried this and the autocomplete still only showed me things that were already in the cs file

You need the main C# one by Microsoft, ms-dotnettools.csharp 8M+ downloads as of this comment. Once installed the highlighting should work as long as a folder is open with a valid csproj/sln.

image

jammy3662 commented 4 years ago

You need the main C# one by Microsoft, ms-dotnettools.csharp 8M+ downloads as of this comment. Once installed the highlighting should work as long as a folder is open with a valid csproj/sln.

image

Here is what I have. As you can see I have the C# extension installed and my godot project open,w ith the cgproj and sln in the project folder. But when I type it only suggest things that are already in the file.

image

Edit: is it necessary that the file I'm editing be in the same path as the csproj? If so, that makes it a lot harder to use since I can't organize files.

aqez commented 4 years ago

No, it is not required for them to be in the same folder but the file must be a part of the project (I think.. it's been a while since I worked with godot but I think it uses old style projects that have to list all of the files explicitly). If you look into your csproj is the file you're working on listed? Also var room: int = 0 is not valid C# code, it would be int room = 0.

So basically you have to keep your csproj file in sync with what's going on in your filesystem which historically has been done automatically by tools. Now that dotnet core is out they have a new csproj format which implicitly includes most things, but I don't think godot is using this (I don't have it installed to check).

jammy3662 commented 4 years ago

I've made some progress: I set the editor to VSCode in Godot, then opened the cs file from Godot. This installed some dependencies and now the autocomplete is giving me something. However, none of them are from the Godot API. I did get quite a few errors during the process, here's the dump.

Starting OmniSharp server at 8/26/2020, 3:26:45 PM
    Target: /Users/user/Code/godot/projects/Sesame/Sesame.sln

OmniSharp server started.
    Path: /Users/user/.vscode/extensions/ms-dotnettools.csharp-1.23.1/.omnisharp/1.37.0/run
    PID: 6848

[info]: OmniSharp.Stdio.Host
        Starting OmniSharp on MacOS 10.14.5 (x64)
[info]: OmniSharp.Services.DotNetCliService
        DotNetPath set to dotnet
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Located 1 MSBuild instance(s)
            1: StandAlone 16.8.0 - "/Users/user/.vscode/extensions/ms-dotnettools.csharp-1.23.1/.omnisharp/1.37.0/omnisharp/.msbuild/Current/Bin"
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        MSBUILD_EXE_PATH environment variable set to '/Users/user/.vscode/extensions/ms-dotnettools.csharp-1.23.1/.omnisharp/1.37.0/omnisharp/.msbuild/Current/Bin/MSBuild.exe'
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Registered MSBuild instance: StandAlone 16.8.0 - "/Users/user/.vscode/extensions/ms-dotnettools.csharp-1.23.1/.omnisharp/1.37.0/omnisharp/.msbuild/Current/Bin"
            CscToolExe = csc.exe
            MSBuildToolsPath = /Users/user/.vscode/extensions/ms-dotnettools.csharp-1.23.1/.omnisharp/1.37.0/omnisharp/.msbuild/Current/Bin
            CscToolPath = /Users/user/.vscode/extensions/ms-dotnettools.csharp-1.23.1/.omnisharp/1.37.0/omnisharp/.msbuild/Current/Bin/Roslyn
            BypassFrameworkInstallChecks = true
            MSBuildExtensionsPath = /Users/user/.vscode/extensions/ms-dotnettools.csharp-1.23.1/.omnisharp/1.37.0/omnisharp/.msbuild
[info]: OmniSharp.Cake.CakeProjectSystem
        Detecting Cake files in '/Users/user/Code/godot/projects/Sesame'.
[info]: OmniSharp.Cake.CakeProjectSystem
        Could not find any Cake files
[info]: OmniSharp.MSBuild.ProjectSystem
        Detecting projects in '/Users/user/Code/godot/projects/Sesame/Sesame.sln'.
[info]: OmniSharp.MSBuild.ProjectManager
        Queue project update for '/Users/user/Code/godot/projects/Sesame/Sesame.csproj'
[info]: OmniSharp.Script.ScriptProjectSystem
        Detecting CSX files in '/Users/user/Code/godot/projects/Sesame'.
[info]: OmniSharp.Script.ScriptProjectSystem
        Could not find any CSX files
[info]: OmniSharp.WorkspaceInitializer
        Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpFormattingWorkspaceOptionsProvider, Order: 0
[info]: OmniSharp.MSBuild.ProjectManager
        Loading project: /Users/user/Code/godot/projects/Sesame/Sesame.csproj
[info]: OmniSharp.WorkspaceInitializer
        Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.RenameWorkspaceOptionsProvider, Order: 100
[info]: OmniSharp.WorkspaceInitializer
        Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.ImplementTypeWorkspaceOptionsProvider, Order: 110
[info]: OmniSharp.WorkspaceInitializer
        Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.BlockStructureWorkspaceOptionsProvider, Order: 140
[info]: OmniSharp.WorkspaceInitializer
        Configuration finished.
[info]: OmniSharp.Stdio.Host
        Omnisharp server running using Stdio at location '/Users/user/Code/godot/projects/Sesame' on host 6758.
[fail]: OmniSharp.MSBuild.ProjectLoader
        The reference assemblies for .NETFramework,Version=v4.7 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/developerpacks
[warn]: OmniSharp.MSBuild.ProjectManager
        Failed to load project file '/Users/user/Code/godot/projects/Sesame/Sesame.csproj'.
/Users/user/Code/godot/projects/Sesame/Sesame.csproj
/Users/user/.vscode/extensions/ms-dotnettools.csharp-1.23.1/.omnisharp/1.37.0/omnisharp/.msbuild/Current/Bin/Microsoft.Common.CurrentVersion.targets(1178,5): Error: The reference assemblies for .NETFramework,Version=v4.7 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/developerpacks

[fail]: OmniSharp.MSBuild.ProjectManager
        Attempted to update project that is not loaded: /Users/user/Code/godot/projects/Sesame/Sesame.csproj
[info]: OmniSharp.OmniSharpWorkspace
        Miscellaneous file: /Users/user/Code/godot/projects/Sesame/class/monitor.cs added to workspace
aqez commented 4 years ago

I just noticed you were running under MacOS, I've seen it help fix this issue to install mono globally on the system under linux. You can give that a try. In particular, these two messages:

fail]: OmniSharp.MSBuild.ProjectLoader
        The reference assemblies for .NETFramework,Version=v4.7 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/developerpacks
[warn]: OmniSharp.MSBuild.ProjectManager
        Failed to load project file '/Users/user/Code/godot/projects/Sesame/Sesame.csproj'.
/Users/user/Code/godot/projects/Sesame/Sesame.csproj
/Users/user/.vscode/extensions/ms-dotnettools.csharp-1.23.1/.omnisharp/1.37.0/omnisharp/.msbuild/Current/Bin/Microsoft.Common.CurrentVersion.targets(1178,5): Error: The reference assemblies for .NETFramework,Version=v4.7 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/developerpacks

Would suggest that omnisharp is having a hard time loading the .NET assemblies. I think installing mono would solve this.

jammy3662 commented 4 years ago

Thanks for your help, aqez. I ended up deciding to use C++ instead, I'm not particularly picky about using C#. If I get C# working with autocomplete in the future, I will post my process here.

Calinou commented 4 years ago

Closing in favor of https://github.com/godotengine/godot-proposals/issues/712, as feature proposals are now tracked in the Godot proposals repository.

anyanyang commented 1 year ago

@jammy3662 : I ran into the same problem as you, this time with Godot 4 on Mac. I had to close VSCode, then from Godot, open any script, which launches VSCode again. This would load with autocomplete working for Godot and project classes. Perhaps there's something in the launch Godot triggers versus a standard launch of VSCode?