<commit_before>open Std

module Cmi = struct
  type error =
    | Not_an_interface of string
    | Wrong_version_interface of string * string
    | Corrupted_interface of string

  exception Error of error

  let to_version_opt = function
    | "Caml1999I017" -> Some "4.02"
    | "Caml1999I020" -> Some "4.03"
    | "Caml1999I021" -> Some "4.04 or 4.05"
    | "Caml1999I022" -> Some "4.06"
    | "Caml1999I023" -> Some "4.07.0"
    | "Caml1999I024" -> Some "4.07.1"
    | "Caml1999I025" -> Some "4.08"
    | "Caml1999I026" -> Some "4.09"
    | "Caml1999I027" -> Some "4.10"
    | "Caml1999I028" -> Some "4.11"
    | "Caml1999I029" -> Some "4.12"
    | "Caml1999I030" -> Some "4.13"
    | "Caml1999I031" -> Some "4.14"
    | _ -> None

  open Format

  let report_error ppf = function
    | Not_an_interface filename ->
        fprintf ppf "%a@ is not a compiled interface"
          Location.print_filename filename
    | Wrong_version_interface (filename, compiler_magic) ->
      begin match to_version_opt compiler_magic with
      | None ->
        fprintf ppf
          "%a@ seems to be compiled with a version of OCaml that is not@.\
           supported by Merlin."
          Location.print_filename filename
      | Some version ->
        fprintf ppf
          "%a@ seems to be compiled with OCaml %s.@.\
           But this instance of Merlin handles OCaml %s."
          Location.print_filename filename version
          (Option.get @@ to_version_opt Config.cmi_magic_number)
      end
    | Corrupted_interface filename ->
        fprintf ppf "Corrupted compiled interface@ %a"
          Location.print_filename filename

  let () =
    Location.register_error_of_exn
      (function
        | Error err -> Some (Location.error_of_printer_file report_error err)
        | _ -> None
      )
end<commit_msg>adapt Magic_numbers.Cmi.report_error to OCaml LSP<commit_after>open Std

module Cmi = struct
  type error =
    | Not_an_interface of string
    | Wrong_version_interface of string * string
    | Corrupted_interface of string

  exception Error of error

  let to_version_opt = function
    | "Caml1999I017" -> Some "4.02"
    | "Caml1999I020" -> Some "4.03"
    | "Caml1999I021" -> Some "4.04 or 4.05"
    | "Caml1999I022" -> Some "4.06"
    | "Caml1999I023" -> Some "4.07.0"
    | "Caml1999I024" -> Some "4.07.1"
    | "Caml1999I025" -> Some "4.08"
    | "Caml1999I026" -> Some "4.09"
    | "Caml1999I027" -> Some "4.10"
    | "Caml1999I028" -> Some "4.11"
    | "Caml1999I029" -> Some "4.12"
    | "Caml1999I030" -> Some "4.13"
    | "Caml1999I031" -> Some "4.14"
    | _ -> None

  open Format

  let report_error ppf = function
    | Not_an_interface filename ->
        fprintf ppf "%a@ is not a compiled interface"
          Location.print_filename filename
    | Wrong_version_interface (filename, compiler_magic) ->
      begin match to_version_opt compiler_magic with
      | None ->
        fprintf ppf
          "Compiler version mismatch: this project seems to be compiled with a version of \
          OCaml compiler that is not supported by the running OCaml LSP. OCaml language \
          support will not work properly until this problem is fixed. \n\
          Hint: It seems the project is built with a newer OCaml compiler version \
          that the running OCaml LSP version doesn't know about. Make sure your \
          editor runs OCaml LSP that supports this version of compiler. \n\
          This diagnostic is based on the compiled interface file: %a"
          Location.print_filename filename
      | Some version ->
        fprintf ppf
          "Compiler version mismatch: this project seems to be compiled with OCaml compiler \
          version %s, but the running OCaml LSP supports OCaml version %s. OCaml language support \
          will not work properly until this problem is fixed. \n\
          Hint: Make sure your editor runs OCaml LSP that supports this version of compiler. \n\
          This diagnostic is based on the compiled interface file: %a"
          version (Option.get @@ to_version_opt Config.cmi_magic_number)
          Location.print_filename filename
      end
    | Corrupted_interface filename ->
        fprintf ppf "Corrupted compiled interface@ %a"
          Location.print_filename filename

  let () =
    Location.register_error_of_exn
      (function
        | Error err -> Some (Location.error_of_printer_file report_error err)
        | _ -> None
      )
end
{'fraction_non_alphanumeric': 0.09031678274545046, 'fraction_numerical': 0.06066052572455628, 'mean_word_length': 2.4010695187165774, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4718967', 'n_tokens_mistral': 1555, 'n_tokens_neox': 1380, 'n_words': 437}