diff --git a/UIX/Microsoft/Iris/Debug/Symbols/ApplicationDebugSymbols.cs b/UIX/Microsoft/Iris/Debug/Symbols/ApplicationDebugSymbols.cs index 3c012ac..348c5dc 100644 --- a/UIX/Microsoft/Iris/Debug/Symbols/ApplicationDebugSymbols.cs +++ b/UIX/Microsoft/Iris/Debug/Symbols/ApplicationDebugSymbols.cs @@ -2,14 +2,17 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; +using System.Text; namespace Microsoft.Iris.Debug.Symbols; +[CLSCompliant(false)] public class ApplicationDebugSymbols { public List Files { get; set; } } +[CLSCompliant(false)] public class FileDebugSymbols { private string[] _sourceCodeLines; @@ -22,12 +25,8 @@ public class FileDebugSymbols public SourceMap SourceMap { get; } = new(); - public uint OffsetByLineAndColumn(int line, int col) => OffsetByLineAndColumn(new(line, col)); - - public uint OffsetByLineAndColumn(SourcePosition pos) + public (uint Offset, SourceSpan Span) GetLocationFromPosition(SourcePosition pos) { - Assert.IsNotNull(_sourceCodeLines, nameof(_sourceCodeLines)); - var foundLocation = SourceMap.Xml.FirstOrDefault(kvp => { var offset = kvp.Key; @@ -38,7 +37,42 @@ public class FileDebugSymbols if (foundLocation.Equals(default(KeyValuePair))) throw new KeyNotFoundException($"No offset was assigned to line {pos.Line}, column {pos.Column}"); - return foundLocation.Key; + return (foundLocation.Key, foundLocation.Value); + } + + public uint OffsetByLineAndColumn(int line, int col) => OffsetByLineAndColumn(new(line, col)); + + public SourceSpan GetContainingSpan(SourcePosition pos) => GetLocationFromPosition(pos).Span; + + public uint OffsetByLineAndColumn(SourcePosition pos) => GetLocationFromPosition(pos).Offset; + + public string GetSourceSubstring(SourceSpan span) + { + if (!HasSourceCode()) + throw new InvalidOperationException($"Must supply source with {nameof(SetSourceCode)}"); + + span.Start.AsZeroIndexed(out var startLine, out var startColumn); + span.End.AsZeroIndexed(out var endLine, out var endColumn); + + StringBuilder sb = new(); + + int currentLineIndex = startLine; + while (currentLineIndex <= endLine) + { + var line = _sourceCodeLines[currentLineIndex]; + + Index lineStartIndex = currentLineIndex == startLine + ? startColumn + : 0; + + Index lineEndIndex = currentLineIndex == endLine + ? endColumn + : ^1; + + sb.AppendLine(line[lineStartIndex..lineEndIndex]); + } + + return sb.ToString(); } public void SetSourceCode(string source) @@ -47,8 +81,11 @@ public class FileDebugSymbols .Select(s => s.TrimEnd('\r')) .ToArray(); } + + public bool HasSourceCode() => _sourceCodeLines is not null; } +[CLSCompliant(false)] public class SourceMap { public Dictionary Xml { get; } = []; @@ -76,6 +113,12 @@ public class SourcePosition : IComparable, IEquatable Position.CompareTo(other.Position); public bool Equals(SourcePosition other) => Position == other.Position; diff --git a/UIX/Microsoft/Iris/InputHandlers/TextEditingHandler.cs b/UIX/Microsoft/Iris/InputHandlers/TextEditingHandler.cs index 284dcf6..7e1830d 100644 --- a/UIX/Microsoft/Iris/InputHandlers/TextEditingHandler.cs +++ b/UIX/Microsoft/Iris/InputHandlers/TextEditingHandler.cs @@ -16,10 +16,7 @@ using Microsoft.Iris.Session; using Microsoft.Iris.UI; using Microsoft.Iris.ViewItems; using System; - -#if NET6_0_OR_GREATER using Range = Microsoft.Iris.ModelItems.Range; -#endif namespace Microsoft.Iris.InputHandlers { diff --git a/UIX/UIX.csproj b/UIX/UIX.csproj index e8f2874..43fcc1a 100644 --- a/UIX/UIX.csproj +++ b/UIX/UIX.csproj @@ -20,6 +20,7 @@ +