From b021dbeae73b9ae7af66ed50571511fabb2707c1 Mon Sep 17 00:00:00 2001 From: Josh Tynjala Date: Fri, 5 Jan 2024 13:41:23 -0800 Subject: [PATCH] lime display: if the project file is newer than an existing debug/release/final.hxml file, don't consider the .hxml file valid anymore Code intelligence should always use the newest hxml content, so the fallback mode where the hxml content is generated, instead of loaded from an existing .hxml file, should be used when the project file is newer. For instance, if the user changes any file/dir paths in their project file, continuing to use the existing .hxml file could lead to confusing error messages that still reference the old/cached file paths. It should always use the latest paths or other values from the project file. It should be considered a bug to use the old cached paths. Previously, as a workaround, the user would need to clean or build their project again to get updated .hxml files. It might also require restarting their editor/IDE too. Bad developer experience when we can detect this case automatically. --- src/lime/tools/HXProject.hx | 6 ++++++ tools/CommandLineTools.hx | 5 +++++ tools/platforms/AndroidPlatform.hx | 7 ++++++- tools/platforms/FlashPlatform.hx | 7 ++++++- tools/platforms/HTML5Platform.hx | 7 ++++++- tools/platforms/IOSPlatform.hx | 7 ++++++- tools/platforms/LinuxPlatform.hx | 7 ++++++- tools/platforms/MacPlatform.hx | 7 ++++++- tools/platforms/TVOSPlatform.hx | 7 ++++++- tools/platforms/WebAssemblyPlatform.hx | 7 ++++++- tools/platforms/WindowsPlatform.hx | 7 ++++++- 11 files changed, 65 insertions(+), 9 deletions(-) diff --git a/src/lime/tools/HXProject.hx b/src/lime/tools/HXProject.hx index 9dd9fb7bb..9c1d38084 100644 --- a/src/lime/tools/HXProject.hx +++ b/src/lime/tools/HXProject.hx @@ -60,6 +60,7 @@ class HXProject extends Script public var templatePaths:Array; @:isVar public var window(get, set):WindowData; public var windows:Array; + public var projectFilePath:String; private var needRerun:Bool; @@ -740,6 +741,11 @@ class HXProject extends Script launchStoryboard.merge(project.launchStoryboard); } + if (projectFilePath == null) + { + projectFilePath = project.projectFilePath; + } + languages = ArrayTools.concatUnique(languages, project.languages, true); libraries = ArrayTools.concatUnique(libraries, project.libraries, true); diff --git a/tools/CommandLineTools.hx b/tools/CommandLineTools.hx index d6248e174..f28d71fc1 100644 --- a/tools/CommandLineTools.hx +++ b/tools/CommandLineTools.hx @@ -1720,6 +1720,11 @@ class CommandLineTools return null; } } + + if (project != null) + { + project.projectFilePath = projectFile; + } } if (project != null && project.needRerun && !project.targetFlags.exists("norerun")) diff --git a/tools/platforms/AndroidPlatform.hx b/tools/platforms/AndroidPlatform.hx index 2509e2b89..407e4461f 100644 --- a/tools/platforms/AndroidPlatform.hx +++ b/tools/platforms/AndroidPlatform.hx @@ -294,7 +294,12 @@ class AndroidPlatform extends PlatformTarget { var path = targetDirectory + "/haxe/" + buildType + ".hxml"; - if (FileSystem.exists(path)) + // try to use the existing .hxml file. however, if the project file was + // modified more recently than the .hxml, then the .hxml cannot be + // considered valid anymore. it may cause errors in editors like vscode. + if (FileSystem.exists(path) + && (project.projectFilePath == null || !FileSystem.exists(project.projectFilePath) + || (FileSystem.stat(path).mtime.getTime() > FileSystem.stat(project.projectFilePath).mtime.getTime()))) { return File.getContent(path); } diff --git a/tools/platforms/FlashPlatform.hx b/tools/platforms/FlashPlatform.hx index 19b4812d5..21828d2a3 100644 --- a/tools/platforms/FlashPlatform.hx +++ b/tools/platforms/FlashPlatform.hx @@ -174,7 +174,12 @@ class FlashPlatform extends PlatformTarget { var path = targetDirectory + "/haxe/" + buildType + ".hxml"; - if (FileSystem.exists(path)) + // try to use the existing .hxml file. however, if the project file was + // modified more recently than the .hxml, then the .hxml cannot be + // considered valid anymore. it may cause errors in editors like vscode. + if (FileSystem.exists(path) + && (project.projectFilePath == null || !FileSystem.exists(project.projectFilePath) + || (FileSystem.stat(path).mtime.getTime() > FileSystem.stat(project.projectFilePath).mtime.getTime()))) { return File.getContent(path); } diff --git a/tools/platforms/HTML5Platform.hx b/tools/platforms/HTML5Platform.hx index 97198ebf4..94d8a45f2 100644 --- a/tools/platforms/HTML5Platform.hx +++ b/tools/platforms/HTML5Platform.hx @@ -213,7 +213,12 @@ class HTML5Platform extends PlatformTarget { var path = targetDirectory + "/haxe/" + buildType + ".hxml"; - if (FileSystem.exists(path)) + // try to use the existing .hxml file. however, if the project file was + // modified more recently than the .hxml, then the .hxml cannot be + // considered valid anymore. it may cause errors in editors like vscode. + if (FileSystem.exists(path) + && (project.projectFilePath == null || !FileSystem.exists(project.projectFilePath) + || (FileSystem.stat(path).mtime.getTime() > FileSystem.stat(project.projectFilePath).mtime.getTime()))) { return File.getContent(path); } diff --git a/tools/platforms/IOSPlatform.hx b/tools/platforms/IOSPlatform.hx index e03754c3a..33197d9a3 100644 --- a/tools/platforms/IOSPlatform.hx +++ b/tools/platforms/IOSPlatform.hx @@ -456,7 +456,12 @@ class IOSPlatform extends PlatformTarget { var path = targetDirectory + "/" + project.app.file + "/haxe/Build.hxml"; - if (FileSystem.exists(path)) + // try to use the existing .hxml file. however, if the project file was + // modified more recently than the .hxml, then the .hxml cannot be + // considered valid anymore. it may cause errors in editors like vscode. + if (FileSystem.exists(path) + && (project.projectFilePath == null || !FileSystem.exists(project.projectFilePath) + || (FileSystem.stat(path).mtime.getTime() > FileSystem.stat(project.projectFilePath).mtime.getTime()))) { return File.getContent(path); } diff --git a/tools/platforms/LinuxPlatform.hx b/tools/platforms/LinuxPlatform.hx index d032080f1..4ee5a9161 100644 --- a/tools/platforms/LinuxPlatform.hx +++ b/tools/platforms/LinuxPlatform.hx @@ -362,7 +362,12 @@ class LinuxPlatform extends PlatformTarget { var path = targetDirectory + "/haxe/" + buildType + ".hxml"; - if (FileSystem.exists(path)) + // try to use the existing .hxml file. however, if the project file was + // modified more recently than the .hxml, then the .hxml cannot be + // considered valid anymore. it may cause errors in editors like vscode. + if (FileSystem.exists(path) + && (project.projectFilePath == null || !FileSystem.exists(project.projectFilePath) + || (FileSystem.stat(path).mtime.getTime() > FileSystem.stat(project.projectFilePath).mtime.getTime()))) { return File.getContent(path); } diff --git a/tools/platforms/MacPlatform.hx b/tools/platforms/MacPlatform.hx index 4f80be65a..2545bdc43 100644 --- a/tools/platforms/MacPlatform.hx +++ b/tools/platforms/MacPlatform.hx @@ -341,7 +341,12 @@ class MacPlatform extends PlatformTarget { var path = targetDirectory + "/haxe/" + buildType + ".hxml"; - if (FileSystem.exists(path)) + // try to use the existing .hxml file. however, if the project file was + // modified more recently than the .hxml, then the .hxml cannot be + // considered valid anymore. it may cause errors in editors like vscode. + if (FileSystem.exists(path) + && (project.projectFilePath == null || !FileSystem.exists(project.projectFilePath) + || (FileSystem.stat(path).mtime.getTime() > FileSystem.stat(project.projectFilePath).mtime.getTime()))) { return File.getContent(path); } diff --git a/tools/platforms/TVOSPlatform.hx b/tools/platforms/TVOSPlatform.hx index 54aae23b7..e0273b3b3 100644 --- a/tools/platforms/TVOSPlatform.hx +++ b/tools/platforms/TVOSPlatform.hx @@ -371,7 +371,12 @@ class TVOSPlatform extends PlatformTarget { var path = targetDirectory + "/" + project.app.file + "/haxe/Build.hxml"; - if (FileSystem.exists(path)) + // try to use the existing .hxml file. however, if the project file was + // modified more recently than the .hxml, then the .hxml cannot be + // considered valid anymore. it may cause errors in editors like vscode. + if (FileSystem.exists(path) + && (project.projectFilePath == null || !FileSystem.exists(project.projectFilePath) + || (FileSystem.stat(path).mtime.getTime() > FileSystem.stat(project.projectFilePath).mtime.getTime()))) { return File.getContent(path); } diff --git a/tools/platforms/WebAssemblyPlatform.hx b/tools/platforms/WebAssemblyPlatform.hx index 69fbdb2f2..a8130365c 100644 --- a/tools/platforms/WebAssemblyPlatform.hx +++ b/tools/platforms/WebAssemblyPlatform.hx @@ -359,7 +359,12 @@ class WebAssemblyPlatform extends PlatformTarget { var path = targetDirectory + "/haxe/" + buildType + ".hxml"; - if (FileSystem.exists(path)) + // try to use the existing .hxml file. however, if the project file was + // modified more recently than the .hxml, then the .hxml cannot be + // considered valid anymore. it may cause errors in editors like vscode. + if (FileSystem.exists(path) + && (project.projectFilePath == null || !FileSystem.exists(project.projectFilePath) + || (FileSystem.stat(path).mtime.getTime() > FileSystem.stat(project.projectFilePath).mtime.getTime()))) { return File.getContent(path); } diff --git a/tools/platforms/WindowsPlatform.hx b/tools/platforms/WindowsPlatform.hx index 46433c6e9..7a754c849 100644 --- a/tools/platforms/WindowsPlatform.hx +++ b/tools/platforms/WindowsPlatform.hx @@ -593,7 +593,12 @@ class WindowsPlatform extends PlatformTarget { var path = targetDirectory + "/haxe/" + buildType + ".hxml"; - if (FileSystem.exists(path)) + // try to use the existing .hxml file. however, if the project file was + // modified more recently than the .hxml, then the .hxml cannot be + // considered valid anymore. it may cause errors in editors like vscode. + if (FileSystem.exists(path) + && (project.projectFilePath == null || !FileSystem.exists(project.projectFilePath) + || (FileSystem.stat(path).mtime.getTime() > FileSystem.stat(project.projectFilePath).mtime.getTime()))) { return File.getContent(path); }