Table of Contents

Struct SourcePosition

Namespace
RDCore.SDK.Model.Source
Assembly
RDCore.SDK.Protocol.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

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 two positions in document order: by line, then by character within the line.

public int CompareTo(SourcePosition other)

Parameters

other SourcePosition

The position to compare with.

Returns

int

Less than zero when this position comes before other, zero when they are the same, greater than zero when it comes after.

Equals(SourcePosition)

Whether two positions are the same line and the same character.

public bool Equals(SourcePosition other)

Parameters

other SourcePosition

The position to compare with.

Returns

bool

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)

The component-wise sum of two positions: lines added to lines, characters to characters.

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

Parameters

left SourcePosition
right SourcePosition

Returns

SourcePosition

Remarks

👉 Not a translation into a document's coordinates: AnchoredAt(SourcePosition) is.

operator >(SourcePosition, SourcePosition)

Whether left comes after right in the document.

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

Parameters

left SourcePosition
right SourcePosition

Returns

bool

operator >=(SourcePosition, SourcePosition)

Whether left comes after right in the document, or is the same position.

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

Parameters

left SourcePosition
right SourcePosition

Returns

bool

operator <(SourcePosition, SourcePosition)

Whether left comes before right in the document.

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

Parameters

left SourcePosition
right SourcePosition

Returns

bool

operator <=(SourcePosition, SourcePosition)

Whether left comes before right in the document, or is the same position.

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

Parameters

left SourcePosition
right SourcePosition

Returns

bool

operator -(SourcePosition, SourcePosition)

The component-wise difference of two positions: lines from lines, characters from characters.

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

Parameters

left SourcePosition
right SourcePosition

Returns

SourcePosition