55namespace OmniSharp . Extensions . LanguageServer . Protocol . Models
66{
77 [ DebuggerDisplay ( "{" + nameof ( DebuggerDisplay ) + ",nq}" ) ]
8- public class Position : IEquatable < Position >
8+ public class Position : IEquatable < Position > , IComparable < Position > , IComparable
99 {
1010 public Position ( )
1111 {
@@ -34,6 +34,21 @@ public bool Equals(Position other) =>
3434 Line == other . Line &&
3535 Character == other . Character ;
3636
37+ public int CompareTo ( Position other )
38+ {
39+ if ( ReferenceEquals ( this , other ) ) return 0 ;
40+ if ( ReferenceEquals ( null , other ) ) return 1 ;
41+ var lineComparison = Line . CompareTo ( other . Line ) ;
42+ return lineComparison != 0 ? lineComparison : Character . CompareTo ( other . Character ) ;
43+ }
44+
45+ public int CompareTo ( object obj )
46+ {
47+ if ( ReferenceEquals ( null , obj ) ) return 1 ;
48+ if ( ReferenceEquals ( this , obj ) ) return 0 ;
49+ return obj is Position other ? CompareTo ( other ) : throw new ArgumentException ( $ "Object must be of type { nameof ( Position ) } ") ;
50+ }
51+
3752 public override int GetHashCode ( )
3853 {
3954 var hashCode = 1927683087 ;
@@ -48,6 +63,14 @@ public override int GetHashCode()
4863
4964 public static implicit operator Position ( ( int line , int character ) value ) => new Position ( value . line , value . character ) ;
5065
66+ public static bool operator < ( Position left , Position right ) => Comparer < Position > . Default . Compare ( left , right ) < 0 ;
67+
68+ public static bool operator > ( Position left , Position right ) => Comparer < Position > . Default . Compare ( left , right ) > 0 ;
69+
70+ public static bool operator <= ( Position left , Position right ) => Comparer < Position > . Default . Compare ( left , right ) <= 0 ;
71+
72+ public static bool operator >= ( Position left , Position right ) => Comparer < Position > . Default . Compare ( left , right ) >= 0 ;
73+
5174 private string DebuggerDisplay => $ "(line: { Line } , char: { Character } )";
5275
5376 /// <inheritdoc />
0 commit comments