flycheck / flycheck-ocaml

OCaml support for Flycheck using Merlin
GNU General Public License v3.0
22 stars 6 forks source link

Highlight the exact region reported by merlin #12

Closed Wilfred closed 2 years ago

Wilfred commented 6 years ago

Given the source code:

let f x: string = x + 1

Flycheck highlights the current symbol, starting at the column position reported by merlin:

screen shot 2018-11-23 at 16 30 59

Region highlighting is controlled by flycheck-highlighting-mode. The default is symbols, but sexps has the same result in this example.

M-x merlin-toggle-view-errors highlights the exact expression instead. This is really helpful when dealing with errors in large functions.

screen shot 2018-11-23 at 16 21 29

Is it possible to get this precise region highlighting with flycheck-ocaml?

Wilfred commented 6 years ago

FWIW, you can see the end position in the Merlin protocol:

$ cat ~/scratch/type_error.ml 
let f x: string = x + 1

$ cat ~/scratch/type_error.ml | ~/.opam/4.05.0/bin/ocamlmerlin single errors | jq .
{
  "class": "return",
  "value": [
    {
      "start": {
        "line": 1,
        "col": 18
      },
      "end": {
        "line": 1,
        "col": 23
      },
      "type": "typer",
      "sub": [],
      "valid": true,
      "message": "This expression has type int but an expression was expected of type\n         string"
    }
  ],
  "notifications": [],
  "timing": {
    "total": 1.9509999999999987,
    "query": 0.13099999999999845,
    "reader": 0.2289999999999992,
    "ppx": 0.06199999999999939,
    "typer": 1.5250000000000021,
    "error": 0.0039999999999995595
  }
}
fmdkdd commented 5 years ago

I believe flycheck/flycheck#1400 would fix this.