jaredly / jaredly/reason-language-server
Formatting problem in VSCode
Nobody has claimed this yet.
- Dominant language
- OCaml
- Stars
- 649
- Forks
- 85
- PR merge metrics
- No merged PRs in 30d
Description
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](https://github.com/jaredly/reason-language-server/files/6338944/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.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the highlighting issue in VSCode with the provided CBST snippet, then inspect node_modules/.lsp/debug.log for related formatter or language-server details. The fix is complete when formatting the document no longer causes the _val1 and c1 tokens in the right-side branch to be highlighted incorrectly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ocaml, vscode
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100