123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827(* {{{ COPYING *(
This file is part of Merlin, an helper for ocaml editors
Copyright (C) 2013 - 2015 Frédéric Bour <frederic.bour(_)lakaban.net>
Thomas Refis <refis.thomas(_)gmail.com>
Simon Castellan <simon.castellan(_)iuwt.fr>
Tomasz Kołodziejski <tkolodziejski(_)gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
The Software is provided "as is", without warranty of any kind, express or
implied, including but not limited to the warranties of merchantability,
fitness for a particular purpose and noninfringement. In no event shall
the authors or copyright holders be liable for any claim, damages or other
liability, whether in an action of contract, tort or otherwise, arising
from, out of or in connection with the software or the use or other dealings
in the Software.
)* }}} *)openStdtypecommand=|Command:string*Marg.docstring*([`Mandatory|`Optional|`Many]*'argsMarg.spec)list*'args*(Mpipeline.t->'args->json)->commandletcommandname?(doc="")~spec~defaultf=Command(name,doc,spec,default,f)letarg?(kind=`Mandatory)namedocaction=(kind,(name,doc,action))letoptionalx=arg~kind:`Optionalxletmanyx=arg~kind:`Manyxletmarg_positionf=Marg.param"position"(function|"start"->f`Start|"end"->f`End|str->(matchint_of_stringstrwith|n->f(`Offsetn)|exception_->(matchletoffset=String.indexstr':'inletline=String.substr~pos:0~len:offsetinletcol=String.substr~pos:(offset+1)~len:(String.lengthstr-offset-1)in`Logical(int_of_stringline,int_of_stringcol)with|pos->fpos|exception_->failwithf"expecting position, got %S. position can be \
start|end|<offset>|<line>:<col>, where offset, line and col are \
numbers, lines are indexed from 1."str)))letmarg_completion_kindf=Marg.param"completion-kind"(function|"t"|"type"|"types"->f`Types|"v"|"val"|"value"|"values"->f`Values|"variant"|"variants"|"var"->f`Variants|"c"|"constr"|"constructor"->f`Constructor|"l"|"label"|"labels"->f`Labels|"m"|"mod"|"module"->f`Modules|"mt"|"modtype"|"module-type"->f`Modules_type|"k"|"kw"|"keyword"->f`Keywords|str->failwithf"expecting completion kind, got %S. kind can be value, variant, \
constructor, label, module or module-type"str)letcommand_is~name(Command(name',_,_,_,_))=String.equalnamename'letfind_commandname=List.find~f:(command_is~name)letfind_command_optname=List.find_opt~f:(command_is~name)letrunpipelinequery=Logger.log~section:"New_commands"~title:"run(query)""%a"Logger.json(fun()->Query_json.dumpquery);letresult=Query_commands.dispatchpipelinequeryinletjson=Query_json.json_of_responsequeryresultinjsonletall_commands=[command"case-analysis"~spec:[arg"-start""<position> Where analysis starts"(marg_position(funstartp(_startp,endp)->(startp,endp)));arg"-end""<position> Where analysis ends"(marg_position(funendp(startp,_endp)->(startp,endp)))]~doc:"When the range determined by (-start, -end) positions is an expression,\n\
this command replaces it with [match expr with _] expression where a \
branch is introduced for each immediate value constructor of the type \
that was determined for expr.\n\
When it is a variable pattern, it is further expanded and new \
branches are introduced for each possible immediate constructor of \
this variable.\n\
The return value has the shape `[{'start': position, 'end': \
position}, content]`, where content is string.\n"~default:(`Offset(-1),`Offset(-1))beginfunbuffer->function|`Offset-1,_->failwith"-start <pos> is mandatory"|_,`Offset-1->failwith"-end <pos> is mandatory"|startp,endp->runbuffer(Query_protocol.Case_analysis(startp,endp))end;command"holes"~spec:[]~doc:"Returns the list of the positions of all the holes in the file."~default:()beginfunbuffer()->runbufferQuery_protocol.Holesend;command"construct"~spec:[arg"-position""<position> Position where construct should happen"(marg_position(funpos(_pos,with_values,depth)->(pos,with_values,depth)));optional"-with-values""<none|local> Use values from the environment"(Marg.param"<none|local>"(funwith_values(pos,_with_values,depth)->matchwith_valueswith|"none"->(pos,None,depth)|"local"->(pos,Some`Local,depth)|_->failwith"-with-values should be one of none or local"));optional"-depth""<int> Depth for the search (defaults to 1)"(Marg.param"int"(fundepth(pos,with_values,_depth)->matchint_of_stringdepthwith|depth->ifdepth>=1then(pos,with_values,Somedepth)elsefailwith"depth should be a positive integer"|exception_->failwith"depth should be a positive integer"))]~doc:"The construct command returns a list of expressions that could fill a\n\
hole at '-position' given its inferred type. The '-depth' parameter \
allows to\n\
recursively construct terms. Note that when '-depth' > 1 partial \
results of\n\
inferior depth will not be returned."~default:(`Offset(-1),None,None)beginfunbuffer(pos,with_values,max_depth)->matchposwith|`Offset-1->failwith"-position <pos> is mandatory"|pos->runbuffer(Query_protocol.Construct(pos,with_values,max_depth))end;command"complete-prefix"~spec:[arg"-position""<position> Position to complete"(marg_position(funpos(txt,_pos,kinds,doc,typ)->(txt,pos,kinds,doc,typ)));optional"-doc""<bool> Add docstring to entries (default is false)"(Marg.bool(fundoc(txt,pos,kinds,_doc,typ)->(txt,pos,kinds,doc,typ)));arg"-prefix""<string> Prefix to complete"(Marg.param"string"(funtxt(_,pos,kinds,doc,typ)->(txt,pos,kinds,doc,typ)));optional"-types""<bool> Report type information (default is true)"(Marg.bool(funtyp(txt,pos,kinds,doc,_typ)->(txt,pos,kinds,doc,typ)));optional"-kind""<completion-kind> Namespace to complete (value, constructor, \
type, variant, label, module, module-type). Default is decided by \
cursor context"(marg_completion_kind(funkind(txt,pos,kinds,doc,typ)->(txt,pos,kind::kinds,doc,typ)))]~doc:"This functions completes an identifier that the user started to type.\n\
It returns a list of possible completions.\n\
With '-types y' (default), each completion comes with type information.\n\
With '-doc y' it tries to lookup OCamldoc, which is slightly more \
time consuming.\n\n\
The result has the form:\n\
```javascript\n\
{\n\
\ 'context': (null | ['application',{'argument_type': string, \
'labels': [{'name':string,'type':string}]}]),\n\
\ 'entries': \
[{'name':string,'kind':string,'desc':string,'info':string}]\n\
}\n\
```\n\n\
Context describe where completion is occurring. Only application is \
distinguished now: that's when one is completing the arguments to a \
function call. In this case, one gets the type expected at the cursor \
as well as the other labels.\n\n\
Entries is the list of possible completion. Each entry is made of:\n\
- a name, the text that should be put in the buffer if selected\n\
- a kind, one of `'value'`, `'variant'`, `'constructor'`, `'label'`, \
`'module'`, `'signature'`, `'type'`, `'method'`, `'#'` (for method \
calls), `'exn'`, `'class'`\n\
- a description, most of the time a type or a definition line, to be \
put next to the name in completion box\n\
- optional information which might not fit in the completion box, \
like signatures for modules or documentation string."~default:("",`None,[],false,true)beginfunbuffer(txt,pos,kinds,doc,typ)->matchposwith|`None->failwith"-position <pos> is mandatory"|#Msource.positionaspos->runbuffer(Query_protocol.Complete_prefix(txt,pos,List.revkinds,doc,typ))end;command"document"~doc:"Returns OCamldoc documentation as a string.\n\
If `-identifier ident` is specified, documentation for this ident is \
looked up from environment at `-position`.\n\
Otherwise, Merlin looks for the documentation for the entity under \
the cursor (at `-position`)."~spec:[arg"-position""<position> Position to complete"(marg_position(funpos(ident,_pos)->(ident,pos)));optional"-identifier""<string> Identifier"(Marg.param"string"(funident(_ident,pos)->(Someident,pos)))]~default:(None,`None)beginfunbuffer(ident,pos)->matchposwith|`None->failwith"-position <pos> is mandatory"|#Msource.positionaspos->runbuffer(Query_protocol.Document(ident,pos))end;command"syntax-document"~doc:"Returns documentation for OCaml syntax for the entity under the cursor"~spec:[arg"-position""<position> Position to complete"(marg_position(funpos_pos->pos))]~default:`Nonebeginfunbufferpos->matchposwith|`None->failwith"-position <pos> is mandatory"|#Msource.positionaspos->runbuffer(Query_protocol.Syntax_documentpos)end;command"expand-ppx"~doc:"Returns the generated code of a PPX."~spec:[arg"-position""<position> Position to expand"(marg_position(funpos_pos->pos))]~default:`Nonebeginfunbufferpos->matchposwith|`None->failwith"-position <pos> is mandatory"|#Msource.positionaspos->runbuffer(Query_protocol.Expand_ppxpos)end;command"enclosing"~spec:[arg"-position""<position> Position to complete"(marg_position(funpos_pos->pos))]~doc:"Returns a list of locations `{'start': position, 'end': position}` in \
increasing size of all entities surrounding the position.\n\
(In a lisp, this would be the locations of all s-exps that contain \
the cursor.)"~default:`Nonebeginfunbufferpos->matchposwith|`None->failwith"-position <pos> is mandatory"|#Msource.positionaspos->runbuffer(Query_protocol.Enclosingpos)end;command"errors"~spec:[arg"-lexing""<bool> Whether to report lexing errors or not"(Marg.bool(funl(_,p,t)->(l,p,t)));arg"-parsing""<bool> Whether to report parsing errors or not"(Marg.bool(funp(l,_,t)->(l,p,t)));arg"-typing""<bool> Whether to report typing errors or not"(Marg.bool(funt(l,p,_)->(l,p,t)))]~doc:"Returns a list of errors in current buffer.\n\
The value is a list where each item as the shape:\n\n\
```javascript\n\
{\n\
'start' : position,\n\
'end' : position,\n\
'valid' : bool,\n\
'message' : string,\n\
'type' : ('type'|'parser'|'env'|'warning'|'unkown')\n\
}\n\
```\n\n\
`start` and `end` are omitted if error has no location (e.g. wrong \
file format), otherwise the editor should probably highlight / mark \
this range.\n\
`type` is an attempt to classify the error.\n\
`valid` is here mostly for informative purpose. It reflects whether \
Merlin was expecting such an error to be possible or not, and is \
useful for debugging purposes.\n\
`message` is the error description to be shown to the user."~default:(true,true,true)beginfunbuffer(lexing,parsing,typing)->runbuffer(Query_protocol.Errors{lexing;parsing;typing})end;command"expand-prefix"~doc:"\n\
The function behaves like `complete-prefix`, but it also handles \
partial, incorrect, or wrongly spelled prefixes (as determined by \
some heuristic).\n\
For instance, `L.ma` can get expanded to `List.map`. This function is \
a useful fallback if normal completion gave no results.\n\
Be careful that it always return fully qualified paths, whereas \
normal completion only completes an identifier (last part of a module \
path)."~spec:[arg"-position""<position> Position to complete"(marg_position(funpos(txt,_pos,kinds,typ)->(txt,pos,kinds,typ)));arg"-prefix""<string> Prefix to complete"(Marg.param"string"(funtxt(_prefix,pos,kinds,typ)->(txt,pos,kinds,typ)));optional"-types""<bool> Report type information (default is false)"(Marg.bool(funtyp(txt,pos,kinds,_typ)->(txt,pos,kinds,typ)));optional"-kind""<completion-kind> Namespace to complete (value, constructor, \
type, variant, label, module, module-type). Default is decided by \
cursor context"(marg_completion_kind(funkind(txt,pos,kinds,typ)->(txt,pos,kind::kinds,typ)))]~default:("",`None,[],false)beginfunbuffer(txt,pos,kinds,typ)->matchposwith|`None->failwith"-position <pos> is mandatory"|#Msource.positionaspos->runbuffer(Query_protocol.Expand_prefix(txt,pos,List.revkinds,typ))end;command"extension-list"~spec:[optional"-status""<all|enabled|disabled> Filter extensions"(Marg.param"<all|enabled|disabled>"(funstatus_status->matchstatuswith|"all"->`All|"enabled"->`Enabled|"disabled"->`Disabled|_->failwith"-status should be one of all, disabled or enabled"))]~doc:"List all known / currently enabled / currently disabled extensions as \
a list of strings."~default:`Allbeginfunbufferstatus->runbuffer(Query_protocol.Extension_liststatus)end;command"findlib-list"~doc:"Returns all known findlib packages as a list of string."~spec:[]~default:()beginfunbuffer()->runbufferQuery_protocol.Findlib_listend;command"flags-list"~spec:[]~doc:"Returns supported compiler flags.The purpose of this command is to \
implement interactive completion of compiler settings in an IDE."~default:()beginfun_()->`List(List.map~f:Json.string(Mconfig.flags_for_completion()))end;command"jump"~spec:[arg"-target""<string> Entity to jump to"(Marg.param"string"(funtarget(_,pos)->(target,pos)));arg"-position""<position> Position to complete"(marg_position(funpos(target,_pos)->(target,pos)))]~doc:"This command can be used to assist navigation in a source code buffer.\n\
Target is a string that can contain one or more of the 'fun', 'let', \
'module', 'module-type' and 'match' words.\n\
It returns the starting position of the function, let definition, \
module or match expression that contains the cursor\n"~default:("",`None)beginfunbuffer(target,pos)->matchposwith|`None->failwith"-position <pos> is mandatory"|#Msource.positionaspos->runbuffer(Query_protocol.Jump(target,pos))end;command"phrase"~spec:[arg"-target""<next|prev> Entity to jump to"(Marg.param"string"(funtarget(_,pos)->matchtargetwith|"next"->(`Next,pos)|"prev"->(`Prev,pos)|_->failwith"-target should be one of 'next' or 'prev'"));arg"-position""<position> Position to complete"(marg_position(funpos(target,_pos)->(target,pos)))]~doc:"Returns the position of the next or previous phrase (top-level \
definition or module definition)."~default:(`Next,`None)beginfunbuffer(target,pos)->matchposwith|`None->failwith"-position <pos> is mandatory"|#Msource.positionaspos->runbuffer(Query_protocol.Phrase(target,pos))end;command"list-modules"~spec:[many"-ext""<extension> file extensions to look for"(Marg.param"extension"(funextexts->ext::exts))]~doc:"Looks into project source paths for files with an extension matching \
and prints the corresponding module name."~default:[]beginfunbufferextensions->runbuffer(Query_protocol.List_modules(List.revextensions))end;command"locate"~spec:[optional"-prefix""<string> Prefix to complete"(Marg.param"string"(funtxt(_,pos,kind)->(Sometxt,pos,kind)));arg"-position""<position> Position to complete"(marg_position(funpos(prefix,_pos,kind)->(prefix,pos,kind)));optional"-look-for""<interface|implementation> Prefer opening interface or \
implementation"(Marg.param"<interface|implementation>"(funkind(prefix,pos,_)->matchkindwith|"mli"|"interface"->(prefix,pos,`MLI)|"ml"|"implementation"->(prefix,pos,`ML)|str->failwithf"expecting interface or implementation, got %S."str))]~doc:"Finds the declaration of entity at the specified position, Or \
referred to by specified string.\n\
Returns either:\n\
- if location failed, a `string` describing the reason to the user,\n\
- `{'pos': position}` if the location is in the current buffer,\n\
- `{'file': string, 'pos': position}` if definition is located in a \
different file."~default:(None,`None,`MLI)beginfunbuffer(prefix,pos,lookfor)->matchposwith|`None->failwith"-position <pos> is mandatory"|#Msource.positionaspos->runbuffer(Query_protocol.Locate(prefix,lookfor,pos))end;command"locate-type"~spec:[arg"-position""<position> Position to complete"(marg_position(funpos_->pos))]~doc:"Locate the declaration of the type of the expression"~default:`Nonebeginfunbufferpos->matchposwith|`None->failwith"-position <pos> is mandatory"|#Msource.positionaspos->runbuffer(Query_protocol.Locate_typepos)end;command"occurrences"~spec:[arg"-identifier-at""<position> Position of the identifier"(marg_position(funpos(_pos,scope)->(`Ident_atpos,scope)));optional"-scope""buffer|project Scope of the query"(Marg.param"<buffer|project>"(funscope(pos,_scope)->matchscopewith|"buffer"->(pos,`Buffer)|"project"->(pos,`Project)|_->failwith"-scope should be one of buffer or project"))]~doc:"Returns a list of locations `{'start': position, 'end': position}` of \
all occurrences in current buffer of the entity at the specified \
position."~default:(`None,`Buffer)beginfunbuffer->function|`None,_->failwith"-identifier-at <pos> is mandatory"|`Ident_atpos,scope->runbuffer(Query_protocol.Occurrences(`Ident_atpos,scope))end;command"outline"~spec:[]~doc:"Returns a tree of objects `{'start': position, 'end': position, \
'name': string, 'kind': string, 'children': subnodes}` describing the \
content of the buffer."~default:()beginfunbuffer()->runbufferQuery_protocol.Outlineend;command"path-of-source"~doc:"Looks for first file with a matching name in the project source and \
build paths"~spec:[arg"-file""<filename> filename to look for in project paths"(Marg.param"filename"(funfilefiles->file::files))]~default:[]beginfunbufferfilenames->runbuffer(Query_protocol.Path_of_source(List.revfilenames))end;command"refactor-open"~doc:"refactor-open -position pos -action <qualify|unqualify>\n\tTODO"~spec:[arg"-position""<position> Position to complete"(marg_position(funpos(action,_pos)->(action,pos)));arg"-action""<qualify|unqualify> Direction of rewriting"(Marg.param"<qualify|unqualify>"(funaction(_action,pos)->matchactionwith|"qualify"->(Some`Qualify,pos)|"unqualify"->(Some`Unqualify,pos)|_->failwith"invalid -action"))]~default:(None,`None)beginfunbuffer->function|None,_->failwith"-action is mandatory"|_,`None->failwith"-position is mandatory"|Someaction,(#Msource.positionaspos)->runbuffer(Query_protocol.Refactor_open(action,pos))end;command"search-by-polarity"~doc:"search-by-polarity -position pos -query ident\n\tTODO"~spec:[arg"-position""<position> Position to complete"(marg_position(funpos(query,_pos)->(query,pos)));arg"-query""<string> Query of the form TODO"(Marg.param"string"(funquery(_prefix,pos)->(query,pos)))]~default:("",`None)beginfunbuffer(query,pos)->matchposwith|`None->failwith"-position <pos> is mandatory"|#Msource.positionaspos->runbuffer(Query_protocol.Polarity_search(query,pos))end;command"search-by-type"~doc:"return a list of values that match a query"~spec:[arg"-position""<position> to complete"(marg_position(funpos(query,_pos,limit,with_doc)->(query,pos,limit,with_doc)));arg"-query""<query> to request values"(Marg.param"string"(funquery(_query,pos,limit,with_doc)->(Somequery,pos,limit,with_doc)));optional"-limit""<int> the maximal amount of results (default is 100)"(Marg.int(funlimit(query,pos,_limit,with_doc)->(query,pos,limit,with_doc)));optional"-with-doc""<bool> include docstring (default is false)"(Marg.bool(funwith_doc(query,pos,limit,_with_doc)->(query,pos,limit,with_doc)))]~default:(None,`None,100,false)beginfunbuffer(query,pos,limit,with_doc)->match(query,pos)with|None,`None->failwith"-position <pos> and -query <string> are mandatory"|None,_->failwith"-query <string> is mandatory"|_,`None->failwith"-position <pos> is mandatory"|Somequery,(#Msource.positionaspos)->runbuffer(Query_protocol.Type_search(query,pos,limit,with_doc))end;command"inlay-hints"~doc:"return a list of inly-hints for additional client (like LSP)"~spec:[arg"-start""<position> Where inlay-hints generation start"(marg_position(funstart(_start,stop,let_binding,pattern_binding,ghost)->(start,stop,let_binding,pattern_binding,ghost)));arg"-end""<position> Where inlay-hints generation stop"(marg_position(funstop(start,_stop,let_binding,pattern_binding,ghost)->(start,stop,let_binding,pattern_binding,ghost)));optional"-let-binding""<bool> Hint let-binding (default is false)"(Marg.bool(funlet_binding(start,stop,_let_binding,pattern_binding,ghost)->(start,stop,let_binding,pattern_binding,ghost)));optional"-pattern-binding""<bool> Hint pattern-binding (default is false)"(Marg.bool(funpattern_binding(start,stop,let_binding,_pattern_binding,ghost)->(start,stop,let_binding,pattern_binding,ghost)));optional"-avoid-ghost-location""<bool> Avoid hinting ghost location (default is true)"(Marg.bool(funghost(start,stop,let_binding,pattern_binding,_ghost)->(start,stop,let_binding,pattern_binding,ghost)))]~default:(`None,`None,false,false,true)beginfunbuffer(start,stop,let_binding,pattern_binding,avoid_ghost)->match(start,stop)with|`None,`None->failwith"-start <pos> and -end are mandatory"|`None,_->failwith"-start <pos> is mandatory"|_,`None->failwith"-end <pos> is mandatory"|(#Msource.position,#Msource.position)asposition->letstart,stop=positioninrunbuffer(Query_protocol.Inlay_hints(start,stop,let_binding,pattern_binding,avoid_ghost))end;command"shape"~doc:"This command can be used to assist navigation in a source code buffer.\n\
It returns a tree of all relevant locations around the cursor.\n\
It is similar to outline without telling any information about the \
entity at a given location.\n\
```javascript\n\
shape =\n\
{\n\
\ 'start' : position,\n\
\ 'end' : position,\n\
\ 'children' : [shape]\n\
}\n\
```\n"~spec:[arg"-position""<position> Position "(marg_position(funpos_pos->pos))]~default:`Nonebeginfunbuffer->function|`None->failwith"-position <pos> is mandatory"|#Msource.positionaspos->runbuffer(Query_protocol.Shapepos)end;command"type-enclosing"~doc:"Returns a list of type information for all expressions at given \
position, sorted by increasing size.\n\
That is asking for type enlosing around `2` in `string_of_int 2` will \
return the types of `2 : int` and `string_of_int 2 : string`.\n\n\
If `-expression` and `-cursor` are specified, the first result will \
be the type\n\
relevant to the prefix ending at the `cursor` offset.\n\n\
`-index` can be used to print only one type information. This is \
useful to\n\
query the types lazily: normally, Merlin would return the signature \
of all\n\
enclosing modules, which can be very expensive.\n\n\
The result is returned as a list of:\n\
```javascript\n\
{\n\
\ 'start': position,\n\
\ 'end': position,\n\
\ 'type': string,\n\
\ // is this expression not in tail position, in tail position, or \
even a tail call?\n\
\ 'tail': ('no' | 'position' | 'call')\n\
}\n\
```"~spec:[arg"-position""<position> Position to complete"(marg_position(funpos(expr,cursor,_pos,index)->(expr,cursor,pos,index)));optional"-expression""<string> Expression to type"(Marg.param"string"(funexpr(_expr,cursor,pos,index)->(expr,cursor,pos,index)));optional"-cursor""<int> Position of the cursor inside expression"(Marg.param"int"(funcursor(expr,_cursor,pos,index)->matchint_of_stringcursorwith|cursor->(expr,cursor,pos,index)|exception_->failwith"cursor should be an integer"));optional"-index""<int> Only print type of <index>'th result"(Marg.param"int"(funindex(expr,cursor,pos,_index)->matchint_of_stringindexwith|index->(expr,cursor,pos,Someindex)|exception_->failwith"index should be an integer"))]~default:("",-1,`None,None)beginfunbuffer(expr,cursor,pos,index)->matchposwith|`None->failwith"-position <pos> is mandatory"|#Msource.positionaspos->letexpr=ifexpr=""thenNoneelseletcursor=ifcursor=-1thenString.lengthexprelsecursorinSome(expr,cursor)inrunbuffer(Query_protocol.Type_enclosing(expr,pos,index))end;command"type-expression"~doc:"Returns the type of the expression when typechecked in the \
environment around the specified position."~spec:[arg"-position""<position> Position to complete"(marg_position(funpos(expr,_pos)->(expr,pos)));arg"-expression""<string> Expression to type"(Marg.param"string"(funexpr(_expr,pos)->(expr,pos)))]~default:("",`None)beginfunbuffer(expr,pos)->matchposwith|`None->failwith"-position <pos> is mandatory"|#Msource.positionaspos->runbuffer(Query_protocol.Type_expr(expr,pos))end;(* Implemented without support from Query_protocol. This command might be
refactored if it proves useful for old protocol too. *)command"check-configuration"~spec:[]~doc:"This command checks that merlin project and options are correct.\n\
The return value has the shape:\n\
```javascript\n\
{\n\
\ 'dot_merlins': [path], // a list of string\n\
\ 'failures': [message] // a list of string\n\
}\n\
```"~default:()beginfunpipeline()->letconfig=Mpipeline.final_configpipelinein`Assoc[(* TODO Remove support for multiple configuration files
The protocol could be changed to:
'config_file': path_to_dot_merlin_or_dune
For now, if the configurator is dune, the field 'dot_merlins'
will contain the path to the dune file (or jbuild, or dune-project)
*)("dot_merlins",`List(matchMconfig.(config.merlin.config_path)with|Somepath->[Json.stringpath]|None->[]));("failures",`List(List.map~f:Json.stringMconfig.(config.merlin.failures)))]end;command"signature-help"~doc:"Returns LSP Signature Help response"~spec:[arg"-position""<position> Position of Signature Help request"(marg_position(funpos(expr,_pos)->(expr,pos)))]~default:("",`None)beginfunbuffer(_,pos)->matchposwith|`None->failwith"-position <pos> is mandatory"|#Msource.positionasposition->letsh={Query_protocol.position;trigger_kind=None;is_retrigger=false;active_signature_help=None}inrunbuffer(Query_protocol.Signature_helpsh)end;(* Used only for testing *)command"dump"~spec:[arg"-what""<source|parsetree|ppxed-source|ppxed-parsetree|typedtree|env|fullenv|browse|tokens|flags|warnings|exn|paths> \
Information to dump ()"(Marg.param"string"(funwhat_->what))]~default:""~doc:"Not for the casual user, used for debugging merlin"beginfunpipelinewhat->runpipeline(Query_protocol.Dump[`Stringwhat])end;(* Used only for testing *)command"dump-configuration"~spec:[]~default:()~doc:"Not for the casual user, used for merlin tests"beginfunpipeline()->Mconfig.dump(Mpipeline.final_configpipeline)end]