From dad04463ae0bc431626a53fb360f7f4cd04fc3a9 Mon Sep 17 00:00:00 2001 From: PTKu <61538034+PTKu@users.noreply.github.com> Date: Thu, 27 Mar 2025 10:00:45 +0100 Subject: [PATCH 1/2] Enhance logging and update launch settings - Enhanced logging in `SemanticsHelpers` class to include filename and line position for type access issues. --- .../Helpers/SemanticsHelpers.cs | 25 ++++++++++++++----- .../src/ixc/Properties/launchSettings.json | 4 +-- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/AXSharp.compiler/src/AXSharp.Cs.Compiler/Helpers/SemanticsHelpers.cs b/src/AXSharp.compiler/src/AXSharp.Cs.Compiler/Helpers/SemanticsHelpers.cs index ef26dd7f..7abb0efb 100644 --- a/src/AXSharp.compiler/src/AXSharp.Cs.Compiler/Helpers/SemanticsHelpers.cs +++ b/src/AXSharp.compiler/src/AXSharp.Cs.Compiler/Helpers/SemanticsHelpers.cs @@ -14,6 +14,7 @@ using AXSharp.Compiler.Cs.Helpers; using AXSharp.Connector; + namespace AXSharp.Compiler.Cs; /// @@ -76,15 +77,27 @@ public static ITypeDeclaration FindTypeDeclaration(this Compilation compilation, return candidates.First(); } - if (candidates.Count() == 0) + try { - Log.Logger.Warning($"Type '{typeAccess?.ToString()}' not found in the semantic tree."); - } + var span = typeAccess?.Location?.GetLineSpan(); + var line = span.Value.StartLinePosition.Line; + var character = span.Value.StartLinePosition.Character; + if (candidates.Count() == 0) + { + Log.Logger.Warning($"{span?.Filename}({line}:{character}) : Type '{typeAccess.TypeSymbol.Name}' not found the type may not be eligible for transpile or meta information is not available because this type is not defined in AX# compliant project. "); + } - if (candidates.Count() > 1) + if (candidates.Count() > 1) + { + Log.Logger.Warning($"{span?.Filename}({line}:{character}) : Multiple types found for '{typeAccess.TypeSymbol.Name}' the declaration appears ambiguous. You may need to fully qualify the declaration."); + } + } + catch { - Log.Logger.Warning($"Multiple types found for '{typeAccess?.ToString()}' in the semantic tree. You may need to fully qualify the declaration."); + + // swallow } + return null; } @@ -113,7 +126,7 @@ public static ITypeDeclaration FindTypeDeclaration(this Compilation compilation, if (candidates.Count() == 0) { - Log.Logger.Warning($"Type '{typeAccess?.ToString()}' not found in the semantic tree."); + Log.Logger.Warning($"Type '{typeAccess?.ToString()}' not found in the semantic tree. {typeAccess?.Location}"); } if (candidates.Count() > 1) diff --git a/src/AXSharp.compiler/src/ixc/Properties/launchSettings.json b/src/AXSharp.compiler/src/ixc/Properties/launchSettings.json index 0512722a..7cefe928 100644 --- a/src/AXSharp.compiler/src/ixc/Properties/launchSettings.json +++ b/src/AXSharp.compiler/src/ixc/Properties/launchSettings.json @@ -9,12 +9,12 @@ "workingDirectory": "c:\\W\\Develop\\gh\\inxton\\axopen\\src\\integrations\\ctrl\\" }, "ixc-simple-template": { - "commandName": "Project", - "commandLineArgs": "--skip-deps", + "commandName": "Project", "workingDirectory": "C:\\W\\Develop\\gh\\inxton\\simatic-ax\\axopen.templates\\axopen.template.simple\\ax" }, "ixc-template-ref": { "commandName": "Project", + "commandLineArgs": "--skip-deps", "workingDirectory": "C:\\W\\Develop\\gh\\inxton\\axopen\\src\\templates.simple\\ctrl" }, "ax-connectors-test-project": { From 88ab84f9568e8755c8e02ece2a67c73fb0a42b37 Mon Sep 17 00:00:00 2001 From: PTKu <61538034+PTKu@users.noreply.github.com> Date: Thu, 27 Mar 2025 10:05:53 +0100 Subject: [PATCH 2/2] Improve error handling in SemanticsHelpers.cs Updated the catch block in the SemanticsHelpers class to log a warning message using Log.Logger.Warning when an exception is caught. This change enhances visibility into potential issues by providing a warning message that indicates the system failed to determine the location of the type declaration for the specified typeAccess?.TypeSymbol?.Name. --- .../src/AXSharp.Cs.Compiler/Helpers/SemanticsHelpers.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/AXSharp.compiler/src/AXSharp.Cs.Compiler/Helpers/SemanticsHelpers.cs b/src/AXSharp.compiler/src/AXSharp.Cs.Compiler/Helpers/SemanticsHelpers.cs index 7abb0efb..f0a0f5a7 100644 --- a/src/AXSharp.compiler/src/AXSharp.Cs.Compiler/Helpers/SemanticsHelpers.cs +++ b/src/AXSharp.compiler/src/AXSharp.Cs.Compiler/Helpers/SemanticsHelpers.cs @@ -94,8 +94,7 @@ public static ITypeDeclaration FindTypeDeclaration(this Compilation compilation, } catch { - - // swallow + Log.Logger.Warning($"Failed to determine the location of the type declaration for `{typeAccess?.TypeSymbol?.Name}`."); }