From 4fa27a868376a0371bab0628b122444e2919a964 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Tue, 15 May 2018 14:17:49 +0300 Subject: Improved error tracking on stubs ui. --- .../Visual_Studio/Tango.Scripting/ScriptEngine.cs | 90 ++++++++++++++++++++-- 1 file changed, 84 insertions(+), 6 deletions(-) (limited to 'Software/Visual_Studio/Tango.Scripting/ScriptEngine.cs') diff --git a/Software/Visual_Studio/Tango.Scripting/ScriptEngine.cs b/Software/Visual_Studio/Tango.Scripting/ScriptEngine.cs index 23933bf42..72696df10 100644 --- a/Software/Visual_Studio/Tango.Scripting/ScriptEngine.cs +++ b/Software/Visual_Studio/Tango.Scripting/ScriptEngine.cs @@ -1,4 +1,5 @@ using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Scripting; using Microsoft.CodeAnalysis.Scripting; using System; @@ -22,6 +23,12 @@ namespace Tango.Scripting private OnExecuteParameters _onExecuteParameters; public List ReferencedAssemblies { get; private set; } + private class IncludesResult + { + public String File { get; set; } + public List Lines { get; set; } + } + /// /// Initializes a new instance of the class. /// @@ -41,7 +48,8 @@ namespace Tango.Scripting { try { - code = ReplaceIncludes(code, workingFolder); + List includeResults = new List(); + code = ReplaceIncludes(code, workingFolder, includeResults); } catch (Exception ex) { @@ -65,9 +73,11 @@ namespace Tango.Scripting { return Task.Factory.StartNew>(() => { + List includeResults = new List(); + try { - code = ReplaceIncludes(code, workingFolder); + code = ReplaceIncludes(code, workingFolder, includeResults); } catch (Exception ex) { @@ -85,7 +95,41 @@ namespace Tango.Scripting var results = script.Compile(); - return results.Where(x => x.Severity == DiagnosticSeverity.Error).ToList().Select(x => new CompilerError() { Error = x.ToString() }).ToList(); + List errors = new List(); + + foreach (var result in results.Where(x => x.Severity == DiagnosticSeverity.Error)) + { + CompilerError error = new CompilerError(); + error.Error = result.GetMessage(); + error.Character = result.Location.GetMappedLineSpan().StartLinePosition.Character + 1; + + int lineIndex = 0; + IncludesResult include = null; + + + foreach (var inc in includeResults) + { + for (int i = 0; i < inc.Lines.Count; i++) + { + if (inc.Lines[i] == code.ToLines()[result.Location.GetMappedLineSpan().StartLinePosition.Line]) + { + include = inc; + lineIndex = i; + break; + } + } + } + + if (include != null) + { + error.File = Path.GetFileName(include.File); + error.Line = lineIndex + 1; + } + + errors.Add(error); + } + + return errors; }); } @@ -94,7 +138,7 @@ namespace Tango.Scripting return String.Join(", ", _onExecuteParameters.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance).Select(x => x.Name)); } - private String ReplaceIncludes(String code, String workingFolder) + private List GetIncludes(String code, String workingFolder) { if (Directory.Exists(workingFolder)) { @@ -102,6 +146,36 @@ namespace Tango.Scripting } List lines = code.ToLines(); + List includeFiles = new List(); + + for (int i = 0; i < lines.Count; i++) + { + var line = lines[i]; + + if (line.Trim().StartsWith("include")) + { + String path = line.Replace("include", "").Trim().Replace("\"", ""); + + if (!File.Exists(path)) + { + throw new FileNotFoundException("Could not locate include file '" + path + "'."); + } + + includeFiles.Add(path); + } + } + + return includeFiles; + } + + private String ReplaceIncludes(String code, String workingFolder, List includeResults) + { + if (Directory.Exists(workingFolder)) + { + Environment.CurrentDirectory = workingFolder; + } + + List lines = code.ToLines().ToList(); for (int i = 0; i < lines.Count; i++) { @@ -116,7 +190,11 @@ namespace Tango.Scripting throw new FileNotFoundException("Could not locate include file '" + path + "'."); } - String content = ReplaceIncludes(File.ReadAllText(path), Path.GetDirectoryName(path)); + String includeContent = File.ReadAllText(path); + + includeResults.Add(new IncludesResult() { File = path, Lines = includeContent.ToLines() }); + + String content = ReplaceIncludes(includeContent, Path.GetDirectoryName(path), includeResults); if (content.Contains("OnExecute(")) { @@ -148,7 +226,7 @@ namespace Tango.Scripting lines.RemoveAll(x => x.Trim().StartsWith("using")); - return String.Join(Environment.NewLine, usings.Distinct()) + String.Join(Environment.NewLine, lines); + return String.Join(Environment.NewLine, usings.Distinct()) + Environment.NewLine + String.Join(Environment.NewLine, lines); } private ScriptOptions CreateOptions() -- cgit v1.3.1 From e1ce4bbfebc27e9c0ce2b4d305246407273aaed0 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Tue, 15 May 2018 14:38:53 +0300 Subject: Stubs UI v1.6 --- Software/Visual_Studio/Tango.Scripting/ScriptEngine.cs | 1 + .../Tango.Stubs.Installer/Tango.Stubs.Installer.vdproj | 10 +++++----- .../Utilities/Tango.Stubs.UI/Properties/AssemblyInfo.cs | 4 ++-- 3 files changed, 8 insertions(+), 7 deletions(-) (limited to 'Software/Visual_Studio/Tango.Scripting/ScriptEngine.cs') diff --git a/Software/Visual_Studio/Tango.Scripting/ScriptEngine.cs b/Software/Visual_Studio/Tango.Scripting/ScriptEngine.cs index 72696df10..028a42cbc 100644 --- a/Software/Visual_Studio/Tango.Scripting/ScriptEngine.cs +++ b/Software/Visual_Studio/Tango.Scripting/ScriptEngine.cs @@ -77,6 +77,7 @@ namespace Tango.Scripting try { + includeResults.Add(new IncludesResult() { File = "Current Tab", Lines = code.ToLines() }); code = ReplaceIncludes(code, workingFolder, includeResults); } catch (Exception ex) diff --git a/Software/Visual_Studio/Utilities/Tango.Stubs.Installer/Tango.Stubs.Installer.vdproj b/Software/Visual_Studio/Utilities/Tango.Stubs.Installer/Tango.Stubs.Installer.vdproj index c211d8b94..3ccfee70b 100644 --- a/Software/Visual_Studio/Utilities/Tango.Stubs.Installer/Tango.Stubs.Installer.vdproj +++ b/Software/Visual_Studio/Utilities/Tango.Stubs.Installer/Tango.Stubs.Installer.vdproj @@ -471,7 +471,7 @@ "DisplayName" = "8:Debug" "IsDebugOnly" = "11:TRUE" "IsReleaseOnly" = "11:FALSE" - "OutputFilename" = "8:..\\..\\Build\\Debug\\Installers\\Tango Stubs Installer v1.5.msi" + "OutputFilename" = "8:..\\..\\Build\\Debug\\Installers\\Tango Stubs Installer v1.6.msi" "PackageFilesAs" = "3:2" "PackageFileSize" = "3:-2147483648" "CabType" = "3:1" @@ -743,7 +743,7 @@ { "AssemblyRegister" = "3:1" "AssemblyIsInGAC" = "11:FALSE" - "AssemblyAsmDisplayName" = "8:StubsExecutionGUI, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL" + "AssemblyAsmDisplayName" = "8:StubsExecutionGUI, Version=1.6.0.0, Culture=neutral, processorArchitecture=MSIL" "ScatterAssemblies" { "_61BDC9339D1440BCBC454CC904BCE79C" @@ -1384,15 +1384,15 @@ { "Name" = "8:Microsoft Visual Studio" "ProductName" = "8:Tango Stubs GUI" - "ProductCode" = "8:{EE297FB2-0764-4AE6-AA06-50E192E1D4F4}" - "PackageCode" = "8:{83A7897A-0326-4930-A7C4-7ADD9C750BAD}" + "ProductCode" = "8:{B0DA878E-9DF1-4E18-9BDA-F7DE537EC410}" + "PackageCode" = "8:{62FD0C7F-1D82-4E19-8969-62CE23912073}" "UpgradeCode" = "8:{72B680FB-E47D-486A-A81E-6C035F2EBA42}" "AspNetVersion" = "8:4.0.30319.0" "RestartWWWService" = "11:FALSE" "RemovePreviousVersions" = "11:FALSE" "DetectNewerInstalledVersion" = "11:TRUE" "InstallAllUsers" = "11:FALSE" - "ProductVersion" = "8:1.5" + "ProductVersion" = "8:1.6" "Manufacturer" = "8:Twine" "ARPHELPTELEPHONE" = "8:" "ARPHELPLINK" = "8:" diff --git a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Properties/AssemblyInfo.cs b/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Properties/AssemblyInfo.cs index 8b9fdc0f1..c77a71753 100644 --- a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Properties/AssemblyInfo.cs +++ b/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Properties/AssemblyInfo.cs @@ -9,6 +9,6 @@ using System.Runtime.InteropServices; [assembly: AssemblyProduct("Stubs execution utility")] [assembly: AssemblyCopyright("Twine LTD 2018")] [assembly: AssemblyTrademark("Twine LTD")] -[assembly: AssemblyVersion("1.5")] -[assembly: AssemblyFileVersion("1.5")] +[assembly: AssemblyVersion("1.6")] +[assembly: AssemblyFileVersion("1.6")] -- cgit v1.3.1