From 26b52dd10d23434677e49a898cb4fe8f4353d4af Mon Sep 17 00:00:00 2001 From: Jack Feser Date: Sun, 24 Sep 2023 17:23:08 -0400 Subject: [PATCH] Disable semantic highlighting unit () as enum member (#1185) * disable semantic highlighting unit () as enum member * add changes entry --- CHANGES.md | 1 + ocaml-lsp-server/src/semantic_highlighting.ml | 2 + .../test/e2e-new/semantic_hl_tests.ml | 68 ++++++++++--------- 3 files changed, 38 insertions(+), 33 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index d43d4c942..71aa5b7c9 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,6 +5,7 @@ - Fix missing super & subscripts in markdown documentation. (#1170) - Do not invoke dune at all if `--fallback-read-dot-merlin` flag is on. (#1173) - Fix semantic highlighting of infix operators that contain '.'. (#1186) +- Disable highlighting unit as an enum member to fix comment highlighting bug. (#1185) ## Features diff --git a/ocaml-lsp-server/src/semantic_highlighting.ml b/ocaml-lsp-server/src/semantic_highlighting.ml index 8cc0a623b..ba297670c 100644 --- a/ocaml-lsp-server/src/semantic_highlighting.ml +++ b/ocaml-lsp-server/src/semantic_highlighting.ml @@ -552,6 +552,7 @@ end = struct Pexp_tuple(...))] *) Option.iter vo ~f:(fun v -> self.expr self v) | Lident "[]" -> () (* TDOO: is this correct? *) + | Lident "()" -> () | _ -> lident c (Token_type.of_builtin EnumMember) (); Option.iter vo ~f:(fun v -> self.expr self v)); @@ -688,6 +689,7 @@ end = struct (match c.txt with | Lident "::" -> process_args () | Lident "[]" -> () + | Lident "()" -> () | _ -> lident c (Token_type.of_builtin EnumMember) (); process_args ()); diff --git a/ocaml-lsp-server/test/e2e-new/semantic_hl_tests.ml b/ocaml-lsp-server/test/e2e-new/semantic_hl_tests.ml index 86b7d7007..4e19840b8 100644 --- a/ocaml-lsp-server/test/e2e-new/semantic_hl_tests.ml +++ b/ocaml-lsp-server/test/e2e-new/semantic_hl_tests.ml @@ -177,38 +177,38 @@ let%expect_test "tokens for ocaml_lsp_server.ml" = | Foo of string | Bar of [ `Int of int | `String of string ] - let u = () + let u = () - let f () = 0 + let f () = 0 end - module type Bar = sig - type t = - { foo : Moo.t - ; bar : int + module type Bar = sig + type t = + { foo : Moo.t + ; bar : int } end - type t = Moo.koo = - | Foo of string - | Bar of [ `BarInt of int | `BarString of string ] + type t = Moo.koo = + | Foo of string + | Bar of [ `BarInt of int | `BarString of string ] - let f (foo : t) = - match foo with - | Moo.Foo s -> s ^ string_of_int 0 - | Moo.Bar (`BarInt i) -> string_of_int i - | Moo.Bar (`BarString s) -> s + let f (foo : t) = + match foo with + | Moo.Foo s -> s ^ string_of_int 0 + | Moo.Bar (`BarInt i) -> string_of_int i + | Moo.Bar (`BarString s) -> s - module Foo (Arg : Bar) = struct - module Inner_foo = struct - type t = string + module Foo (Arg : Bar) = struct + module Inner_foo = struct + type t = string end end - module Foo_inst = Foo (struct - type t = - { foo : Moo.t - ; bar : int + module Foo_inst = Foo (struct + type t = + { foo : Moo.t + ; bar : int } end) |}] @@ -365,24 +365,12 @@ let%expect_test "tokens for ocaml_lsp_server.ml" = "type": "variable", "modifiers": [] }, - { - "start_pos": { "character": 10, "line": 18 }, - "length": 2, - "type": "enumMember", - "modifiers": [] - }, { "start_pos": { "character": 6, "line": 20 }, "length": 1, "type": "function", "modifiers": [ "definition" ] }, - { - "start_pos": { "character": 8, "line": 20 }, - "length": 2, - "type": "enumMember", - "modifiers": [] - }, { "start_pos": { "character": 13, "line": 20 }, "length": 1, @@ -746,3 +734,17 @@ let z = 0 >>= 1 let x = 1.0 *. 2.0 let y = 1 * 2 let z = 0 >>= 1 |}] + +let%expect_test "comment in unit" = + test_semantic_tokens_full + @@ String.trim + {| +let y = (* comment *) 0 +let x = ((* comment *)) +let ((*comment*)) = () + |}; + [%expect + {| + let y = (* comment *) 0 + let x = ((* comment *)) + let ((*comment*)) = () |}]