TextDocument¶
Document model for reading and manipulating text documents.
Position¶
Position
dataclass
¶
Represents a line and character position in a document.
is_before
¶
Check if this position is before another position.
is_before_or_equal
¶
is_after
¶
is_after_or_equal
¶
is_equal
¶
compare_to
¶
Compare this position to another.
Returns:
Type | Description |
---|---|
int
|
Negative if this < other, 0 if equal, positive if this > other |
Source code in vscode_sockpuppet/document.py
translate
¶
Create a new position relative to this position.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
line_delta
|
int
|
Delta for line value (default 0) |
0
|
character_delta
|
int
|
Delta for character value (default 0) |
0
|
Returns:
Type | Description |
---|---|
Position
|
New Position object |
Source code in vscode_sockpuppet/document.py
with_line
¶
with_character
¶
Range¶
Range
dataclass
¶
Represents a range in a document with start and end positions.
contains
¶
Check if a position or range is contained in this range.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
position_or_range
|
Position | Range
|
Position or Range to check |
required |
Returns:
Type | Description |
---|---|
bool
|
True if contained within this range |
Source code in vscode_sockpuppet/document.py
is_equal
¶
intersection
¶
Compute the intersection of two ranges.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other
|
Range
|
Another range |
required |
Returns:
Type | Description |
---|---|
Optional[Range]
|
The intersection range, or None if no intersection |
Source code in vscode_sockpuppet/document.py
union
¶
Compute the union of two ranges.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other
|
Range
|
Another range |
required |
Returns:
Type | Description |
---|---|
Range
|
Range spanning both ranges |
Source code in vscode_sockpuppet/document.py
with_start
¶
TextLine¶
TextLine
¶
TextLine(line_number: int, text: str, is_empty_or_whitespace: bool, first_non_whitespace_char_index: int, range_obj: Range, range_including_line_break: Range)
Represents a line of text in a document.
Source code in vscode_sockpuppet/document.py
TextDocument¶
TextDocument
¶
Represents a text document in VS Code. Mirrors the VS Code TextDocument API.
Source code in vscode_sockpuppet/document.py
encoding
property
¶
The file encoding that will be used when the document is saved.
Common values include: 'utf8', 'utf8bom', 'utf16le', 'utf16be', 'windows1252', 'iso88591', etc.
save
¶
Save the document.
Returns:
Type | Description |
---|---|
bool
|
True if saved successfully |
Source code in vscode_sockpuppet/document.py
line_at
¶
Get a text line by line number or position.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
line_or_position
|
int | Position
|
Line number (0-based) or Position |
required |
Returns:
Type | Description |
---|---|
TextLine
|
TextLine object |
Source code in vscode_sockpuppet/document.py
offset_at
¶
Get the document offset for a position.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
position
|
Position
|
The position |
required |
Returns:
Type | Description |
---|---|
int
|
The character offset |
Source code in vscode_sockpuppet/document.py
position_at
¶
Get the position for a document offset.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
offset
|
int
|
The character offset |
required |
Returns:
Type | Description |
---|---|
Position
|
Position object |
Source code in vscode_sockpuppet/document.py
get_text
¶
Get text from the document.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
range
|
Optional[Range]
|
Optional range to get text from (entire document if None) |
None
|
Returns:
Type | Description |
---|---|
str
|
The text content |
Source code in vscode_sockpuppet/document.py
get_word_range_at_position
¶
Get the word range at a position.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
position
|
Position
|
The position |
required |
regex
|
Optional[str]
|
Optional regex pattern for word boundaries |
None
|
Returns:
Type | Description |
---|---|
Optional[Range]
|
Range of the word, or None if no word at position |
Source code in vscode_sockpuppet/document.py
validate_range
¶
Ensure a range is valid for this document.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
range
|
Range
|
The range to validate |
required |
Returns:
Type | Description |
---|---|
Range
|
Validated range |
Source code in vscode_sockpuppet/document.py
validate_position
¶
Ensure a position is valid for this document.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
position
|
Position
|
The position to validate |
required |
Returns:
Type | Description |
---|---|
Position
|
Validated position |