Last active
April 25, 2025 12:04
-
-
Save Creta5164/244fcb11a3b2d5d65ef196ca0e2d08ed to your computer and use it in GitHub Desktop.
[Godot 4.4] Adds the ability to open with VSCode to the right-click menu to Godot's file system dock.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if TOOLS | |
using System.IO; | |
using System.Linq; | |
using Godot; | |
using static Godot.GD; | |
using static Godot.EditorContextMenuPlugin; | |
namespace CretaPark.GodotTools; | |
[Tool] | |
public partial class OpenInVSCode : EditorPlugin { | |
private readonly EditorContextMenuPlugin _contextMenuPlugin = new(); | |
public override void _EnablePlugin() | |
=> AddContextMenuPlugin(ContextMenuSlot.Filesystem, _contextMenuPlugin); | |
public override void _DisablePlugin() | |
=> RemoveContextMenuPlugin(_contextMenuPlugin); | |
[Tool] | |
public partial class EditorContextMenuPlugin : Godot.EditorContextMenuPlugin { | |
public override void _PopupMenu(string[] paths) { | |
Theme editorTheme = EditorInterface.Singleton.GetEditorTheme(); | |
Texture2D codeEditIcon = editorTheme.GetIcon("CodeEdit", "EditorIcons"); | |
AddContextMenuItem("Open in VSCode", Callable.From<string[]>(Execute), codeEditIcon); | |
} | |
private void Execute(string[] paths) { | |
if (paths is { Length: 0 }) | |
return; | |
string externalCodePath = EditorInterface.Singleton | |
.GetEditorSettings() | |
.GetSetting("text_editor/external/exec_path") | |
.AsString(); | |
if (!Path.GetDirectoryName(externalCodePath).EndsWith("Microsoft VS Code")) { | |
Print( | |
$"[{nameof(OpenInVSCode)}] Please ensure setting \"text_editor/external/exec_path\"" | |
+ " is set to the path of VSCode in Editor settings." | |
); | |
return; | |
} | |
var selectedPaths = paths.Select(ProjectSettings.GlobalizePath); | |
OS.Execute(externalCodePath, [ "-r", ..selectedPaths ]); | |
} | |
} | |
} | |
#endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[plugin] | |
name="OpenInVSCode" | |
description="Adds the ability to open with VSCode to the right-click menu to Godot's file system dock." | |
author="Creta Park" | |
version="1.1.0" | |
language="C-sharp" | |
script="OpenInVSCode.cs" |
Heya, awesome plugin! Do you mind if I upload my GDScript adaptation to the Godot asset store? I have your name included as well in the authors and I can link back to this Gist if you like @Creta5164
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Important
This code will no longer require a workaround after 4.4, please check this out.Edit : This code snippet is now using 4.4's new
EditorContextMenuPlugin
!Preview