Hi,
On Thu, Aug 31, 2017 at 9:02 AM, LCD 47 <[email protected]> wrote:
> On 27 August 2017, Bram Moolenaar <[email protected]> wrote:
>>
>> Patch 8.0.1006
>> Problem: Cannot parse text with 'erroformat' without changing a quickfix
>> list.
>> Solution: Add the "text" argument to getqflist(). (Yegappan Lakshmanan)
>> Files: runtime/doc/eval.txt, src/evalfunc.c, src/proto/quickfix.pro,
>> src/quickfix.c, src/testdir/test_quickfix.vim
>
> It's awesome that this feature has been added, however the interface
> is confusing:
>
> [...]
>> + text use 'errorformat' to extract items from the
>> + text and return the resulting entries. The
>> + value can be a string with one line or a list
>> + with multiple lines. The current quickfix list
>> + is not modified.
> [...]
>> + When 'text' is specified, all the other items are ignored. The
>> + returned dictionary contains the entry 'items' with the list
>> + of entries.
>> In case of error processing {what}, an empty dictionary is
>> returned.
> [...]
>
> What is the point in reusing getqflist() for this instead of writing
> a new function? It makes no sense: when "text" is used the other
> arguments are silently ignored, and the {"items": ...} around the qflist
> is useless. Why not a function getexpr(list), that returns a list?
>
It made sense to use the getqflist() function to either return an existing
list from the quickfix stack or a new list from the supplied text. It also
avoids adding many functions for dealing with the quickfix lists.
>
> The return value is inconsistent: getqflist("text": []) returns {}
> rather than {"items": []}, which is indistinguishable from an error.
>
The attached patch fixes this problem.
>
> The fact that unknown keys in the input dictionary are silently
> ignored means among other things that there is no way to test for the
> new feature. Compare to:
>
You can check for a particular patch [has("patch-8.0.1006")].
This applies to any function that takes a dictionary argument. As support
for new keys are added to the dictionary, there is no clean way to check
for the new feature.
>
> if exists("*getexpr")
> let qflist = getexpr(['some input'])
> else
> " do it the old way
> endif
>
> or
>
> try
> let qflist = getexpr(['some input'])
> catch /\m^Vim\%((\a\+)\)\=:E117/
> " do it the old way
> endif
>
> Finally, there's also a confusion about "text" being a key on
> input, and also a key with a completely different meaning on output.
>
In my original patch, the new key was called 'expr'. As only text values
are accepted for this key, Bram renamed it to 'text' when he merged
the patch.
Regards,
Yegappan
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.
diff --git a/src/quickfix.c b/src/quickfix.c
index 8277b937e..ffe59b349 100644
--- a/src/quickfix.c
+++ b/src/quickfix.c
@@ -4653,6 +4653,10 @@ qf_get_list_from_text(dictitem_T *di, dict_T *retdict)
|| (di->di_tv.v_type == VAR_LIST
&& di->di_tv.vval.v_list != NULL))
{
+ list_T *l = list_alloc();
+ if (l == NULL)
+ return FAIL;
+
qi = (qf_info_T *)alloc((unsigned)sizeof(qf_info_T));
if (qi != NULL)
{
@@ -4662,17 +4666,13 @@ qf_get_list_from_text(dictitem_T *di, dict_T *retdict)
if (qf_init_ext(qi, 0, NULL, NULL, &di->di_tv, p_efm,
TRUE, (linenr_T)0, (linenr_T)0, NULL, NULL) > 0)
{
- list_T *l = list_alloc();
- if (l != NULL)
- {
- (void)get_errorlist(qi, NULL, 0, l);
- dict_add_list(retdict, "items", l);
- status = OK;
- }
+ (void)get_errorlist(qi, NULL, 0, l);
qf_free(qi, 0);
}
free(qi);
}
+ dict_add_list(retdict, "items", l);
+ status = OK;
}
return status;
diff --git a/src/testdir/test_quickfix.vim b/src/testdir/test_quickfix.vim
index 076d583fd..d6b65e339 100644
--- a/src/testdir/test_quickfix.vim
+++ b/src/testdir/test_quickfix.vim
@@ -2536,7 +2536,7 @@ func XgetListFromText(cchar)
call assert_equal(30, l[1].lnum)
call assert_equal({}, g:Xgetlist({'text' : 10}))
- call assert_equal({}, g:Xgetlist({'text' : []}))
+ call assert_equal([], g:Xgetlist({'text' : []}).items)
" Make sure that the quickfix stack is not modified
call assert_equal(0, g:Xgetlist({'nr' : '$'}).nr)