Table of Contents

Class ModuleBlocks

Namespace
RDCore.SDK.Formatting
Assembly
RDCore.SDK.dll

The blocks of a module that a line is in and that the module does not close, and what an editor does with them when a line break is typed: it indents the new line, and closes the block the line before it opens.

public static class ModuleBlocks
Inheritance
ModuleBlocks
Inherited Members

Remarks

What is a block, and which closer ends it, is what the module's syntax tree says, as ModuleIndenter has it: a Sub, a Function or a Property (MS-VBAL §5.3.1), an Enum (§5.2.3.4), a Type (§5.2.3.3), an If block (§5.4.2.8), a Select Case (§5.4.2.10), a For or For Each loop (§5.4.2.3, §5.4.2.4), a Do loop (§5.4.2.6), a While loop (§5.4.2.2) and a With block (§5.4.2.21). A single-line If (§5.4.2.9) is not a block.

A block is closed by a statement that starts with its closer on the line it ends on, the last statement of its lines or one after a colon (x = 1: End If); a closer that ends a block within it does not close it as well. A Next that lists names closes one loop for each name.

Methods

OnLineBreakAsync(ModuleParseResult, string, int, CodeFormattingOptions, Func<string, CancellationToken, Task<ModuleParseResult>>, CancellationToken)

The edits a line break typed into a module brings, as an editor makes them once it has the new line: the line the break ends and the new line are indented as ModuleIndenter has them, the new line even when it is empty; and when the line before the new one opens a block that the module has no closer for, and the new line is empty, the block's closer is written on a line of its own after it, at the level of the opener.

public static Task<IReadOnlyList<TextEdit>> OnLineBreakAsync(ModuleParseResult parse, string text, int line, CodeFormattingOptions options, Func<string, CancellationToken, Task<ModuleParseResult>> reparse, CancellationToken token = default)

Parameters

parse ModuleParseResult

The module, as it was parsed from text, the line break in it.

text string

The text of the module, the line break in it. A line ends with a carriage return, a line feed, or both, as the Language Server Protocol counts them.

line int

The line the break starts, from 0.

options CodeFormattingOptions

How code is indented.

reparse Func<string, CancellationToken, Task<ModuleParseResult>>

Parses the text of the module with the closer in it.

token CancellationToken

A token that cancels the parse.

Returns

Task<IReadOnlyList<TextEdit>>

The edits, in the order they are to be made: by line, then by character, and the closer's insertion after the edits of the new line.

Remarks

The edits leave the new line where it is, and what is written on it: the closer goes on the line after it, so that what the user types next is the block's body. A block that has its closer further down, as one does when its opener is typed again, is not closed a second time.

The lines are indented as the module is once the closer is in it, which is parsed again for that: the new line is then in the block's body, as a procedure's is although the module has nothing after its header yet.

Exceptions

ArgumentNullException

parse, text, options or reparse is null.

OpenAt(ModuleParseResult, string, int)

The blocks a line of a module is in that the module has no closer for: the line's own block when it opens one, and each block it is in.

public static IReadOnlyList<ModuleBlock> OpenAt(ModuleParseResult parse, string text, int line)

Parameters

parse ModuleParseResult

The module, as it was parsed from text.

text string

The text of the module. A line ends with a carriage return, a line feed, or both, as the Language Server Protocol counts them.

line int

The line, from 0.

Returns

IReadOnlyList<ModuleBlock>

The open blocks, the innermost first; none when the line is in no open block, or is not a line of the text.

Exceptions

ArgumentNullException

parse or text is null.