mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-01 01:25:43 -05:00
Mege dev to master (#6)
* Merge master to dev (#4) * Misc. clean-ups related to removing unneeded PowerShell Language Service code. * Remove unneeded files and clean up remaining code. * Enable file change tracking with Workspace and EditorSession. * Merge ServiceHost xUnit test project into dev. (#5) * Setup standard src, test folder structure. Add unit test project. * Actually stage the deletes. Update .gitignore
This commit is contained in:
123
src/ServiceHost/Workspace/BufferRange.cs
Normal file
123
src/ServiceHost/Workspace/BufferRange.cs
Normal file
@@ -0,0 +1,123 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Microsoft.SqlTools.EditorServices
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides details about a range between two positions in
|
||||
/// a file buffer.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("Start = {Start.Line}:{Start.Column}, End = {End.Line}:{End.Column}")]
|
||||
public class BufferRange
|
||||
{
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Provides an instance that represents a range that has not been set.
|
||||
/// </summary>
|
||||
public static readonly BufferRange None = new BufferRange(0, 0, 0, 0);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the start position of the range in the buffer.
|
||||
/// </summary>
|
||||
public BufferPosition Start { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the end position of the range in the buffer.
|
||||
/// </summary>
|
||||
public BufferPosition End { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if the current range is non-zero, i.e.
|
||||
/// contains valid start and end positions.
|
||||
/// </summary>
|
||||
public bool HasRange
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.Equals(BufferRange.None);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the BufferRange class.
|
||||
/// </summary>
|
||||
/// <param name="start">The start position of the range.</param>
|
||||
/// <param name="end">The end position of the range.</param>
|
||||
public BufferRange(BufferPosition start, BufferPosition end)
|
||||
{
|
||||
if (start > end)
|
||||
{
|
||||
throw new ArgumentException(
|
||||
string.Format(
|
||||
"Start position ({0}, {1}) must come before or be equal to the end position ({2}, {3}).",
|
||||
start.Line, start.Column,
|
||||
end.Line, end.Column));
|
||||
}
|
||||
|
||||
this.Start = start;
|
||||
this.End = end;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the BufferRange class.
|
||||
/// </summary>
|
||||
/// <param name="startLine">The 1-based starting line number of the range.</param>
|
||||
/// <param name="startColumn">The 1-based starting column number of the range.</param>
|
||||
/// <param name="endLine">The 1-based ending line number of the range.</param>
|
||||
/// <param name="endColumn">The 1-based ending column number of the range.</param>
|
||||
public BufferRange(
|
||||
int startLine,
|
||||
int startColumn,
|
||||
int endLine,
|
||||
int endColumn)
|
||||
{
|
||||
this.Start = new BufferPosition(startLine, startColumn);
|
||||
this.End = new BufferPosition(endLine, endColumn);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Compares two instances of the BufferRange class.
|
||||
/// </summary>
|
||||
/// <param name="obj">The object to which this instance will be compared.</param>
|
||||
/// <returns>True if the ranges are equal, false otherwise.</returns>
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (!(obj is BufferRange))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
BufferRange other = (BufferRange)obj;
|
||||
|
||||
return
|
||||
this.Start.Equals(other.Start) &&
|
||||
this.End.Equals(other.End);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculates a unique hash code that represents this instance.
|
||||
/// </summary>
|
||||
/// <returns>A hash code representing this instance.</returns>
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return this.Start.GetHashCode() ^ this.End.GetHashCode();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user