https://github.com/vim/vim/pull/6947
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.![]()
Merging #6947 into master will increase coverage by
0.01%.
The diff coverage is100.00%.
@@ Coverage Diff @@ ## master #6947 +/- ## ========================================== + Coverage 88.55% 88.57% +0.01% ========================================== Files 148 148 Lines 161341 161366 +25 ========================================== + Hits 142882 142925 +43 + Misses 18459 18441 -18
| Impacted Files | Coverage Δ | |
|---|---|---|
| src/evalfunc.c | 96.26% <ø> (ø) |
|
| src/search.c | 91.96% <100.00%> (+0.09%) |
⬆️ |
| src/netbeans.c | 76.29% <0.00%> (-0.30%) |
⬇️ |
| src/message.c | 88.54% <0.00%> (+0.04%) |
⬆️ |
| src/channel.c | 89.92% <0.00%> (+0.05%) |
⬆️ |
| src/gui_gtk_x11.c | 58.73% <0.00%> (+0.09%) |
⬆️ |
| src/sign.c | 94.94% <0.00%> (+0.17%) |
⬆️ |
| src/gui_gtk.c | 31.67% <0.00%> (+0.27%) |
⬆️ |
| src/gui.c | 63.45% <0.00%> (+0.69%) |
⬆️ |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing data
Powered by Codecov. Last update b806aa5...68f776f. Read the comment docs.
@prabirshrestha commented on this pull request.
> @@ -7309,12 +7311,24 @@ matchend({expr}, {pat} [, {start} [, {count}]]) *matchend()*
GetText()->matchend('word')
-matchfuzzy({list}, {str}) *matchfuzzy()*
- Returns a list with all the strings in {list} that fuzzy
- match {str}. The strings in the returned list are sorted
- based on the matching score. {str} is treated as a literal
- string and regular expression matching is NOT supported.
- The maximum supported {str} length is 256.
+matchfuzzy({list}, {str} [, {key}])
based on my comment here might be good to not support key but instead support expression with v:val which can be optimized to extract key. #6932 (comment)
@prabirshrestha approved this pull request.
@prabirshrestha commented on this pull request.
In src/testdir/test_functions.vim:
> + call assert_fails("let x = matchfuzzy(l, 'cam', 'random')", 'E715:')
+ call assert_equal([], matchfuzzy(l, 'day', {'text_cb' : {v -> []}}))
+ call assert_equal([], matchfuzzy(l, 'day', {'text_cb' : {v -> 1}}))
+ call assert_fails("let x = matchfuzzy(l, 'day', {'text_cb' : {a, b -> 1}})", 'E119:')
+ call assert_equal([], matchfuzzy(l, 'cam'))
+ call assert_fails("let x = matchfuzzy(l, 'cam', {'text_cb' : []})", 'E921:')
+ call assert_fails("let x = matchfuzzy(l, 'foo', {'key' : []})", 'E730:')
+ call assert_fails("let x = matchfuzzy(l, 'cam', test_null_dict())", 'E715:')
+ call assert_fails("let x = matchfuzzy(l, 'foo', {'key' : test_null_string()})", 'E475:')
+ call assert_fails("let x = matchfuzzy(l, 'foo', {'text_cb' : test_null_function()})", 'E475:')
+
+ let l = [{'id' : 5, 'name' : 'foo'}, {'id' : 6, 'name' : []}, {'id' : 7}]
+ call assert_fails("let x = matchfuzzy(l, 'foo', {'key' : 'name'})", 'E730:')
+
+ " Test for the fuzzymatchpos() function
+ call assert_equal([['curl', 'world'], [[2,3], [2,3]]], matchfuzzypos(['world', 'curl'], 'rl'))
missing tests for key and text_cb for matchfuzzypost
In src/testdir/test_functions.vim:
> + call assert_fails("let x = matchfuzzy(l, 'cam', 'random')", 'E715:')
+ call assert_equal([], matchfuzzy(l, 'day', {'text_cb' : {v -> []}}))
+ call assert_equal([], matchfuzzy(l, 'day', {'text_cb' : {v -> 1}}))
+ call assert_fails("let x = matchfuzzy(l, 'day', {'text_cb' : {a, b -> 1}})", 'E119:')
+ call assert_equal([], matchfuzzy(l, 'cam'))
+ call assert_fails("let x = matchfuzzy(l, 'cam', {'text_cb' : []})", 'E921:')
+ call assert_fails("let x = matchfuzzy(l, 'foo', {'key' : []})", 'E730:')
+ call assert_fails("let x = matchfuzzy(l, 'cam', test_null_dict())", 'E715:')
+ call assert_fails("let x = matchfuzzy(l, 'foo', {'key' : test_null_string()})", 'E475:')
+ call assert_fails("let x = matchfuzzy(l, 'foo', {'text_cb' : test_null_function()})", 'E475:')
+
+ let l = [{'id' : 5, 'name' : 'foo'}, {'id' : 6, 'name' : []}, {'id' : 7}]
+ call assert_fails("let x = matchfuzzy(l, 'foo', {'key' : 'name'})", 'E730:')
+
+ " Test for the fuzzymatchpos() function
+ call assert_equal([['curl', 'world'], [[2,3], [2,3]]], matchfuzzypos(['world', 'curl'], 'rl'))
can we also have a test case for multiple matches in the same item.
matchfuzzypos(['hello world hello world', 'hello', 'world]`, 'hello')
In src/testdir/test_functions.vim:
> + call assert_equal([], matchfuzzy(l, 'day', {'text_cb' : {v -> []}}))
+ call assert_equal([], matchfuzzy(l, 'day', {'text_cb' : {v -> 1}}))
+ call assert_fails("let x = matchfuzzy(l, 'day', {'text_cb' : {a, b -> 1}})", 'E119:')
+ call assert_equal([], matchfuzzy(l, 'cam'))
+ call assert_fails("let x = matchfuzzy(l, 'cam', {'text_cb' : []})", 'E921:')
+ call assert_fails("let x = matchfuzzy(l, 'foo', {'key' : []})", 'E730:')
+ call assert_fails("let x = matchfuzzy(l, 'cam', test_null_dict())", 'E715:')
+ call assert_fails("let x = matchfuzzy(l, 'foo', {'key' : test_null_string()})", 'E475:')
+ call assert_fails("let x = matchfuzzy(l, 'foo', {'text_cb' : test_null_function()})", 'E475:')
+
+ let l = [{'id' : 5, 'name' : 'foo'}, {'id' : 6, 'name' : []}, {'id' : 7}]
+ call assert_fails("let x = matchfuzzy(l, 'foo', {'key' : 'name'})", 'E730:')
+endfunc
+
+" Test for the fuzzymatchpos() function
+func Test_matchfuzzypos()
missing tests for empty array. matchfuzzypos([], 'foo')
@prabirshrestha commented on this pull request.
> :echo v:oldfiles->matchfuzzy("test")
< results in a list of file names fuzzy matching "test". >
:let l = readfile("buffer.c")->matchfuzzy("str")
< results in a list of lines in "buffer.c" fuzzy matching "str".
+matchfuzzypos({list}, {str} [, {dict}]) *matchfuzzypos()*
add example for dict or might be add a comment to refer to matchfuzzy dict option.
@prabirshrestha requested changes on this pull request.
added few comments.
In src/testdir/test_functions.vim:
> + call assert_fails("let x = matchfuzzy(l, 'day', {'text_cb' : {a, b -> 1}})", 'E119:')
+ call assert_equal([], matchfuzzy(l, 'cam'))
+ call assert_fails("let x = matchfuzzy(l, 'cam', {'text_cb' : []})", 'E921:')
+ call assert_fails("let x = matchfuzzy(l, 'foo', {'key' : []})", 'E730:')
+ call assert_fails("let x = matchfuzzy(l, 'cam', test_null_dict())", 'E715:')
+ call assert_fails("let x = matchfuzzy(l, 'foo', {'key' : test_null_string()})", 'E475:')
+ call assert_fails("let x = matchfuzzy(l, 'foo', {'text_cb' : test_null_function()})", 'E475:')
+
+ let l = [{'id' : 5, 'name' : 'foo'}, {'id' : 6, 'name' : []}, {'id' : 7}]
+ call assert_fails("let x = matchfuzzy(l, 'foo', {'key' : 'name'})", 'E730:')
+endfunc
+
+" Test for the fuzzymatchpos() function
+func Test_matchfuzzypos()
+ call assert_equal([['curl', 'world'], [[2,3], [2,3]]], matchfuzzypos(['world', 'curl'], 'rl'))
+ call assert_equal([['curl', 'world'], [[2,3], [2,3]]], matchfuzzypos(['world', 'one', 'curl'], 'rl'))
shouldn't this response be this instead? so that if there is multiple highlights it can still be represented correctly?
[ [ "curl", "world", "curl world"], [ [ [2,3] ], [ [2,3 ] ], [ [2,3], [7,8] ] ] ]
@yegappan any plans to return multiple highlights for an item? Is it currently the limitation in the library?
Would be good if it supported it even if the library didnt support it so in future can update the library without updating the public api.
—
You are receiving this because you commented.
@yegappan any plans to return multiple highlights for an item? Is it currently the limitation in the library?
Would be good if it supported it even if the library didnt support it so in future can update the library without updating the public api.
It is very common if you are trying to create a fuzzy matching for files.
Here is a real example where I'm searching for sys\dri\hosts. In this case I'm actually interested in hosts file and not sys. this means hosts needs to be highlighted.
In projects I can see this using as controller/feature/featuresA/component.tsx, controller/features/featuresA/service.tsx I might want to use featureA/service. which means I want both to highlight.
—
You are receiving this because you commented.
It is very common if you are trying to create a fuzzy matching for files.
Here is a real example where I'm searching for
sys\dri\hosts. In this case I'm actually interested inhostsfile and notsys. this meanshostsneeds to be highlighted.
—
You are receiving this because you are subscribed to this thread.
If I want to 100 matches with each items having 2 highlights and only want to highlight 39:49 items do I need to loop through all the highlights which is 200 iterations or I can just ask for items[39:49] and iterate only 20 higlights?
I'm looking something like ios api for virtualization.
—
You are receiving this because you commented.
If I want to 100 matches with each items having 2 highlights and only want to highlight
39:49items do I need to loop through all the highlights which is 200 iterations or I can just ask foritems[39:49]and iterate only 20 higlights?
—
You are receiving this because you are subscribed to this thread.
Now it makes sense. I was looking for range but seems like you are giving character positions so should be possible to do it.
For this text System32\\drivers\\mausbhost.sys when I search for Sys\dri\hosts I get 0, 1, 2, 8, 9, 10, 11, 16, 22, 23, 24, 25, 27. If I want to use prop_add I need to calculate the length on my own as I most likely want to avoid adding prop_add for each character.
let matches = [ 0, 1, 2, 8, 9, 10, 11, 16, 22, 23, 24, 25, 27 ] call prop_add(lnum, 0, { 'length': 3 }) call prop_add(lnum, 8, { 'length': 4 }) call prop_add(lnum, 16, { 'length': 1 }) call prop_add(lnum, 22, { 'length': 4 }) call prop_add(lnum, 27, { 'length': 1 })
might be what I need now is another function to convert it to range.
let matches = [ 0, 1, 2, 8, 9, 10, 11, 16, 22, 23, 24, 25, 27 ] let matchrange = matchpos2range(matches) " matchrange = [[0, 3], [8, 4], [16, 1], [22, 4], [27, 1]] for range in matchrange call prop_add(lnum, range[0], { 'length': range[1] }) endfor
—
You are receiving this because you commented.
Here's a very simple command that I used for testing matchaddpos():
if prop_type_get('test')->empty() call prop_type_add('test', {'highlight': 'Title'}) endif function s:fuzzyfind(bang, mod, ...) abort if a:0 != 2 return endif const files = systemlist('cd ' .. a:1 .. '; find -type f | sed "s/^\.\///"') const matches = matchfuzzypos(files, a:2) const info = printf('%s [dir: %s]', a:2, fnamemodify(a:1, ':~:.')) if empty(matches) return endif silent execute a:mod 'new' fnameescape(info) setlocal buftype=nofile noswapfile bufhidden=wipe call setline(1, matches[0]) if a:bang for i in len(matches[1])->range()[: winheight(0) - 1] call len(matches[1][i]) \ ->range() \ ->map({_,j -> \ prop_add(i + 1, matches[1][i][j] + 1, { \ 'length': 1, \ 'type': 'test', \ 'bufnr': bufnr('%') \ }) \ }) endfor endif setlocal nomodifiable endfunction command -nargs=+ -bang -complete=dir Fuzzy call s:fuzzyfind(<bang>0, <q-mods>, <f-args>)