Skip to content

Commit

Permalink
fix #106 Run-configurations for Godot without C#
Browse files Browse the repository at this point in the history
  • Loading branch information
van800 committed Jan 12, 2024
1 parent 343bc99 commit 2a7210b
Show file tree
Hide file tree
Showing 12 changed files with 116 additions and 61 deletions.
12 changes: 6 additions & 6 deletions resharper/src/ProjectModel/GodotMessagingClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
using GodotTools.IdeMessaging;
using GodotTools.IdeMessaging.Requests;
using JetBrains.Application.Threading;
using JetBrains.Application.Threading.Tasks;
using JetBrains.Collections.Viewable;
using JetBrains.Lifetimes;
using JetBrains.ProjectModel;
using JetBrains.Rd.Base;
using JetBrains.ReSharper.Feature.Services.Protocol;
using JetBrains.Rider.Model.Godot.FrontendBackend;
using JetBrains.Threading;
using JetBrains.Util;
using ILogger = JetBrains.Util.ILogger;

Expand All @@ -30,9 +28,11 @@ public GodotMessagingClient(ISolution solution, ILogger logger, Lifetime lifetim
myLogger = logger;
var model = solution.GetProtocolSolution().GetGodotFrontendBackendModel();

model.MainProjectBasePath.AdviseOnce(lifetime, baseDir =>
model.GodotDescriptor.AdviseOnce(lifetime, descriptor =>
{
myClient = new Client(Identity, baseDir, this, this);
if (descriptor.IsPureGdScriptProject) return;
myClient = new Client(Identity, descriptor.MainProjectBasePath, this, this);
SubscribeConnected(logger, threading, model);
SubscribeDisconnected(logger, threading, model);
myClient.Start();
Expand All @@ -42,7 +42,7 @@ public GodotMessagingClient(ISolution solution, ILogger logger, Lifetime lifetim
private void SubscribeDisconnected(ILogger logger, IThreading threading, GodotFrontendBackendModel model)
{
// it looks like it subscribes to be called just once
myClient.AwaitDisconnected().ContinueWith(task =>
myClient.AwaitDisconnected().ContinueWith(_ =>
{
logger.Info("Godot Editor disconnected...");
model.EditorState.SetValue(GodotEditorState.Disconnected);
Expand All @@ -52,7 +52,7 @@ private void SubscribeDisconnected(ILogger logger, IThreading threading, GodotFr

private void SubscribeConnected(ILogger logger, IThreading threading, GodotFrontendBackendModel model)
{
myClient.AwaitConnected().ContinueWith(task =>
myClient.AwaitConnected().ContinueWith(_ =>
{
logger.Info("Godot Editor connected...");
model.EditorState.SetValue(GodotEditorState.Connected);
Expand Down
7 changes: 6 additions & 1 deletion resharper/src/ProjectModel/GodotTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ public class GodotTracker
public GodotTracker(ISolution solution, ILogger logger, ISolutionLoadTasksScheduler tasksScheduler)
{
var model = solution.GetProtocolSolution().GetGodotFrontendBackendModel();
if (solution.SolutionFile == null && solution.SolutionDirectory.Combine("project.godot").ExistsFile)
{
model.GodotDescriptor.SetValue(new GodotDescriptor(true, solution.SolutionDirectory.FullPath));
}

tasksScheduler.EnqueueTask(new SolutionLoadTask(GetType(),
SolutionLoadTaskKinds.Done,
() =>
Expand All @@ -25,7 +30,7 @@ public GodotTracker(ISolution solution, ILogger logger, ISolutionLoadTasksSchedu
if (!file.ExistsFile) continue;
MainProjectBasePath = file.Directory;
logger.Verbose($"Godot MainProjectBasePath: {file.Directory}");
model.MainProjectBasePath.SetValue(file.Directory.FullPath);
model.GodotDescriptor.SetValue(new GodotDescriptor(false, file.Directory.FullPath));
break;
}
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ object GodotFrontendBackendModel : Ext(SolutionModel.Solution) {
+"Connected"
}

val GodotDescriptor = structdef("GodotDescriptor"){
field("isPureGdScriptProject", bool).documentation = "True for pure GdScript project"
field("mainProjectBasePath", string).documentation = "Path to the folder with the project.godot"
}

init {
setting(Kotlin11Generator.Namespace, "com.jetbrains.rider.model.godot.frontendBackend")
setting(CSharp50Generator.Namespace, "JetBrains.Rider.Model.Godot.FrontendBackend")
Expand All @@ -34,13 +39,14 @@ object GodotFrontendBackendModel : Ext(SolutionModel.Solution) {

// Misc backend/fronted context
property("godotPath", string).documentation = "Path to GodotEditor"
property("mainProjectBasePath", string).documentation = "Path to the folder with the project.godot"

// Settings stored in the backend
field("backendSettings", aggregatedef("GodotBackendSettings") {
property("enableDebuggerExtensions", bool)
})

property("godotDescriptor", GodotDescriptor)

property("editorState", GodotEditorState)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ class FrontendBackendHost(project: Project) : LifetimedService() {
task
}

GodotProjectDiscoverer.getInstance(project).godotMonoPath.adviseNotNull(lifetime){
GodotProjectDiscoverer.getInstance(project).godot3Path.adviseNotNull(lifetime){
model.godotPath.set(it)
}

GodotProjectDiscoverer.getInstance(project).godotCorePath.adviseNotNull(lifetime){ s ->
GodotProjectDiscoverer.getInstance(project).godot4Path.adviseNotNull(lifetime){ s ->

RiderDebuggerWorkerModelManager.getModels().adviseNotNull(lifetime){
model.backendSettings.enableDebuggerExtensions.flowInto(lifetime,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.jetbrains.rd.util.lifetime.Lifetime
import com.jetbrains.rd.util.reactive.IProperty
import com.jetbrains.rd.util.reactive.Property
import com.jetbrains.rd.util.reactive.adviseNotNull
import com.jetbrains.rider.model.godot.frontendBackend.GodotDescriptor
import com.jetbrains.rider.model.godot.frontendBackend.GodotFrontendBackendModel
import com.jetbrains.rider.plugins.godot.run.GodotRunConfigurationGenerator
import com.jetbrains.rider.plugins.godot.run.configurations.GodotDebugRunConfiguration
Expand All @@ -24,18 +25,19 @@ import java.io.File
@Service(Service.Level.PROJECT)
class GodotProjectDiscoverer(project: Project) : LifetimedService() {

val mainProjectBasePath : IProperty<String?> = Property(null)
val godotDescriptor : IProperty<GodotDescriptor?> = Property(null)
private val logger = Logger.getInstance(GodotProjectDiscoverer::class.java)
val godotMonoPath : IProperty<String?> = Property(null)
val godotCorePath : IProperty<String?> = Property(null)
val godot3Path : IProperty<String?> = Property(null)
val godot4Path : IProperty<String?> = Property(null)

init {
mainProjectBasePath.adviseNotNull(project.lifetime){
logger.info("Godot mainProjectBasePath: $it")
godotMonoPath.set(
MetadataMonoFileWatcher.Util.getFromMonoMetadataPath(it)
?: MetadataMonoFileWatcher.Util.getGodotPath(it) ?: getGodotPathFromPlayerRunConfiguration(project))
godotCorePath.set(MetadataCoreFileWatcher.Util.getGodotPath(it) ?: getGodotPathFromCorePlayerRunConfiguration(project))
godotDescriptor.adviseNotNull(project.lifetime){
logger.info("Godot godotDescriptor: $it")
val basePath = File(it.mainProjectBasePath)
godot3Path.set(
MetadataMonoFileWatcher.Util.getFromMonoMetadataPath(basePath)
?: MetadataMonoFileWatcher.Util.getGodotPath(basePath) ?: getGodotPathFromPlayerRunConfiguration(project))
godot4Path.set(MetadataCoreFileWatcher.Util.getGodotPath(basePath) ?: getGodotPathFromCorePlayerRunConfiguration(project))
}
}

Expand Down Expand Up @@ -78,8 +80,8 @@ class GodotProjectDiscoverer(project: Project) : LifetimedService() {
session: ClientProjectSession,
model: GodotFrontendBackendModel
) {
model.mainProjectBasePath.adviseNotNull(lifetime) {
getInstance(session.project).mainProjectBasePath.set(it)
model.godotDescriptor.adviseNotNull(lifetime){
getInstance(session.project).godotDescriptor.set(it)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ import kotlin.io.path.isDirectory
class MetadataCoreFileWatcher : ProjectActivity {

object Util {
fun getGodotPath(mainProjectBasePath: String): String? {
val projectPath = File(mainProjectBasePath)
fun getGodotPath(projectPath: File): String? {
val projectMetadataCfg = projectPath.resolve(cfgDir).resolve(cfgFileName)

if (projectMetadataCfg.exists()) {
Expand All @@ -53,10 +52,11 @@ class MetadataCoreFileWatcher : ProjectActivity {
withContext(Dispatchers.EDT) {
project.solution.isLoaded.whenTrue(project.lifetime) {l->
val godotDiscoverer = GodotProjectDiscoverer.getInstance(project)
godotDiscoverer.mainProjectBasePath.viewNotNull(l) { lt, mainProjectBasePath ->
godotDiscoverer.godotDescriptor.viewNotNull(l) { lt, descriptor ->
val mainProjectBaseFile = File(descriptor.mainProjectBasePath)
lt.launchBackground {
val watchService: WatchService = FileSystems.getDefault().newWatchService()
val metaFileDir = File(mainProjectBasePath).resolve(cfgDir).toPath()
val metaFileDir = mainProjectBaseFile.resolve(cfgDir).toPath()

withTimeout(Duration.ofMinutes(5)) {
while (!(metaFileDir.isDirectory())) {
Expand All @@ -81,11 +81,11 @@ class MetadataCoreFileWatcher : ProjectActivity {
val context = event.context() ?: continue
if (context.toString() == cfgFileName) {
logger.info("GodotCoreProjectDiscoverer.getInstance(project).godotPath.set()")
val newPath = Util.getGodotPath(mainProjectBasePath) ?: continue
val newPath = Util.getGodotPath(mainProjectBaseFile) ?: continue
logger.info("GodotCoreProjectDiscoverer.getInstance(project).godotPath.set($newPath)")
application.invokeLater {
logger.info("application.invokeLater GodotProjectDiscoverer.getInstance(project).godotPath.set($newPath)")
GodotProjectDiscoverer.getInstance(project).godotCorePath.set(newPath)
GodotProjectDiscoverer.getInstance(project).godot4Path.set(newPath)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class MetadataMonoFileWatcher : ProjectActivity {
//Windows: %APPDATA%\Godot\projects\{PROJECT_NAME}_{MD5_OF_PROJECT_PATH}\
//macOS: $XDG_DATA_HOME/Godot/projects/{PROJECT_NAME}_{MD5_OF_PROJECT_PATH}/ or $HOME/Library/Application Support/Godot/projects/{PROJECT_NAME}_{MD5_OF_PROJECT_PATH}/
//Linux: $XDG_DATA_HOME/godot/projects/{PROJECT_NAME}_{MD5_OF_PROJECT_PATH}/ or $HOME/.local/share/godot/projects/{PROJECT_NAME}_{MD5_OF_PROJECT_PATH}/
fun getGodotPath(projectPath: String): String? {
fun getGodotPath(projectPath: File): String? {
val projectsSettingsPath = if (SystemInfo.isMac) {
val home = Paths.get(System.getenv("HOME"))
home.resolve("Library/Application Support/Godot/projects")
Expand All @@ -43,8 +43,8 @@ class MetadataMonoFileWatcher : ProjectActivity {
} else
throw Exception("Unexpected OS.")

val md5 = projectPath.md5()
val projectSettingsPath = projectsSettingsPath.resolve("${Paths.get(projectPath).fileName}-$md5")
val md5 = projectPath.path.md5()
val projectSettingsPath = projectsSettingsPath.resolve("${projectPath.toPath().fileName}-$md5")
val projectMetadataCfg = projectSettingsPath.resolve("project_metadata.cfg").toFile()

if (projectMetadataCfg.exists()) {
Expand All @@ -63,8 +63,7 @@ class MetadataMonoFileWatcher : ProjectActivity {
return BigInteger(1, md.digest(toByteArray())).toString(16).padStart(32, '0')
}

fun getFromMonoMetadataPath(mainProjectBasePath: String): String? {
val basePath = File(mainProjectBasePath)
fun getFromMonoMetadataPath(basePath: File): String? {
var metaFile = basePath.resolve(metaFileDir).resolve(metaFileName)
if (!metaFile.exists())
metaFile = basePath.resolve(metaFileDir).resolve(oldMetaFileName)
Expand Down Expand Up @@ -92,10 +91,12 @@ class MetadataMonoFileWatcher : ProjectActivity {
withContext(Dispatchers.EDT) {
project.solution.isLoaded.whenTrue(project.lifetime) { l ->
val godotDiscoverer = GodotProjectDiscoverer.getInstance(project)
godotDiscoverer.mainProjectBasePath.viewNotNull(l) { lt, mainProjectBasePath ->
godotDiscoverer.godotDescriptor.viewNotNull(l) { lt, descriptor ->
if (descriptor.isPureGdScriptProject) return@viewNotNull
val mainProjectBasePath = File(descriptor.mainProjectBasePath)
thread(name = "MetadataFileWatcher") {
val watchService: WatchService = FileSystems.getDefault().newWatchService()
val metaFileDir = File(mainProjectBasePath).resolve(metaFileDir).toPath()
val metaFileDir = mainProjectBasePath.resolve(metaFileDir).toPath()

if (!(metaFileDir.isDirectory()))
return@thread
Expand All @@ -117,7 +118,7 @@ class MetadataMonoFileWatcher : ProjectActivity {
logger.info("GodotProjectDiscoverer.getInstance(project).godotPath.set($newPath)")
application.invokeLater {
logger.info("application.invokeLater GodotProjectDiscoverer.getInstance(project).godotPath.set($newPath)")
GodotProjectDiscoverer.getInstance(project).godotMonoPath.set(newPath)
GodotProjectDiscoverer.getInstance(project).godot3Path.set(newPath)
}
}
}
Expand Down
Loading

0 comments on commit 2a7210b

Please sign in to comment.