// // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. // namespace Microsoft.SqlTools.EditorServices { /// /// Provides details and operations for a buffer position in a /// specific file. /// public class FilePosition : BufferPosition { public FilePosition( ScriptFile scriptFile, int line, int column) : base(line, column) { } #if false #region Private Fields private ScriptFile scriptFile; #endregion #region Constructors /// /// Creates a new FilePosition instance for the 1-based line and /// column numbers in the specified file. /// /// The ScriptFile in which the position is located. /// The 1-based line number in the file. /// The 1-based column number in the file. public FilePosition( ScriptFile scriptFile, int line, int column) : base(line, column) { this.scriptFile = scriptFile; } /// /// Creates a new FilePosition instance for the specified file by /// copying the specified BufferPosition /// /// The ScriptFile in which the position is located. /// The original BufferPosition from which the line and column will be copied. public FilePosition( ScriptFile scriptFile, BufferPosition copiedPosition) : this(scriptFile, copiedPosition.Line, copiedPosition.Column) { scriptFile.ValidatePosition(copiedPosition); } #endregion #region Public Methods /// /// Gets a FilePosition relative to this position by adding the /// provided line and column offset relative to the contents of /// the current file. /// /// The line offset to add to this position. /// The column offset to add to this position. /// A new FilePosition instance for the calculated position. public FilePosition AddOffset(int lineOffset, int columnOffset) { return this.scriptFile.CalculatePosition( this, lineOffset, columnOffset); } /// /// Gets a FilePosition for the line and column position /// of the beginning of the current line after any initial /// whitespace for indentation. /// /// A new FilePosition instance for the calculated position. public FilePosition GetLineStart() { string scriptLine = scriptFile.FileLines[this.Line - 1]; int lineStartColumn = 1; for (int i = 0; i < scriptLine.Length; i++) { if (!char.IsWhiteSpace(scriptLine[i])) { lineStartColumn = i + 1; break; } } return new FilePosition(this.scriptFile, this.Line, lineStartColumn); } /// /// Gets a FilePosition for the line and column position /// of the end of the current line. /// /// A new FilePosition instance for the calculated position. public FilePosition GetLineEnd() { string scriptLine = scriptFile.FileLines[this.Line - 1]; return new FilePosition(this.scriptFile, this.Line, scriptLine.Length + 1); } #endregion #endif } }