Hi,
On Tue, Jul 19, 2016 at 8:47 AM, Yegappan Lakshmanan
<[email protected]> wrote:
> Hi,
>
> On Mon, Jul 18, 2016 at 5:21 PM, Yegappan Lakshmanan
> <[email protected]> wrote:
>> Hi,
>>
>> When a buffer is modified (lines are added/removed), the line numbers
>> in the quickfix list are updated to reflect the new line numbers
>> using the qf_mark_adjust() function.
>>
>> This functionality is broken with the recent changes made to optimize
>> this update (curbuf->b_has_qf_entry). This happens when a quickfix list
>> and an empty location list are used. The qf_mark_adjust() function sets
>> the b_has_qf_entry flag to FALSE if a quickfix entry is not found. But
>> this function is called for both a quickfix list and the location list
>> to adjust the line numbers. If any one of the list is empty, then this
>> flag will be set to FALSE. After this, further modifications to the
>> buffer will not update the line numbers. Should we use two separate
>> flags (one for the quickfix list and the other for the location list?)
>
The attached patch fixes this problem. I have also updated the tests
to detect this problem.
- Yegappan
>>
>> I created the following test function to illustrate the problem:
>>
>> function! Test_Qf_Mark_Adjust()
>> let l = []
>> for i in range(1, 20)
>> call add(l, 'Line' . i)
>> endfor
>> call writefile(l, 'Xqftestfile')
>>
>> call setloclist(0, [])
>>
>> edit Xqftestfile
>>
>> cgetexpr ['Xqftestfile:5:Line5',
>> \ 'Xqftestfile:10:Line10',
>> \ 'Xqftestfile:15:Line15',
>> \ 'Xqftestfile:20:Line20']
>>
>> 6,14delete
>> call append(6, ['Buffer', 'Window'])
>>
>> let l = getqflist()
>>
>> call assert_equal(5, l[0].lnum)
>> call assert_equal(6, l[2].lnum)
>> call assert_equal(13, l[3].lnum)
>>
>> enew!
>> call delete('Xqftestfile')
>> endfunction
>>
>
> The above test function is already part of test_quickfix.vim (Xadjust_qflnum)
> except for the line that sets the empty location list.
>
> The current test is not catching this problem because the Test_adjust_lnum()
> is the first test that gets executed. When this test executes there are no
> previous location lists. I ran into this problem when I added a test that
> created an empty location list and executed before Test_adjust_lnum().
>
> - 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 fecc2c9..98d3200 100644
--- a/src/quickfix.c
+++ b/src/quickfix.c
@@ -1408,7 +1408,8 @@ qf_add_entry(
qfp->qf_fnum = bufnum;
if (buf != NULL)
- buf->b_has_qf_entry = TRUE;
+ buf->b_has_qf_entry |=
+ (qi == &ql_info) ? BUF_HAS_QF_ENTRY : BUF_HAS_LL_ENTRY;
}
else
qfp->qf_fnum = qf_get_fnum(qi, dir, fname);
@@ -1680,7 +1681,8 @@ qf_get_fnum(qf_info_T *qi, char_u *directory, char_u
*fname)
if (buf == NULL)
return 0;
- buf->b_has_qf_entry = TRUE;
+ buf->b_has_qf_entry =
+ (qi == &ql_info) ? BUF_HAS_QF_ENTRY : BUF_HAS_LL_ENTRY;
return buf->b_fnum;
}
@@ -2729,7 +2731,8 @@ qf_mark_adjust(
qf_info_T *qi = &ql_info;
int found_one = FALSE;
- if (!curbuf->b_has_qf_entry)
+ if ((wp == NULL && !(curbuf->b_has_qf_entry & BUF_HAS_QF_ENTRY)) ||
+ (wp != NULL && !(curbuf->b_has_qf_entry & BUF_HAS_LL_ENTRY)))
return;
if (wp != NULL)
{
@@ -2758,7 +2761,8 @@ qf_mark_adjust(
}
if (!found_one)
- curbuf->b_has_qf_entry = FALSE;
+ curbuf->b_has_qf_entry &=
+ (wp == NULL) ? ~BUF_HAS_QF_ENTRY : ~BUF_HAS_LL_ENTRY;
}
/*
diff --git a/src/structs.h b/src/structs.h
index 00a8e03..191fa1f 100644
--- a/src/structs.h
+++ b/src/structs.h
@@ -1906,6 +1906,8 @@ struct file_buffer
#ifdef FEAT_QUICKFIX
char_u *b_p_bh; /* 'bufhidden' */
char_u *b_p_bt; /* 'buftype' */
+#define BUF_HAS_QF_ENTRY 1
+#define BUF_HAS_LL_ENTRY 2
int b_has_qf_entry;
#endif
int b_p_bl; /* 'buflisted' */
diff --git a/src/testdir/test_quickfix.vim b/src/testdir/test_quickfix.vim
index 83f4d0c..e79315b 100644
--- a/src/testdir/test_quickfix.vim
+++ b/src/testdir/test_quickfix.vim
@@ -1341,13 +1341,14 @@ function! Xadjust_qflnum(cchar)
enew | only
- call s:create_test_file('Xqftestfile')
- edit Xqftestfile
+ let fname = 'Xqftestfile' . a:cchar
+ call s:create_test_file(fname)
+ exe 'edit ' . fname
- Xgetexpr ['Xqftestfile:5:Line5',
- \ 'Xqftestfile:10:Line10',
- \ 'Xqftestfile:15:Line15',
- \ 'Xqftestfile:20:Line20']
+ Xgetexpr [fname . ':5:Line5',
+ \ fname . ':10:Line10',
+ \ fname . ':15:Line15',
+ \ fname . ':20:Line20']
6,14delete
call append(6, ['Buffer', 'Window'])
@@ -1359,11 +1360,13 @@ function! Xadjust_qflnum(cchar)
call assert_equal(13, l[3].lnum)
enew!
- call delete('Xqftestfile')
+ call delete(fname)
endfunction
function! Test_adjust_lnum()
+ call setloclist(0, [])
call Xadjust_qflnum('c')
+ call setqflist([])
call Xadjust_qflnum('l')
endfunction