Skip to content

Formatting problem in VSCode #475

@spike7638

Description

@spike7638

Please include steps needed to reproduce the bug, along any relevant sections of the log file, located at node_modules/.lsp/debug.log

The following code (written by a student solving an exam problem) shows up with peculiar formatting at line 14:

type cbst = Leaf | Node((value, count), cbst, cbst);

let rec largestCount: cbst => int =
inTree =>
switch (inTree) {
| Leaf => failwith("largestCount does not take empty CBST")
| Node((_val1, c1), Leaf, Leaf) => c1
| Node((_val1, c1), leftSide, Leaf) =>
if (c1 >= largestCount(leftSide)) {
c1;
} else {
largestCount(leftSide);
}
| Node((_val1, c1), Leaf, rightSide) => // PECULIAR FORMATTING
if (c1 >= largestCount(rightSide)) {
c1;
} else {
largestCount(rightSide);
}
| Node((_val1, c1), leftSide, rightSide) =>
if (c1 >= largestCount(leftSide) && c1 >= largestCount(rightSide)) {
c1;
} else if (largestCount(leftSide) >= c1
&& largestCount(leftSide) >= largestCount(rightSide)) {
largestCount(leftSide);
} else {
largestCount(rightSide);
}
};

The word "_val1" at lines 7 and 8 is highlighted in green, with the following c1 in each case highlighted in red. But at line 15, only the "1" in "_val1" is highlighted green, and the c1 is just in black like most other text in the program.
If we place lines 9-13 in a block, though, like this

type cbst = Leaf | Node((value, count), cbst, cbst);

let rec largestCount: cbst => int =
inTree =>
switch (inTree) {
| Leaf => failwith("largestCount does not take empty CBST")
| Node((_val1, c1), Leaf, Leaf) => c1
| Node((_val1, c1), leftSide, Leaf) =>
{ //ADDED
if (c1 >= largestCount(leftSide)) {
c1;
} else {
largestCount(leftSide);
}
} //ADDED
| Node((_val1, c1), Leaf, rightSide) =>
if (c1 >= largestCount(rightSide)) {
c1;
} else {
largestCount(rightSide);
}
| Node((_val1, c1), leftSide, rightSide) =>
if (c1 >= largestCount(leftSide) && c1 >= largestCount(rightSide)) {
c1;
} else if (largestCount(leftSide) >= c1
&& largestCount(leftSide) >= largestCount(rightSide)) {
largestCount(leftSide);
} else {
debug.log

    largestCount(rightSide);
  }
};

then the highlighting looks right again. On the other hand, reformatting the document (select-all, right-click, Format Document) leads to those new braces getting removed, and the coloring problem renews itself.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions