5
5
namespace OmniSharp . Extensions . LanguageServer . Protocol . Models
6
6
{
7
7
[ DebuggerDisplay ( "{" + nameof ( DebuggerDisplay ) + ",nq}" ) ]
8
- public class Position : IEquatable < Position >
8
+ public class Position : IEquatable < Position > , IComparable < Position > , IComparable
9
9
{
10
10
public Position ( )
11
11
{
@@ -34,6 +34,21 @@ public bool Equals(Position other) =>
34
34
Line == other . Line &&
35
35
Character == other . Character ;
36
36
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
+
37
52
public override int GetHashCode ( )
38
53
{
39
54
var hashCode = 1927683087 ;
@@ -48,6 +63,14 @@ public override int GetHashCode()
48
63
49
64
public static implicit operator Position ( ( int line , int character ) value ) => new Position ( value . line , value . character ) ;
50
65
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
+
51
74
private string DebuggerDisplay => $ "(line: { Line } , char: { Character } )";
52
75
53
76
/// <inheritdoc />
0 commit comments