Skip to content

raesl.types

Some general types, inspired by the Language Server Protocol.

Reference

Diagnostic

Diagnostic(
    message: str,
    range: Range,
    severity: DiagnosticSeverity = Error,
    code: str = None,
    source: str = None,
    related_information: List[
        DiagnosticRelatedInformation
    ] = None,
)

Represents a diagnostic, such as a compiler error or warning.

Diagnostic objects are only valid in the scope of a resource.

Parameters:

Name Type Description Default
message str

The diagnostic's message.

required
range Range

The range at which the message applies.

required
severity DiagnosticSeverity

The diagnostic's severity. Can be omitted. If omitted it is up to the client to interpret diagnostics as error, warning, info or hint.

Error
code str

The diagnostic's code, which might appear in the user interface.

None
source str

A human-readable string describing the source of this diagnostic, e.g. 'esl', or 'esl compiler'.

None
related_information List[DiagnosticRelatedInformation]

A list of related diagnostic information, e.g. when symbol-names within a scope collide you can mark all definitions via this property.

None
Source code in src/raesl/types.py
def __init__(
    self,
    message: str,
    range: Range,
    severity: DiagnosticSeverity = DiagnosticSeverity.Error,
    code: str = None,
    source: str = None,
    related_information: List[DiagnosticRelatedInformation] = None,
):
    self.message = message
    self.range = range
    self.severity = severity
    self.code = code
    self.source = source
    self.related_information = related_information

DiagnosticRelatedInformation

DiagnosticRelatedInformation(
    location: Location, message: str
)

Represents a related message and source code location for a diagnostic.

This should be used to point to code locations that cause or are related to a diagnostic, e.g when duplicating a symbol in a scope.

Parameters:

Name Type Description Default
location Location

The location of this related diagnostic information.

required
message str

The message of this related diagnostic information.

required
Source code in src/raesl/types.py
def __init__(self, location: Location, message: str):
    self.location = location
    self.message = message

Location

Location(uri: str, range: Range)

Represents a location inside a resource. Such as a line inside a text file.

Parameters:

Name Type Description Default
uri str

URI of this location.

required
range Range

Range of this location.

required
Source code in src/raesl/types.py
def __init__(self, uri: str, range: Range):
    self.uri = uri
    self.range = range

get_key

get_key() -> Tuple[str, int, int]

Get a tuple with identification for this position.

Source code in src/raesl/types.py
def get_key(self) -> Tuple[str, int, int]:
    """Get a tuple with identification for this position."""
    return self.uri, self.range.start.line, self.range.start.character

Position

Position(line: int = 0, character: int = 0)

Position in a text document expressed as zero-based line and character offset.

A position is between two characters like an 'insert' cursor in an editor. Special values like for example -1 to denote the end of a line are not supported.

Parameters:

Name Type Description Default
line int

Line position in a document (zero-based).

0
character int

Character offset on a line in a document (zero-based). Assuming that the line is represented as a string, the 'character' value represents the gap between 'character' and 'character + 1'.

0
Source code in src/raesl/types.py
def __init__(self, line: int = 0, character: int = 0):
    self.line = line
    self.character = character

Range

Range(start: Position, end: Position)

A range in a text document expressed as (zero-based) start and end positions.

A range is comparable to a selection in an editor. Therefore the end position is exclusive. If you want to specify a range that contains a line including the ending character(s) then use an end position denoting the start of the next line.

Parameters:

Name Type Description Default
start Position

The range's start position.

required
end Position

The range's end position.

required
Source code in src/raesl/types.py
def __init__(self, start: Position, end: Position):
    self.start = start
    self.end = end