Skip to content

Instantly share code, notes, and snippets.

@Creta5164
Last active April 25, 2025 12:04
Show Gist options
  • Save Creta5164/244fcb11a3b2d5d65ef196ca0e2d08ed to your computer and use it in GitHub Desktop.
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.
#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
[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"
@Creta5164
Copy link
Author

Creta5164 commented May 13, 2024

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

image

image

@ZachAR3
Copy link

ZachAR3 commented May 13, 2024

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