Table of Contents

Struct SourcePosition

Namespace
RDCore.SDK.Model.Source
Assembly
RDCore.SDK.dll

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

Line int

The zero-based line number.

Character int

The zero-based character offset within the line.

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

int

Line

The zero-based line number.

public int Line { get; init; }

Property Value

int

Zero

Position L0C0.

public static SourcePosition Zero { get; }

Property Value

SourcePosition

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

anchor SourcePosition

The 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

other SourcePosition

An 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 other in the sort order.
Zero This instance occurs in the same position in the sort order as other.
Greater than zero This instance follows other in 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

other SourcePosition

An object to compare with this object.

Returns

bool

true if the current object is equal to the other parameter; otherwise, false.

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 L0C0 notation

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

left SourcePosition
right SourcePosition

Returns

SourcePosition

operator >(SourcePosition, SourcePosition)

public static bool operator >(SourcePosition left, SourcePosition right)

Parameters

left SourcePosition
right SourcePosition

Returns

bool

operator >=(SourcePosition, SourcePosition)

public static bool operator >=(SourcePosition left, SourcePosition right)

Parameters

left SourcePosition
right SourcePosition

Returns

bool

operator <(SourcePosition, SourcePosition)

public static bool operator <(SourcePosition left, SourcePosition right)

Parameters

left SourcePosition
right SourcePosition

Returns

bool

operator <=(SourcePosition, SourcePosition)

public static bool operator <=(SourcePosition left, SourcePosition right)

Parameters

left SourcePosition
right SourcePosition

Returns

bool

operator -(SourcePosition, SourcePosition)

public static SourcePosition operator -(SourcePosition left, SourcePosition right)

Parameters

left SourcePosition
right SourcePosition

Returns

SourcePosition