Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Formatting problem in VSCode #475

Open
spike7638 opened this issue Apr 19, 2021 · 0 comments
Open

Formatting problem in VSCode #475

spike7638 opened this issue Apr 19, 2021 · 0 comments

Comments

@spike7638
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant