Compare commits
5 Commits
3008d8037d
...
zed_editor
| Author | SHA1 | Date | |
|---|---|---|---|
| 6e61233a7b | |||
| bf59455412 | |||
| a016b9d47b | |||
| 7bdc08f8be | |||
| 269e8963e8 |
@@ -40,10 +40,11 @@ namespace FlaxEditor.Modules.SourceCodeEditing
|
||||
var codeEditing = Editor.Instance.CodeEditing;
|
||||
var vsCode = codeEditing.GetInBuildEditor(CodeEditorTypes.VSCode);
|
||||
var rider = codeEditing.GetInBuildEditor(CodeEditorTypes.Rider);
|
||||
var zed = codeEditing.GetInBuildEditor(CodeEditorTypes.Zed);
|
||||
|
||||
#if PLATFORM_WINDOW
|
||||
// Favor the newest Visual Studio
|
||||
for (int i = (int)CodeEditorTypes.VS2019; i >= (int)CodeEditorTypes.VS2008; i--)
|
||||
for (int i = (int)CodeEditorTypes.VS2026; i >= (int)CodeEditorTypes.VS2008; i--)
|
||||
{
|
||||
var visualStudio = codeEditing.GetInBuildEditor((CodeEditorTypes)i);
|
||||
if (visualStudio != null)
|
||||
@@ -66,6 +67,8 @@ namespace FlaxEditor.Modules.SourceCodeEditing
|
||||
_currentEditor = vsCode;
|
||||
else if (rider != null)
|
||||
_currentEditor = rider;
|
||||
else if (zed != null)
|
||||
_currentEditor = zed;
|
||||
else
|
||||
_currentEditor = codeEditing.GetInBuildEditor(CodeEditorTypes.SystemDefault);
|
||||
}
|
||||
|
||||
@@ -66,6 +66,9 @@ namespace FlaxEditor.Modules.SourceCodeEditing
|
||||
case CodeEditorTypes.Rider:
|
||||
Name = "Rider";
|
||||
break;
|
||||
case CodeEditorTypes.Zed:
|
||||
Name = "Zed";
|
||||
break;
|
||||
default: throw new ArgumentOutOfRangeException(nameof(type), type, null);
|
||||
}
|
||||
}
|
||||
@@ -83,6 +86,7 @@ namespace FlaxEditor.Modules.SourceCodeEditing
|
||||
case CodeEditorTypes.VSCodeInsiders:
|
||||
case CodeEditorTypes.VSCode: return "-vscode -vs2022";
|
||||
case CodeEditorTypes.Rider: return "-vs2022";
|
||||
case CodeEditorTypes.Zed: return "-vs2022";
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "ScriptsBuilder.h"
|
||||
#include "CodeEditors/VisualStudioCodeEditor.h"
|
||||
#include "CodeEditors/RiderCodeEditor.h"
|
||||
#include "CodeEditors/ZedEditor.h"
|
||||
#if USE_VISUAL_STUDIO_DTE
|
||||
#include "CodeEditors/VisualStudio/VisualStudioEditor.h"
|
||||
#endif
|
||||
@@ -241,6 +242,7 @@ bool CodeEditingManagerService::Init()
|
||||
#endif
|
||||
VisualStudioCodeEditor::FindEditors(&CodeEditors);
|
||||
RiderCodeEditor::FindEditors(&CodeEditors);
|
||||
ZedEditor::FindEditors(&CodeEditors);
|
||||
CodeEditors.Add(New<SystemDefaultCodeEditor>());
|
||||
|
||||
return false;
|
||||
|
||||
@@ -77,6 +77,11 @@ API_ENUM(Namespace="FlaxEditor", Attributes="HideInEditor") enum class CodeEdito
|
||||
/// </summary>
|
||||
VSCodeInsiders,
|
||||
|
||||
/// <summary>
|
||||
/// Zed
|
||||
/// </summary>
|
||||
Zed,
|
||||
|
||||
/// <summary>
|
||||
/// Rider
|
||||
/// </summary>
|
||||
|
||||
@@ -14,6 +14,9 @@
|
||||
|
||||
#if PLATFORM_WINDOWS
|
||||
#include "Engine/Platform/Win32/IncludeWindowsHeaders.h"
|
||||
#elif PLATFORM_MAC
|
||||
#include "Engine/Platform/Apple/AppleUtils.h"
|
||||
#include <AppKit/AppKit.h>
|
||||
#endif
|
||||
|
||||
namespace
|
||||
@@ -218,6 +221,15 @@ void RiderCodeEditor::FindEditors(Array<CodeEditor*>* output)
|
||||
#endif
|
||||
|
||||
#if PLATFORM_MAC
|
||||
// System installed app
|
||||
NSURL* AppURL = [[NSWorkspace sharedWorkspace]URLForApplicationWithBundleIdentifier:@"com.jetbrains.rider"];
|
||||
if (AppURL != nullptr)
|
||||
{
|
||||
const String path = AppleUtils::ToString((CFStringRef)[AppURL path]);
|
||||
SearchDirectory(&installations, path / TEXT("/Contents/Resources"));
|
||||
}
|
||||
|
||||
// JetBrains Toolbox installations
|
||||
String applicationSupportFolder;
|
||||
FileSystem::GetSpecialFolderPath(SpecialFolder::ProgramData, applicationSupportFolder);
|
||||
|
||||
@@ -232,6 +244,7 @@ void RiderCodeEditor::FindEditors(Array<CodeEditor*>* output)
|
||||
|
||||
// Check the local installer version
|
||||
SearchDirectory(&installations, TEXT("/Applications/Rider.app/Contents/Resources"));
|
||||
SearchDirectory(&installations, TEXT("/Applications/Rider EAP.app/Contents/Resources"));
|
||||
#endif
|
||||
|
||||
for (const String& directory : subDirectories)
|
||||
|
||||
180
Source/Editor/Scripting/CodeEditors/ZedEditor.cpp
Normal file
180
Source/Editor/Scripting/CodeEditors/ZedEditor.cpp
Normal file
@@ -0,0 +1,180 @@
|
||||
// Copyright (c) Wojciech Figat. All rights reserved.
|
||||
|
||||
#include "ZedEditor.h"
|
||||
#include "Engine/Platform/FileSystem.h"
|
||||
#include "Engine/Platform/CreateProcessSettings.h"
|
||||
#include "Engine/Core/Log.h"
|
||||
#include "Editor/Editor.h"
|
||||
#include "Editor/ProjectInfo.h"
|
||||
#include "Editor/Scripting/ScriptsBuilder.h"
|
||||
#include "Engine/Engine/Globals.h"
|
||||
#if PLATFORM_LINUX
|
||||
#include <stdio.h>
|
||||
#elif PLATFORM_WINDOWS
|
||||
#include "Engine/Platform/Win32/IncludeWindowsHeaders.h"
|
||||
#elif PLATFORM_MAC
|
||||
#include "Engine/Platform/Apple/AppleUtils.h"
|
||||
#include <AppKit/AppKit.h>
|
||||
#endif
|
||||
|
||||
ZedEditor::ZedEditor(const String& execPath)
|
||||
: _execPath(execPath)
|
||||
, _workspacePath(Globals::ProjectFolder)
|
||||
{
|
||||
}
|
||||
|
||||
void ZedEditor::FindEditors(Array<CodeEditor*>* output)
|
||||
{
|
||||
#if PLATFORM_WINDOWS
|
||||
String cmd;
|
||||
if (Platform::ReadRegValue(HKEY_CURRENT_USER, TEXT("SOFTWARE\\Classes\\Applications\\Zed.exe\\shell\\open\\command"), TEXT(""), &cmd) || cmd.IsEmpty())
|
||||
{
|
||||
if (Platform::ReadRegValue(HKEY_LOCAL_MACHINE, TEXT("SOFTWARE\\Classes\\Applications\\Zed.exe\\shell\\open\\command"), TEXT(""), &cmd) || cmd.IsEmpty())
|
||||
{
|
||||
// No hits in registry, try default path instead
|
||||
}
|
||||
}
|
||||
String path;
|
||||
if (cmd.IsEmpty())
|
||||
{
|
||||
path = cmd.Substring(1, cmd.Length() - String(TEXT("\" \"%1\"")).Length() - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
String localAppDataPath;
|
||||
FileSystem::GetSpecialFolderPath(SpecialFolder::LocalAppData, localAppDataPath);
|
||||
path = localAppDataPath / TEXT("Programs/Zed/Zed.exe");
|
||||
}
|
||||
if (FileSystem::FileExists(path))
|
||||
{
|
||||
output->Add(New<ZedEditor>(path));
|
||||
}
|
||||
#elif PLATFORM_LINUX
|
||||
char buffer[128];
|
||||
FILE* pipe = popen("/bin/bash -c \"type -p zed\"", "r");
|
||||
if (pipe)
|
||||
{
|
||||
StringAnsi pathAnsi;
|
||||
while (fgets(buffer, sizeof(buffer), pipe) != NULL)
|
||||
pathAnsi += buffer;
|
||||
pclose(pipe);
|
||||
const String path(pathAnsi.Get(), pathAnsi.Length() != 0 ? pathAnsi.Length() - 1 : 0);
|
||||
if (FileSystem::FileExists(path))
|
||||
{
|
||||
output->Add(New<VisualStudioCodeEditor>(path, false));
|
||||
return;
|
||||
}
|
||||
}
|
||||
{
|
||||
const String path(TEXT("/usr/bin/zed"));
|
||||
if (FileSystem::FileExists(path))
|
||||
{
|
||||
output->Add(New<VisualStudioCodeEditor>(path, false));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Detect Flatpak installations
|
||||
{
|
||||
CreateProcessSettings procSettings;
|
||||
procSettings.FileName = TEXT("/bin/bash -c \"flatpak list --app --columns=application | grep dev.zed.Zed -c\"");
|
||||
procSettings.HiddenWindow = true;
|
||||
if (Platform::CreateProcess(procSettings) == 0)
|
||||
{
|
||||
const String runPath(TEXT("flatpak run dev.zed.Zed"));
|
||||
output->Add(New<VisualStudioCodeEditor>(runPath));
|
||||
return;
|
||||
}
|
||||
}
|
||||
#elif PLATFORM_MAC
|
||||
// Prefer the Zed CLI application over bundled app, as this handles opening files in existing instance better.
|
||||
// The bundle also contains the CLI application under Zed.app/Contents/MacOS/zed, but using this doesn't make any difference.
|
||||
const String cliPath(TEXT("/usr/local/bin/zed"));
|
||||
if (FileSystem::FileExists(cliPath))
|
||||
{
|
||||
output->Add(New<ZedEditor>(cliPath));
|
||||
return;;
|
||||
}
|
||||
|
||||
// System installed app
|
||||
NSURL* AppURL = [[NSWorkspace sharedWorkspace]URLForApplicationWithBundleIdentifier:@"dev.zed.Zed"];
|
||||
if (AppURL != nullptr)
|
||||
{
|
||||
const String path = AppleUtils::ToString((CFStringRef)[AppURL path]);
|
||||
output->Add(New<ZedEditor>(path));
|
||||
return;
|
||||
}
|
||||
|
||||
// Predefined locations
|
||||
String userFolder;
|
||||
FileSystem::GetSpecialFolderPath(SpecialFolder::Documents, userFolder);
|
||||
String paths[3] =
|
||||
{
|
||||
TEXT("/Applications/Zed.app"),
|
||||
userFolder + TEXT("/../Zed.app"),
|
||||
userFolder + TEXT("/../Downloads/Zed.app"),
|
||||
};
|
||||
for (const String& path : paths)
|
||||
{
|
||||
if (FileSystem::DirectoryExists(path))
|
||||
{
|
||||
output->Add(New<ZedEditor>(path));
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
CodeEditorTypes ZedEditor::GetType() const
|
||||
{
|
||||
return CodeEditorTypes::Zed;
|
||||
}
|
||||
|
||||
String ZedEditor::GetName() const
|
||||
{
|
||||
return TEXT("Zed");
|
||||
}
|
||||
|
||||
void ZedEditor::OpenFile(const String& path, int32 line)
|
||||
{
|
||||
// Generate VS solution files for intellisense
|
||||
if (!FileSystem::FileExists(Globals::ProjectFolder / Editor::Project->Name + TEXT(".sln")))
|
||||
{
|
||||
ScriptsBuilder::GenerateProject(TEXT("-vs2022"));
|
||||
}
|
||||
|
||||
// Open file
|
||||
line = line > 0 ? line : 1;
|
||||
CreateProcessSettings procSettings;
|
||||
procSettings.FileName = _execPath;
|
||||
procSettings.Arguments = String::Format(TEXT("\"{0}\" \"{1}:{2}\""), _workspacePath, path, line);
|
||||
procSettings.HiddenWindow = false;
|
||||
procSettings.WaitForEnd = false;
|
||||
procSettings.LogOutput = false;
|
||||
procSettings.ShellExecute = true;
|
||||
Platform::CreateProcess(procSettings);
|
||||
}
|
||||
|
||||
void ZedEditor::OpenSolution()
|
||||
{
|
||||
// Generate VS solution files for intellisense
|
||||
if (!FileSystem::FileExists(Globals::ProjectFolder / Editor::Project->Name + TEXT(".sln")))
|
||||
{
|
||||
ScriptsBuilder::GenerateProject(TEXT("-vs2022"));
|
||||
}
|
||||
|
||||
// Open solution
|
||||
CreateProcessSettings procSettings;
|
||||
procSettings.FileName = _execPath;
|
||||
procSettings.Arguments = String::Format(TEXT("\"{0}\""), _workspacePath);
|
||||
procSettings.HiddenWindow = false;
|
||||
procSettings.WaitForEnd = false;
|
||||
procSettings.LogOutput = false;
|
||||
procSettings.ShellExecute = true;
|
||||
Platform::CreateProcess(procSettings);
|
||||
}
|
||||
|
||||
bool ZedEditor::UseAsyncForOpen() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
41
Source/Editor/Scripting/CodeEditors/ZedEditor.h
Normal file
41
Source/Editor/Scripting/CodeEditors/ZedEditor.h
Normal file
@@ -0,0 +1,41 @@
|
||||
// Copyright (c) Wojciech Figat. All rights reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Editor/Scripting/CodeEditor.h"
|
||||
|
||||
/// <summary>
|
||||
/// Implementation of code editor utility that is using Microsoft Visual Studio Code.
|
||||
/// </summary>
|
||||
class ZedEditor : public CodeEditor
|
||||
{
|
||||
private:
|
||||
|
||||
String _execPath;
|
||||
String _workspacePath;
|
||||
|
||||
public:
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="VisualStudioEditor"/> class.
|
||||
/// </summary>
|
||||
/// <param name="execPath">Executable file path</param>
|
||||
ZedEditor(const String& execPath);
|
||||
|
||||
public:
|
||||
|
||||
/// <summary>
|
||||
/// Tries to find installed Visual Studio Code instance. Adds them to the result list.
|
||||
/// </summary>
|
||||
/// <param name="output">The output editors.</param>
|
||||
static void FindEditors(Array<CodeEditor*>* output);
|
||||
|
||||
public:
|
||||
|
||||
// [CodeEditor]
|
||||
CodeEditorTypes GetType() const override;
|
||||
String GetName() const override;
|
||||
void OpenFile(const String& path, int32 line) override;
|
||||
void OpenSolution() override;
|
||||
bool UseAsyncForOpen() const override;
|
||||
};
|
||||
@@ -114,7 +114,7 @@ namespace Flax.Build.Projects.VisualStudio
|
||||
vcProjectFileContent.AppendLine(" <Keyword>MakeFileProj</Keyword>");
|
||||
if (Version >= VisualStudioVersion.VisualStudio2022)
|
||||
vcProjectFileContent.AppendLine(" <ResolveNuGetPackages>false</ResolveNuGetPackages>");
|
||||
vcProjectFileContent.AppendLine(" <VCTargetsPath Condition=\"$(Configuration.Contains('Linux'))\">./</VCTargetsPath>");
|
||||
vcProjectFileContent.AppendLine(" <VCTargetsPath Condition=\"$(Configuration.Contains('Linux')) or $(Configuration.Contains('Mac'))\">./</VCTargetsPath>");
|
||||
vcProjectFileContent.AppendLine(" </PropertyGroup>");
|
||||
|
||||
// Default properties
|
||||
|
||||
Reference in New Issue
Block a user