Skip to content

Commit

Permalink
vim: Type search in :MerlinSearch and update the doc
Browse files Browse the repository at this point in the history
':MerlinSearch' switches between polarity search and search by type
depending on the first character of the query, like is done in the emacs
plugin.

Documentation about the three search functions is added.
  • Loading branch information
Julow committed Dec 10, 2024
1 parent fc7cdb4 commit c742acc
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 4 deletions.
17 changes: 13 additions & 4 deletions vim/merlin/autoload/merlin.vim
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,16 @@ function! merlin#SearchByType(debug,query)
endif
endfunction

" Do a polarity search or a search by type depending on the first character of
" the query.
function! merlin#Search(debug, query)
if a:query =~ "^[-+]"
call merlin#PolaritySearch(a:debug, a:query)
else
call merlin#SearchByType(a:debug, a:query)
endif
endfunction

function! s:StopHighlight()
if exists('w:enclosing_zone') && w:enclosing_zone != -1
call matchdelete(w:enclosing_zone)
Expand Down Expand Up @@ -821,11 +831,10 @@ function! merlin#Register()
command! -buffer -nargs=0 MerlinGotoDotMerlin call merlin#GotoDotMerlin()
command! -buffer -nargs=0 MerlinEchoDotMerlin call merlin#EchoDotMerlin()

""" Polarity search
command! -buffer -complete=customlist,merlin#ExpandTypePrefix -nargs=+ MerlinSearch call merlin#PolaritySearch(0,<q-args>)

""" Search by type
""" Search
command! -buffer -complete=customlist,merlin#ExpandTypePrefix -nargs=+ MerlinSearchPolarity call merlin#PolaritySearch(0,<q-args>)
command! -buffer -complete=customlist,merlin#ExpandTypePrefix -nargs=+ MerlinSearchType call merlin#SearchByType(0,<q-args>)
command! -buffer -complete=customlist,merlin#ExpandTypePrefix -nargs=+ MerlinSearch call merlin#Search(0,<q-args>)

""" debug --------------------------------------------------------------------
command! -buffer -nargs=0 MerlinDebugLastCommands MerlinPy merlin.vim_last_commands()
Expand Down
38 changes: 38 additions & 0 deletions vim/merlin/doc/merlin.txt
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,44 @@ Act either as *:py* or *:py3* depending on the version of python is used
by the vim plugin.
This is only useful if you want to write custom merlin extensions.

:MerlinSearch *:MerlinSearch*

Act either as :MerlinSearchPolarity or :MerlinSearchType depending on the first
character of the query. If the query starts with '-' or '+', then
:MerlinSearchPolarity is used, otherwise, :MerlinSearchType is used.

>
:MerlinSearch -int +string
:MerlinSearch int -> string
<

:MerlinSearchPolarity *:MerlinSearchPolarity*

Search for values in the current scope that have a type matching the query.
The results are displayed in a completion menu.

The query language is simply a list of path identifiers prefixed by `+` or `-`,
e.g. `-int`, `-int +string`, `-Hashtbl.t +int`.

`-` is interpreted as "consuming" and `+` as "producing": `-int +string` looks
for functions consuming an `int` and producing a `string`.

>
:MerlinSearchPolarity -int +string
<

:MerlinSearchType *:MerlinSearchType*

Works similarly to :MerlinSearchPolarity but uses a different query language.
The results are displayed in a completion menu.

The query language is a list of type constructors separated by '->'.
Type parameters and functions are allowed: `('a -> bool) -> 'a list -> bool`.

>
:MerlinSearchType int -> string
<

==============================================================================
OPTIONS *merlin-options*

Expand Down

0 comments on commit c742acc

Please sign in to comment.