From 81edefe0f9f0b5c6d1871ec0f2ca2c8109aa37c4 Mon Sep 17 00:00:00 2001 From: Michael Bottini Date: Fri, 22 Dec 2023 11:06:18 -0800 Subject: [PATCH] Fix #209: Remove (* *) from brackets config language-configuration.json lets you define various pairs of brackets and braces for autoclosing, surrounding selected text with characters, and, as it turns out, dictating which brackets get colorized by the native bracket colorizer. Currently, having `(* *)` inside the `brackets` field is causing the infix multiplication operator to be treated by the bracket colorizer as two brackets: an opening `(*` and a closing `)`. Two things happen here: * The `(*` does not correspond to a corresponding `*)` bracket, so it is treated as unbalanced (hence why that part of the operator is colored red). * Absent any preceding parens in the expression, the `)` is also treated as an unbalanced paren and is colored red. This is the best case, which colors the entire operator a uniform red. Strange, but normal-looking enough that it actually looked intentional to me when I first started getting into F#. The multiplication operator is weird due to how similar it is to block comments - maybe it's supposed to be that way! * But the bug really gets exposed when there is a preceding paren in the expression such as in the expression `(Seq.fold (*) 1 [1;2;3])`. In this case, there *is* a balancing paren - the paren that precedes `Seq.fold`. Now the multiplication operator is half red (the block comment bracket never gets balanced) and half whatever the colorizer picks for the two parens. And now the closing paren after `[1;2;3]` is unbalanced and made red! As far as I can tell, putting the block comment brackets inside the `brackets` field is pointless. We color our comments green anyway, so the colors don't show anyway. It is true that F# provides support for nested comment blocks, but we aren't taking advantage of the color feature anyway (and I'm unsure if it's even possible to do so). The block comments should, however, remain in the other fields that control autocomplete and surrounding selected text. --- fsharp.syntaxtest/language-configuration.json | 1 - sample-code/SimpleTypes.fs | 10 ++++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/fsharp.syntaxtest/language-configuration.json b/fsharp.syntaxtest/language-configuration.json index 52734c5..4edfa68 100644 --- a/fsharp.syntaxtest/language-configuration.json +++ b/fsharp.syntaxtest/language-configuration.json @@ -36,7 +36,6 @@ "brackets": [ ["(", ")"], - ["(*", "*)"], ["{", "}"], ["[", "]"], ["[|", "|]"], diff --git a/sample-code/SimpleTypes.fs b/sample-code/SimpleTypes.fs index 5a5dc38..26d98e6 100644 --- a/sample-code/SimpleTypes.fs +++ b/sample-code/SimpleTypes.fs @@ -44,6 +44,16 @@ module Test = let b = "" let double = (*) 2 // *) was being captured as a comment + + // Both of these operators should have the same syntax highlighting, + // specifically the infix multiplication operator. + let foldSum xs = Seq.fold (+) 0 xs + let foldProduct xs = Seq.fold (*) 1 xs + + // Parenthesizing the above expression should not associate the `)` + // part of the multiplication operator with the opening paren before + // the expression. + let foldProduct2 xs = (Seq.fold (*) 1 xs) (** This block is colorized because markdown can set up his context.