Table of Contents

Class LineEdits

Namespace
RDCore.SDK.Extensibility.Diagnostics
Assembly
RDCore.SDK.dll

The edits of a fix (EditFix) that remove or write whole lines, placed by the parse of the module an analyzer is given (ParseResult): which lines a node is alone on, and lines of their own written before or after one.

public static class LineEdits
Inheritance
LineEdits
Inherited Members

Remarks

The parse accounts for everything written in the module: the syntax tree, its Trivia (comments, line continuations) and its PrecompilerTrivia (the #If directives). What none of them has a range for is blanks. So whether anything else is written on the lines of a node is a question the parse answers, without the text.

A line this writes ends with the module's own line ending (LineEnding) and is written without indentation: the language server indents the lines a fix writes, the way the user indents the code, before it offers the fix.

Methods

EndOfDeclarations(ModuleParseResult)

Where declarations are added to the declaration section of a module (MS-VBAL §5.2): the start of the line after the last line written before the first procedure and the comments directly above it, which stay the procedure's. In a module with no procedure, it is the end of the text.

public static SourcePosition? EndOfDeclarations(ModuleParseResult parse)

Parameters

parse ModuleParseResult

The parse of the module.

Returns

SourcePosition?

The position, or null when it is in a branch of an #If block (MS-VBAL §3.4), where a declaration would be compiled only when that branch is live, or when the parse has no syntax tree.

Remarks

A line is blank when nothing the parse has a range for is written on it, and a comment is directly above a procedure when the lines between them hold comments and nothing else.

InsertLinesAfter(ModuleParseResult, SyntaxNode, params string[])

Lines of their own, written after the line a node ends on.

public static TextEdit InsertLinesAfter(ModuleParseResult parse, SyntaxNode node, params string[] lines)

Parameters

parse ModuleParseResult

The parse of the module the node is in.

node SyntaxNode

The node.

lines string[]

The lines, without their line ends or indentation; an empty one is a blank line.

Returns

TextEdit

InsertLinesAfter(ModuleParseResult, SourceRange, params string[])

Lines of their own, written after the line a range ends on.

public static TextEdit InsertLinesAfter(ModuleParseResult parse, SourceRange range, params string[] lines)

Parameters

parse ModuleParseResult

The parse of the module the range is in.

range SourceRange

The range.

lines string[]

The lines, without their line ends or indentation; an empty one is a blank line.

Returns

TextEdit

Remarks

After the last line of a text that does not end with a line end, the lines are written at the end of the text, each after a line end.

InsertLinesAfterDeclarations(ModuleParseResult, params string[])

Lines of their own, written at the end of the declaration section of a module (EndOfDeclarations(ModuleParseResult)): a field, or a declaration a fix moves to module level. A procedure written directly after them gets a blank line before it.

public static TextEdit? InsertLinesAfterDeclarations(ModuleParseResult parse, params string[] lines)

Parameters

parse ModuleParseResult

The parse of the module.

lines string[]

The lines, without their line ends or indentation; an empty one is a blank line.

Returns

TextEdit

The edit, or null when there is no end of the declaration section to write at (EndOfDeclarations(ModuleParseResult)).

InsertLinesBefore(ModuleParseResult, SyntaxNode, params string[])

Lines of their own, written before the line a node starts on.

public static TextEdit InsertLinesBefore(ModuleParseResult parse, SyntaxNode node, params string[] lines)

Parameters

parse ModuleParseResult

The parse of the module the node is in.

node SyntaxNode

The node.

lines string[]

The lines, without their line ends or indentation; an empty one is a blank line.

Returns

TextEdit

InsertLinesBefore(ModuleParseResult, SourceRange, params string[])

Lines of their own, written before the line a range starts on: before the End Sub of a procedure (EndRange).

public static TextEdit InsertLinesBefore(ModuleParseResult parse, SourceRange range, params string[] lines)

Parameters

parse ModuleParseResult

The parse of the module the range is in.

range SourceRange

The range.

lines string[]

The lines, without their line ends or indentation; an empty one is a blank line.

Returns

TextEdit

WholeLinesOf(ModuleParseResult, SyntaxNode)

The lines a node is written on, from the start of its first line to the start of the line after its last, when nothing else is written on them: removed, they leave no blank line behind.

public static SourceRange? WholeLinesOf(ModuleParseResult parse, SyntaxNode node)

Parameters

parse ModuleParseResult

The parse of the module the node is in.

node SyntaxNode

The node.

Returns

SourceRange?

The range of the lines, or null when anything else is written on them (see WholeLinesOf(ModuleParseResult, SourceRange)).

WholeLinesOf(ModuleParseResult, SourceRange)

The lines a span of the module is written on, from the start of its first line to the start of the line after its last, when nothing else is written on them: an empty Else through the line before its End If, or the statements of a body.

public static SourceRange? WholeLinesOf(ModuleParseResult parse, SourceRange span)

Parameters

parse ModuleParseResult

The parse of the module the span is in.

span SourceRange

The span.

Returns

SourceRange?

The range of the lines, or null when anything else is written on them, or when the parse has no syntax tree.

Remarks

Something else is written on the lines when a node of the tree, a trivia or a directive has characters on them and is neither inside the span nor around it: a statement after a :, a comment after the code, a line continuation that carries a statement onto the first line or off the last. A node around the span, such as the block or the procedure it is in, is something else when it has characters on those lines besides the span's: the If ... Then of a single-line If, or an End If after a :.

The last line of a text that does not end with a line end has none to remove: the range then ends at the end of the text, and the line end before the span stays, as a blank last line.