ocaml
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Reporter: remove annoying duplication of large datatypes

+263 -318
+1 -255
lib/core/Reporter.ml
··· 10 10 module R = Resolver 11 11 module Sc = R.Scope 12 12 13 - module Message = struct 14 - type expected_value = 15 - | Content 16 - | Text 17 - | Obj 18 - | Bool 19 - | Sym 20 - | Dx_query 21 - | Dx_sequent 22 - | Dx_prop 23 - | Datalog_term 24 - | Node 25 - | URI 26 - | Argument 27 - [@@deriving show] 28 - 29 - type t = 30 - | Import_not_found of URI.t 31 - | Invalid_URI 32 - | Asset_has_no_content_address of string 33 - | Asset_not_found of string 34 - | Current_tree_has_no_uri 35 - | Duplicate_tree of origin * origin 36 - | Parse_error 37 - | Unbound_method of (string * Value.obj) 38 - | Type_warning 39 - | Type_error of 40 - { 41 - got: Value.t option; 42 - expected: expected_value list 43 - } 44 - | Unbound_fluid_symbol of Symbol.t 45 - | Unbound_variable of string 46 - | Unresolved_identifier of ((Sc.data, R.P.tag) Trie.t [@opaque]) * Trie.path 47 - | Unresolved_xmlns of string 48 - | Reference_error of URI.t 49 - | Unhandled_case 50 - | Transclusion_loop 51 - | Internal_error 52 - | Configuration_error 53 - | Initialization_warning 54 - | Routing_error 55 - | Profiling of float * float 56 - | External_error 57 - | Resource_not_found of URI.t 58 - | Broken_link of {uri: URI.t; suggestion: URI.t option} 59 - | IO_error 60 - | Log 61 - | Missing_argument 62 - | Uninterpreted_config_options of string list list 63 - | Using_default_option of string list 64 - | Required_config_option of string 65 - [@@deriving show] 66 - 67 - let default_severity : t -> Asai.Diagnostic.severity = function 68 - | Import_not_found _ -> Error 69 - | Unresolved_identifier _ -> Warning 70 - | Unresolved_xmlns _ -> Error 71 - | Invalid_URI -> Error 72 - | Unbound_method _ -> Error 73 - | Asset_has_no_content_address _ -> Error 74 - | Asset_not_found _ -> Error 75 - | Current_tree_has_no_uri -> Error 76 - | Reference_error _ -> Error 77 - | Duplicate_tree _ -> Error 78 - | Parse_error -> Error 79 - | Type_error _ -> Error 80 - | Type_warning -> Warning 81 - | Unbound_fluid_symbol _ -> Error 82 - | Unbound_variable _ -> Error 83 - | Unhandled_case -> Bug 84 - | Transclusion_loop -> Error 85 - | Internal_error -> Bug 86 - | Configuration_error -> Error 87 - | Initialization_warning -> Warning 88 - | Routing_error -> Error 89 - | Profiling _ -> Info 90 - | External_error -> Error 91 - | Log -> Info 92 - | Resource_not_found _ -> Error 93 - | Broken_link _ -> Warning 94 - | IO_error -> Error 95 - | Missing_argument -> Error 96 - | Uninterpreted_config_options _ -> Warning 97 - | Using_default_option _ -> Info 98 - | Required_config_option string -> Error 99 - 100 - let short_code : t -> string = function 101 - | Import_not_found _ -> "import_not_found" 102 - | Invalid_URI -> "invalid_uri" 103 - | Asset_has_no_content_address _ -> "asset_not_found" (* This is taken from the original wording of the message, but I think this is very confusing.*) 104 - | Asset_not_found _ -> "asset_not_found" 105 - | Current_tree_has_no_uri -> "current_tree_has_no_uri" 106 - | Duplicate_tree _ -> "duplicate_tree" 107 - | Parse_error -> "parse_error" 108 - | Unbound_method _ -> "unbound_method" 109 - | Type_warning -> "type_warning" 110 - | Type_error _ -> "type_error" 111 - | Unbound_fluid_symbol _ -> "unbound_fluid_symbol" 112 - | Unbound_variable _ -> "Unbound_variable" 113 - | Unresolved_xmlns _ -> "unresolved_xmlns" 114 - | Unresolved_identifier _ -> "unresolved_identifier" 115 - | Reference_error _ -> "reference_error" 116 - | Unhandled_case -> "unhandled_case" 117 - | Transclusion_loop -> "transclusion_loop" 118 - | Internal_error -> "internal_error" 119 - | Configuration_error -> "configuration_error" 120 - | Initialization_warning -> "initialization_warning" 121 - | Routing_error -> "routing_error" 122 - | Profiling (_, _) -> "profiling" 123 - | External_error -> "external_error" 124 - | Resource_not_found _ -> "resource_not_found" 125 - | Broken_link _ -> "broken_link" 126 - | IO_error -> "io_error" 127 - | Log -> "log" 128 - | Missing_argument -> "missing_argument" 129 - | Uninterpreted_config_options _ -> "unknown_config_option" 130 - | Using_default_option _ -> "using_default_option" 131 - | Required_config_option _ -> "required_config_option" 132 - 133 - let this_is : Value.t -> string = function 134 - | Value.Content _ -> "content" 135 - | Value.Clo (_, _, _) -> "a closure" 136 - | Value.Dx_prop _ -> "a datalog proposition" 137 - | Value.Dx_sequent _ -> "a datalog sequent" 138 - | Value.Dx_query _ -> "a datalog query" 139 - | Value.Dx_var _ -> "a datalog variable" 140 - | Value.Dx_const _ -> "a datalog constant" 141 - | Value.Sym _ -> "a symbol" 142 - | Value.Obj _ -> "an object" 143 - 144 - let show_expected_value : expected_value -> string = function 145 - | Content -> "content" 146 - | Text -> "text" 147 - | Obj -> "an object" 148 - | Bool -> "a boolean" 149 - | Sym -> "a symbol" 150 - | Dx_query -> "a datalog query" 151 - | Dx_sequent -> "a datalog sequent" 152 - | Dx_prop -> "a datalog proposition" 153 - | Datalog_term -> "a datalog term" 154 - | Node -> "a node" (* This might be hard to understand for the end user*) 155 - | URI -> "a URI" 156 - | Argument -> "an argument" 157 - 158 - let default_text : t -> Asai.Diagnostic.text = function 159 - | Import_not_found uri -> Asai.Diagnostic.textf "%a not found" URI.pp uri 160 - | Unresolved_xmlns prefix -> 161 - Asai.Diagnostic.textf "Could not resolve prefix `%s` to XML namespace" prefix 162 - | Unresolved_identifier (_, p) -> 163 - Asai.Diagnostic.textf "Unknown binding \\%a. To interpret as a TeX control sequence, explicitly enter TeX mode using #{...}." Trie.pp_path p 164 - | Type_error {got; expected} -> 165 - begin 166 - let expected_msg = 167 - match expected with 168 - | [] -> Asai.Diagnostic.textf "An unknown type error ocurred" 169 - | expected :: [] -> 170 - Asai.Diagnostic.textf "Expected %s" (show_expected_value expected) 171 - | _ -> 172 - Asai.Diagnostic.textf "Expected one of %a" (Format.pp_print_list ~pp_sep: (fun out () -> Format.fprintf out ", ") pp_expected_value) expected 173 - in 174 - let got_msg = 175 - match got with 176 - | None -> Asai.Diagnostic.textf "" 177 - | Some v -> 178 - Asai.Diagnostic.textf " but this is %s" (this_is v) 179 - in 180 - let hint = 181 - match got with 182 - | Some Value.Clo (_, _, _) -> Asai.Diagnostic.textf "Did you forget to supply an argument?" 183 - | Some Value.Content _ 184 - | Some Value.Dx_prop _ 185 - | Some Value.Dx_sequent _ 186 - | Some Value.Dx_query _ 187 - | Some Value.Dx_var _ 188 - | Some Value.Dx_const _ 189 - | Some Value.Sym _ 190 - | Some Value.Obj _ 191 - | None -> 192 - Asai.Diagnostic.textf "" 193 - in 194 - Asai.Diagnostic.textf "%t%t.\n%t" expected_msg got_msg hint 195 - end 196 - | Asset_not_found msg -> Asai.Diagnostic.text msg 197 - | Unbound_method (mthd, {prototype; methods}) -> 198 - let method_names = List.map fst @@ Value.Method_table.to_list methods in 199 - Asai.Diagnostic.textf 200 - "Unbound method %s. Available methods are:@.%a" 201 - mthd 202 - Format.(pp_print_list (fun ppf s -> fprintf ppf " %s" s)) 203 - method_names 204 - | Uninterpreted_config_options keys -> 205 - Asai.Diagnostic.textf 206 - "Uninterpreted config option%s: %a" 207 - ( 208 - if List.length keys = 1 then "" 209 - else if List.length keys > 1 then "s" 210 - else assert false 211 - ) 212 - Format.( 213 - pp_print_list 214 - ~pp_sep: (fun out () -> fprintf out ", ") 215 - (fun ppf k -> 216 - fprintf ppf "%a" (pp_print_list ~pp_sep: (fun out () -> fprintf out ".") pp_print_string) k 217 - ) 218 - ) 219 - keys 220 - | Using_default_option k -> 221 - Asai.Diagnostic.textf 222 - "Configuration option %a is not set. Using default value." 223 - Format.(pp_print_list ~pp_sep: (fun out () -> fprintf out ".") pp_print_string) 224 - k 225 - | Required_config_option k -> 226 - Asai.Diagnostic.textf "Required option %s is not set." k 227 - | Broken_link {uri; suggestion} -> 228 - begin 229 - match suggestion with 230 - | None -> 231 - Asai.Diagnostic.textf "Potentially broken link to `%a`" URI.pp uri 232 - | Some suggestion -> 233 - Asai.Diagnostic.textf "Potentially broken link to `%a`; did you mean `%a`?" URI.pp uri URI.pp suggestion 234 - end 235 - | Resource_not_found uri -> 236 - Asai.Diagnostic.textf "Resource not found: %a" URI.pp uri 237 - | Duplicate_tree (o1, o2) -> 238 - let show_origin = function 239 - | Physical doc -> Lsp.(Uri.to_path @@ Text_document.documentUri doc) 240 - | Subtree {parent} -> Format.asprintf "%a" pp_identity parent 241 - | Undefined -> "undefined" 242 - in 243 - Asai.Diagnostic.textf 244 - "%s@ and@ %s@ use@ the@ same@ URI" 245 - (show_origin o1) 246 - (show_origin o2) 247 - | Invalid_URI 248 - | Asset_has_no_content_address _ 249 - | Reference_error _ 250 - | Parse_error 251 - | Type_warning 252 - | Unbound_fluid_symbol _ 253 - | Unbound_variable _ 254 - | Unhandled_case 255 - | Transclusion_loop 256 - | Internal_error 257 - | Configuration_error 258 - | Initialization_warning 259 - | Routing_error 260 - | Profiling _ 261 - | External_error 262 - | Current_tree_has_no_uri 263 - | IO_error 264 - | Log 265 - | Missing_argument -> 266 - Asai.Diagnostic.text "" 267 - end 13 + module Message = Reporter_message 268 14 269 15 include Asai.StructuredReporter.Make(Message) 270 16
+1 -63
lib/core/Reporter.mli
··· 4 4 * SPDX-License-Identifier: GPL-3.0-or-later 5 5 *) 6 6 7 - module Message : 8 - sig 9 - type expected_value = 10 - | Content 11 - | Text 12 - | Obj 13 - | Bool 14 - | Sym 15 - | Dx_query 16 - | Dx_sequent 17 - | Dx_prop 18 - | Datalog_term 19 - | Node 20 - | URI 21 - | Argument 22 - [@@deriving show] 23 - 24 - type t = 25 - | Import_not_found of URI.t 26 - | Invalid_URI 27 - | Asset_has_no_content_address of string 28 - | Asset_not_found of string 29 - | Current_tree_has_no_uri 30 - | Duplicate_tree of Base.origin * Base.origin 31 - | Parse_error 32 - | Unbound_method of (string * Value.obj) 33 - | Type_warning 34 - | Type_error of 35 - { 36 - got: Value.t option; 37 - expected: expected_value list 38 - } 39 - | Unbound_fluid_symbol of Symbol.t 40 - | Unbound_variable of string 41 - | Unresolved_identifier of ((Resolver.Scope.data, Resolver.P.tag) Trie.t) * Trie.path 42 - | Unresolved_xmlns of string 43 - | Reference_error of URI.t 44 - | Unhandled_case 45 - | Transclusion_loop 46 - | Internal_error 47 - | Configuration_error 48 - | Initialization_warning 49 - | Routing_error 50 - | Profiling of float * float 51 - | External_error 52 - | Resource_not_found of URI.t 53 - | Broken_link of {uri: URI.t; suggestion: URI.t option} 54 - | IO_error 55 - | Log 56 - | Missing_argument 57 - | Uninterpreted_config_options of string list list 58 - | Using_default_option of string list 59 - | Required_config_option of string 60 - 61 - val pp : 62 - Ppx_deriving_runtime.Format.formatter -> 63 - t -> 64 - Ppx_deriving_runtime.unit 65 - val show : t -> Ppx_deriving_runtime.string 66 - val default_severity : t -> Asai.Diagnostic.severity 67 - val short_code : t -> string 68 - val default_text : t -> Asai.Diagnostic.text 69 - end 7 + module Message : module type of Reporter_message 70 8 71 9 include module type of Asai.StructuredReporter.Make(Message) 72 10 module Tty : module type of Asai.Tty.Make(Message)
+261
lib/core/Reporter_message.ml
··· 1 + open Forester_prelude 2 + open Base 3 + 4 + open struct 5 + module R = Resolver 6 + module Sc = R.Scope 7 + end 8 + 9 + type expected_value = 10 + | Content 11 + | Text 12 + | Obj 13 + | Bool 14 + | Sym 15 + | Dx_query 16 + | Dx_sequent 17 + | Dx_prop 18 + | Datalog_term 19 + | Node 20 + | URI 21 + | Argument 22 + [@@deriving show] 23 + 24 + type t = 25 + | Import_not_found of URI.t 26 + | Invalid_URI 27 + | Asset_has_no_content_address of string 28 + | Asset_not_found of string 29 + | Current_tree_has_no_uri 30 + | Duplicate_tree of origin * origin 31 + | Parse_error 32 + | Unbound_method of (string * Value.obj) 33 + | Type_warning 34 + | Type_error of 35 + { 36 + got: Value.t option; 37 + expected: expected_value list 38 + } 39 + | Unbound_fluid_symbol of Symbol.t 40 + | Unbound_variable of string 41 + | Unresolved_identifier of ((Sc.data, R.P.tag) Trie.t [@opaque]) * Trie.path 42 + | Unresolved_xmlns of string 43 + | Reference_error of URI.t 44 + | Unhandled_case 45 + | Transclusion_loop 46 + | Internal_error 47 + | Configuration_error 48 + | Initialization_warning 49 + | Routing_error 50 + | Profiling of float * float 51 + | External_error 52 + | Resource_not_found of URI.t 53 + | Broken_link of {uri: URI.t; suggestion: URI.t option} 54 + | IO_error 55 + | Log 56 + | Missing_argument 57 + | Uninterpreted_config_options of string list list 58 + | Using_default_option of string list 59 + | Required_config_option of string 60 + [@@deriving show] 61 + 62 + let default_severity : t -> Asai.Diagnostic.severity = function 63 + | Import_not_found _ -> Error 64 + | Unresolved_identifier _ -> Warning 65 + | Unresolved_xmlns _ -> Error 66 + | Invalid_URI -> Error 67 + | Unbound_method _ -> Error 68 + | Asset_has_no_content_address _ -> Error 69 + | Asset_not_found _ -> Error 70 + | Current_tree_has_no_uri -> Error 71 + | Reference_error _ -> Error 72 + | Duplicate_tree _ -> Error 73 + | Parse_error -> Error 74 + | Type_error _ -> Error 75 + | Type_warning -> Warning 76 + | Unbound_fluid_symbol _ -> Error 77 + | Unbound_variable _ -> Error 78 + | Unhandled_case -> Bug 79 + | Transclusion_loop -> Error 80 + | Internal_error -> Bug 81 + | Configuration_error -> Error 82 + | Initialization_warning -> Warning 83 + | Routing_error -> Error 84 + | Profiling _ -> Info 85 + | External_error -> Error 86 + | Log -> Info 87 + | Resource_not_found _ -> Error 88 + | Broken_link _ -> Warning 89 + | IO_error -> Error 90 + | Missing_argument -> Error 91 + | Uninterpreted_config_options _ -> Warning 92 + | Using_default_option _ -> Info 93 + | Required_config_option string -> Error 94 + 95 + let short_code : t -> string = function 96 + | Import_not_found _ -> "import_not_found" 97 + | Invalid_URI -> "invalid_uri" 98 + | Asset_has_no_content_address _ -> "asset_not_found" (* This is taken from the original wording of the message, but I think this is very confusing.*) 99 + | Asset_not_found _ -> "asset_not_found" 100 + | Current_tree_has_no_uri -> "current_tree_has_no_uri" 101 + | Duplicate_tree _ -> "duplicate_tree" 102 + | Parse_error -> "parse_error" 103 + | Unbound_method _ -> "unbound_method" 104 + | Type_warning -> "type_warning" 105 + | Type_error _ -> "type_error" 106 + | Unbound_fluid_symbol _ -> "unbound_fluid_symbol" 107 + | Unbound_variable _ -> "Unbound_variable" 108 + | Unresolved_xmlns _ -> "unresolved_xmlns" 109 + | Unresolved_identifier _ -> "unresolved_identifier" 110 + | Reference_error _ -> "reference_error" 111 + | Unhandled_case -> "unhandled_case" 112 + | Transclusion_loop -> "transclusion_loop" 113 + | Internal_error -> "internal_error" 114 + | Configuration_error -> "configuration_error" 115 + | Initialization_warning -> "initialization_warning" 116 + | Routing_error -> "routing_error" 117 + | Profiling (_, _) -> "profiling" 118 + | External_error -> "external_error" 119 + | Resource_not_found _ -> "resource_not_found" 120 + | Broken_link _ -> "broken_link" 121 + | IO_error -> "io_error" 122 + | Log -> "log" 123 + | Missing_argument -> "missing_argument" 124 + | Uninterpreted_config_options _ -> "unknown_config_option" 125 + | Using_default_option _ -> "using_default_option" 126 + | Required_config_option _ -> "required_config_option" 127 + 128 + let this_is : Value.t -> string = function 129 + | Value.Content _ -> "content" 130 + | Value.Clo (_, _, _) -> "a closure" 131 + | Value.Dx_prop _ -> "a datalog proposition" 132 + | Value.Dx_sequent _ -> "a datalog sequent" 133 + | Value.Dx_query _ -> "a datalog query" 134 + | Value.Dx_var _ -> "a datalog variable" 135 + | Value.Dx_const _ -> "a datalog constant" 136 + | Value.Sym _ -> "a symbol" 137 + | Value.Obj _ -> "an object" 138 + 139 + let show_expected_value : expected_value -> string = function 140 + | Content -> "content" 141 + | Text -> "text" 142 + | Obj -> "an object" 143 + | Bool -> "a boolean" 144 + | Sym -> "a symbol" 145 + | Dx_query -> "a datalog query" 146 + | Dx_sequent -> "a datalog sequent" 147 + | Dx_prop -> "a datalog proposition" 148 + | Datalog_term -> "a datalog term" 149 + | Node -> "a node" (* This might be hard to understand for the end user*) 150 + | URI -> "a URI" 151 + | Argument -> "an argument" 152 + 153 + let default_text : t -> Asai.Diagnostic.text = function 154 + | Import_not_found uri -> Asai.Diagnostic.textf "%a not found" URI.pp uri 155 + | Unresolved_xmlns prefix -> 156 + Asai.Diagnostic.textf "Could not resolve prefix `%s` to XML namespace" prefix 157 + | Unresolved_identifier (_, p) -> 158 + Asai.Diagnostic.textf "Unknown binding \\%a. To interpret as a TeX control sequence, explicitly enter TeX mode using #{...}." Trie.pp_path p 159 + | Type_error {got; expected} -> 160 + begin 161 + let expected_msg = 162 + match expected with 163 + | [] -> Asai.Diagnostic.textf "An unknown type error ocurred" 164 + | expected :: [] -> 165 + Asai.Diagnostic.textf "Expected %s" (show_expected_value expected) 166 + | _ -> 167 + Asai.Diagnostic.textf "Expected one of %a" (Format.pp_print_list ~pp_sep: (fun out () -> Format.fprintf out ", ") pp_expected_value) expected 168 + in 169 + let got_msg = 170 + match got with 171 + | None -> Asai.Diagnostic.textf "" 172 + | Some v -> 173 + Asai.Diagnostic.textf " but this is %s" (this_is v) 174 + in 175 + let hint = 176 + match got with 177 + | Some Value.Clo (_, _, _) -> Asai.Diagnostic.textf "Did you forget to supply an argument?" 178 + | Some Value.Content _ 179 + | Some Value.Dx_prop _ 180 + | Some Value.Dx_sequent _ 181 + | Some Value.Dx_query _ 182 + | Some Value.Dx_var _ 183 + | Some Value.Dx_const _ 184 + | Some Value.Sym _ 185 + | Some Value.Obj _ 186 + | None -> 187 + Asai.Diagnostic.textf "" 188 + in 189 + Asai.Diagnostic.textf "%t%t.\n%t" expected_msg got_msg hint 190 + end 191 + | Asset_not_found msg -> Asai.Diagnostic.text msg 192 + | Unbound_method (mthd, {prototype; methods}) -> 193 + let method_names = List.map fst @@ Value.Method_table.to_list methods in 194 + Asai.Diagnostic.textf 195 + "Unbound method %s. Available methods are:@.%a" 196 + mthd 197 + Format.(pp_print_list (fun ppf s -> fprintf ppf " %s" s)) 198 + method_names 199 + | Uninterpreted_config_options keys -> 200 + Asai.Diagnostic.textf 201 + "Uninterpreted config option%s: %a" 202 + ( 203 + if List.length keys = 1 then "" 204 + else if List.length keys > 1 then "s" 205 + else assert false 206 + ) 207 + Format.( 208 + pp_print_list 209 + ~pp_sep: (fun out () -> fprintf out ", ") 210 + (fun ppf k -> 211 + fprintf ppf "%a" (pp_print_list ~pp_sep: (fun out () -> fprintf out ".") pp_print_string) k 212 + ) 213 + ) 214 + keys 215 + | Using_default_option k -> 216 + Asai.Diagnostic.textf 217 + "Configuration option %a is not set. Using default value." 218 + Format.(pp_print_list ~pp_sep: (fun out () -> fprintf out ".") pp_print_string) 219 + k 220 + | Required_config_option k -> 221 + Asai.Diagnostic.textf "Required option %s is not set." k 222 + | Broken_link {uri; suggestion} -> 223 + begin 224 + match suggestion with 225 + | None -> 226 + Asai.Diagnostic.textf "Potentially broken link to `%a`" URI.pp uri 227 + | Some suggestion -> 228 + Asai.Diagnostic.textf "Potentially broken link to `%a`; did you mean `%a`?" URI.pp uri URI.pp suggestion 229 + end 230 + | Resource_not_found uri -> 231 + Asai.Diagnostic.textf "Resource not found: %a" URI.pp uri 232 + | Duplicate_tree (o1, o2) -> 233 + let show_origin = function 234 + | Physical doc -> Lsp.(Uri.to_path @@ Text_document.documentUri doc) 235 + | Subtree {parent} -> Format.asprintf "%a" pp_identity parent 236 + | Undefined -> "undefined" 237 + in 238 + Asai.Diagnostic.textf 239 + "%s@ and@ %s@ use@ the@ same@ URI" 240 + (show_origin o1) 241 + (show_origin o2) 242 + | Invalid_URI 243 + | Asset_has_no_content_address _ 244 + | Reference_error _ 245 + | Parse_error 246 + | Type_warning 247 + | Unbound_fluid_symbol _ 248 + | Unbound_variable _ 249 + | Unhandled_case 250 + | Transclusion_loop 251 + | Internal_error 252 + | Configuration_error 253 + | Initialization_warning 254 + | Routing_error 255 + | Profiling _ 256 + | External_error 257 + | Current_tree_has_no_uri 258 + | IO_error 259 + | Log 260 + | Missing_argument -> 261 + Asai.Diagnostic.text ""