Struct SourcePosition
A position in a source document, expressed as a zero-based line number and a zero-based character offset.
public readonly record struct SourcePosition : IComparable<SourcePosition>, IEquatable<SourcePosition>
- Implements
- Inherited Members
- Extension Methods
Remarks
👉 Character offsets count UTF-16 code units, consistent with both the LSP default position encoding and the native encoding of VBA (BSTR) strings.
Constructors
SourcePosition(int, int)
A position in a source document, expressed as a zero-based line number and a zero-based character offset.
public SourcePosition(int Line, int Character)
Parameters
Remarks
👉 Character offsets count UTF-16 code units, consistent with both the LSP default position encoding and the native encoding of VBA (BSTR) strings.
Properties
Character
The zero-based character offset within the line.
public int Character { get; init; }
Property Value
Line
The zero-based line number.
public int Line { get; init; }
Property Value
Zero
Position L0C0.
public static SourcePosition Zero { get; }
Property Value
Methods
AnchoredAt(SourcePosition)
Translates this position, which is relative to a fragment of a document, into a position in that
document — where anchor is where the fragment itself begins in it.
public SourcePosition AnchoredAt(SourcePosition anchor)
Parameters
anchorSourcePositionThe position, in the document, of the fragment's first character.
Returns
- SourcePosition
The same point in the source, expressed in the document's own coordinates.
Remarks
👉 This is not a vector addition, and operator + is not a substitute for it. The
anchor's Character applies only to the fragment's first line, because that is the
only line the fragment shares with what precedes it: every later line of the fragment starts at
the document's column 0 just as it starts at the fragment's. Adding the anchor's character offset
to every line instead pushes each line after the first that many columns to the right.
CompareTo(SourcePosition)
Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.
public int CompareTo(SourcePosition other)
Parameters
otherSourcePositionAn object to compare with this instance.
Returns
- int
A value that indicates the relative order of the objects being compared. The return value has these meanings:
Value Meaning Less than zero This instance precedes otherin the sort order.Zero This instance occurs in the same position in the sort order as other.Greater than zero This instance follows otherin the sort order.
Equals(SourcePosition)
Indicates whether the current object is equal to another object of the same type.
public bool Equals(SourcePosition other)
Parameters
otherSourcePositionAn object to compare with this object.
Returns
GetHashCode()
Returns the hash code for this instance.
public override int GetHashCode()
Returns
- int
A 32-bit signed integer that is the hash code for this instance.
ToString()
A string representation of this source position.
public override string ToString()
Returns
- string
Line/Character position in a
L0C0notation
Remarks
For internal/debugging purposes only: this representation is not intended to be surfaced.
Operators
operator +(SourcePosition, SourcePosition)
public static SourcePosition operator +(SourcePosition left, SourcePosition right)
Parameters
leftSourcePositionrightSourcePosition
Returns
operator >(SourcePosition, SourcePosition)
public static bool operator >(SourcePosition left, SourcePosition right)
Parameters
leftSourcePositionrightSourcePosition
Returns
operator >=(SourcePosition, SourcePosition)
public static bool operator >=(SourcePosition left, SourcePosition right)
Parameters
leftSourcePositionrightSourcePosition
Returns
operator <(SourcePosition, SourcePosition)
public static bool operator <(SourcePosition left, SourcePosition right)
Parameters
leftSourcePositionrightSourcePosition
Returns
operator <=(SourcePosition, SourcePosition)
public static bool operator <=(SourcePosition left, SourcePosition right)
Parameters
leftSourcePositionrightSourcePosition
Returns
operator -(SourcePosition, SourcePosition)
public static SourcePosition operator -(SourcePosition left, SourcePosition right)
Parameters
leftSourcePositionrightSourcePosition