Document

in-memory representation of a file at any given URI. Not thread-safe.

Constructors

this
this(DocumentUri uri)

Creates a new document at the given document URI, with version 0 and no text and guessed language ID. See getLanguageId

this
this(TextDocumentItem doc)

Creates a new document at the given document URI, with the given version and language and creates a copy of the text to use.

Members

Functions

applyChange
void applyChange(TextRange range, const(char)[] newContent)
bytesToOffset
size_t bytesToOffset(size_t bytes)

Converts a byte offset to an LSP offset.

bytesToPosition
Position bytesToPosition(size_t bytes)

Converts a byte offset to a line/column position.

clone
Document clone()

Returns a copy of this document with the text memory duplicated. May safely be cast to immutable.

eolAt
EolType eolAt(int line)

Returns how a line is terminated at the given 0-based line number. Defaults to LF for the last line / no line terminator.

getLanguageId
string getLanguageId()

Returns the language ID or guesses it given the filename's extension. Returns null if none is set and can't be guessed.

length
size_t length()

Returns the text length.

lineAt
string lineAt(Position position)

Returns the text of a line at the given position.

lineAt
string lineAt(uint line)

Returns the text of a line starting at line 0.

lineAtScope
auto lineAtScope(Position position)
auto lineAtScope(uint line)

Returns the line text at the given position. The memory content may be modified by the setContent method by other code in the same context or in a different context.

lineByteRangeAt
size_t[2] lineByteRangeAt(uint line)

Returns a byte offset range as [start, end] of the given 0-based line number. Contains the line terminator, if it exists.

lineColumnBytesToPosition
Position lineColumnBytesToPosition(uint line, uint column)

Converts a line/column byte offset to a line/column position.

movePositionBytes
Position movePositionBytes(Position src, size_t start, size_t end)

Returns the position at "end" starting from the given "src" position which is assumed to be at byte "start" Faster to quickly calculate nearby positions of known byte positions. Falls back to bytesToPosition if end is before start.

nextPositionBytes
Position nextPositionBytes(Position src, size_t start, size_t end)

Calls movePositionBytes, updates src to be the return value and updates start to become end. This reduces boilerplate in common calling scenarios.

offsetToBytes
size_t offsetToBytes(size_t offset)

Converts an LSP offset to a byte offset for using for example in array slicing.

offsetToPosition
Position offsetToPosition(size_t offset)

Converts an LSP offset to a line/column position.

positionToBytes
size_t positionToBytes(Position position)

Converts a line/column position to a byte offset.

positionToOffset
size_t positionToOffset(Position position)

Converts a line/column position to an LSP offset.

rawText
const(char)[] rawText()
string rawText()

Returns a read-only view of the text. The text may however be changed by other operations, so this slice should be used directly and not after any context yield or API call potentially modifying the data.

setContent
typeof(this) setContent(const(char)[] newContent)

Sets the content of this document to the given content. Copies the data from newContent into this text buffer.

wordRangeAt
TextRange wordRangeAt(Position position)

Returns the word range at a given line/column position.

wordRangeAt
size_t[2] wordRangeAt(size_t bytes)

Returns the word range at a given byte position.

Static functions

nullDocument
Document nullDocument(const(char)[] content)

Creates a document with no URI and no language ID and copies the content into the text buffer using setContent.

Variables

languageId
string languageId;

The language ID as reported by the client. Should not be changed.

uri
DocumentUri uri;

The URI of this document. Should not be changed.

version_
long version_;

The document version as reported by the client. Should not be changed.

Meta