public static BufferRange ToBufferRange(this Microsoft.SqlTools.ServiceLayer.Workspace.Contracts.Range range) { // It turns out that VSCode sends Range objects as 0-indexed lines, while // our BufferPosition and BufferRange logic assumes 1-indexed. Therefore // need to increment all ranges by 1 when copying internally and reduce // when returning to the caller return(new BufferRange( new BufferPosition(range.Start.Line + 1, range.Start.Character + 1), new BufferPosition(range.End.Line + 1, range.End.Character + 1) )); }
/// <summary> /// Switch from 0-based offsets to 1 based offsets /// </summary> /// <param name="changeRange"></param> /// <param name="insertString"></param> private static FileChange GetFileChangeDetails(Range changeRange, string insertString) { // The protocol's positions are zero-based so add 1 to all offsets return(new FileChange { InsertString = insertString, Line = changeRange.Start.Line + 1, Offset = changeRange.Start.Character + 1, EndLine = changeRange.End.Line + 1, EndOffset = changeRange.End.Character + 1 }); }
/// <summary> /// Switch from 0-based offsets to 1 based offsets /// </summary> /// <param name="changeRange"></param> /// <param name="insertString"></param> private static FileChange GetFileChangeDetails(Microsoft.SqlTools.ServiceLayer.Workspace.Contracts.Range changeRange, string insertString) { // The protocol's positions are zero-based so add 1 to all offsets return(new FileChange { InsertString = insertString, Line = changeRange.Start.Line + 1, Offset = changeRange.Start.Character + 1, EndLine = changeRange.End.Line + 1, EndOffset = changeRange.End.Character + 1 }); }