Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file extend_helper.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165# 1 "extend_helper.cppo.ml"openParsetreeopenExtend_protocol# 10 "extend_helper.cppo.ml"(** Default implementation for [Reader_def.print_outcome] using
[Oprint] from compiler-libs *)letprint_outcome_using_oprintppf=function|Reader.Out_valuex->!Oprint.out_valueppfx|Reader.Out_typex->!Oprint.out_typeppfx|Reader.Out_class_typex->!Oprint.out_class_typeppfx|Reader.Out_module_typex->!Oprint.out_module_typeppfx|Reader.Out_sig_itemx->!Oprint.out_sig_itemppfx|Reader.Out_signaturex->!Oprint.out_signatureppfx|Reader.Out_type_extensionx->!Oprint.out_type_extensionppfx|Reader.Out_phrasex->!Oprint.out_phraseppfx(** Generate an extension node that will be reported as a syntax error by
Merlin. *)letsyntax_errormsgloc:extension=letstr=Location.mkloc"merlin.syntax-error"locinletpayload=PStr[{pstr_loc=Location.none;pstr_desc=Pstr_eval({pexp_loc=Location.none;pexp_desc=Pexp_constant(# 30 "extend_helper.cppo.ml"Parsetree.Pconst_string# 30 "extend_helper.cppo.ml"(msg,None));pexp_attributes=[];# 33 "extend_helper.cppo.ml"pexp_loc_stack=[]# 35 "extend_helper.cppo.ml"},[]);}]in(str,payload);;(** Physical locations might be too precise for some features.
For instance in:
let x = f in y
^1 ^2
Merlin cannot distinguish position ^1 from ^2 in the normal AST,
because IN doesn't appear in abstract syntax. This is a problem when
completing, because a different environment should be selected for both
positions.
One can add relaxed_location attributes to make some locations closer to
the concrete syntax.
Here is the same line annotated with physical and relaxed locations:
let x = f in y
[ ] [ ] -- physical locations for f and y nodes
[ ][ ] -- relaxed locations for f and y nodes
*)letrelaxed_locationloc:attribute=letstr=Location.mkloc"merlin.relaxed-location"locin# 64 "extend_helper.cppo.ml"{attr_name=str;attr_payload=PStr[];attr_loc=str.loc}# 72 "extend_helper.cppo.ml";;(** If some code should be ignored by merlin when reporting information to
the user, put a hide_node attribute.
This is useful for generated/desugared code which doesn't correspond to
anything in concrete syntax (example use-case: encoding of some
js_of_ocaml constructs).
*)lethide_node:attribute=letstr=Location.mknoloc"merlin.hide"in# 85 "extend_helper.cppo.ml"{attr_name=str;attr_payload=PStr[];attr_loc=str.loc}# 95 "extend_helper.cppo.ml"(** The converse: when merlin should focus on a specific node of the AST.
The main use case is also for js_of_ocaml.
Assuming <code> is translated to:
let module M = struct
let prolog = ... (* boilerplate *)
let code = <mapping-of-code>
let epilog = ... (* boilerplate *)
end
in M.boilerplate
To make merlin focus on [M.code] and ignore the boilerplate ([M.prolog]
and [M.epilog]), add a [focus_node] attribute to the [M.code] item.
*)letfocus_node:attribute=letstr=Location.mknoloc"merlin.focus"in# 115 "extend_helper.cppo.ml"{attr_name=str;attr_payload=PStr[];attr_loc=str.loc}# 124 "extend_helper.cppo.ml"(* Projections for merlin attributes and extensions *)letclassify_extension(id,_:extension):[`Other|`Syntax_error]=matchid.Location.txtwith|"merlin.syntax-error"->`Syntax_error|_->`Otherletclassify_attribute(attr:attribute):[`Other|`Relaxed_location|`Hide|`Focus]=# 133 "extend_helper.cppo.ml"matchattr.Parsetree.attr_name.Location.txtwith# 137 "extend_helper.cppo.ml"|"merlin.relaxed-location"->`Relaxed_location|"merlin.hide"->`Hide|"merlin.focus"->`Focus|_->`Otherletextract_syntax_error(id,payload:extension):string*Location.t=ifid.Location.txt<>"merlin.syntax-error"theninvalid_arg"Merlin_extend.Reader_helper.extract_syntax_error";letmsg=matchpayloadwith|PStr[{pstr_desc=Pstr_eval({pexp_desc=Pexp_constant(# 148 "extend_helper.cppo.ml"Parsetree.Pconst_string# 148 "extend_helper.cppo.ml"(msg,_));_},_);_}]->msg|_->"Warning: extension produced an incorrect syntax-error node"inmsg,id.Location.locletextract_relaxed_location:attribute->Location.t=function# 157 "extend_helper.cppo.ml"|{attr_name={Location.txt="merlin.relaxed-location";loc};_}->loc# 161 "extend_helper.cppo.ml"|_->invalid_arg"Merlin_extend.Reader_helper.extract_relaxed_location"