When writing inside a pair of parentheses the highlighting for the closing parenthesis shows up in a random letter instead:

I'm not sure how I could give you a more minimal example than what I gave you at the other issue. This is what I have in my .vimrc:
call plug#begin('~/.vim/bundle')
Plug 'Shougo/neocomplete.vim'
Plug 'lervag/vimtex'
call plug#end()
let g:tex_flavor = "latex"
let g:neocomplete#enable_at_startup = 1
Then I just open a new buffer with a .tex file, write a word a few times for neocomplete to pick it up and try writing it inside a pair of parentheses.
Ok, thanks. I've reproduced it and will look into it.
Strange. It seems this problem is not new. However, before I started to use matchaddpos, there would be no highlighting because matchadd uses a regex that would no longer match anything.
The issue is that neocomplete opens the completion menu, and while this menu is open, newly inputted text seems to be unavailable. That is, functions such as getline(), searchpos(), etc, will only see the text inserted before the completion menu is displayed.
Ok, I am not able to find a solution to this. However, I found a workaround:
let g:neocomplete#enable_refresh_always = 1
Perhaps @Shougo knows another way to fix this/avoid this? I am not even able to detect whether the completion menu is open (pumvisible() always returns 0, even if the menu is open).
Uhm, weird. But, well, it seems to be working fine with that option, so I'm happy.
Thanks again for your great work here. You should add a paypal thing or something for users to make donations. :)
Yes, I agree, it's a little bit weird. Unfortunately, I think there is nothing more I can do.
I'm very happy to hear you like the plugin. As I'm sure you understand, I'm not doing this for the money. It's fun in itself, and it is even more fun when other people enjoy the work. However, if people like it so much they want to donate, I would of course be even more happy. So I'll add a Paypal donate button to the readme file as you suggest. :)
Just a little update: even with enable_refresh_always set this problem still happens sometimes:

It happens when you select one of the matches from the pop up menu. You type half the word and then use <tab> or whatever key you use to complete the word. The highlighting will stick to where the parenthesis was.
With other filetypes the highlighting is just gone when the pop up menu shows up, which is better, I think, but I don't know how it works, since you said pumvisible() always returns 0. But if I open a new buffer without any filetype and start typing I get this:

And then when the pop up menu shows up the highlighting is gone:

I don't know how addmatchpos() works… how do you keep the position updated? But there could be a way to only highlight if there are two matching parentheses. If when the pop up is visible you can't "see" the other parenthesis, then there wouldn't be any highlighting. I suppose this is what happens in the example above.
This is not a big deal, though, and the enable_refresh_always option is a big help already. I just thought I'd mention it for the record.
Ok, I've now updated with a new attempt. Instead of matchaddpos I now use matchadd, which should be available for most people. This becomes similar to the original version, however, I now use more complicated matching. In particular, I ensure that the delimiters only match if both delimiters are found. This seems to work well for me. Let me know what you think.
I had let g:neocomplete#enable_refresh_always = 1 in my .vimrc and with the new update the pop up menu wasn't even showing up except for some weird flashes. But now I removed it and it seems like everything is working perfectly. 🎉
I don't know if that option could be necessary for some users, but since I don't need it it's all good for me. And I guess that must be a problem with neocomplete anyway.
Thanks again for taking the time to look into this!
Strange. I have enable_refresh_always on, but the completion menu shows as expected here. In any case, I'm happy to hear that you're happy with the latest version!
@lervag I've been using mucomplete instead of neocomplete and now this problem came back. :(
Which is weird, since you said that now the delimiters only match if both delimiters are found.
mucomplete doesn't do anything besides calling Vim's own completion methods, and indeed, the problem can reproduced with vimtex alone. I can reproduce it with just the following in my .vimrc:
call plug#begin('~/.vim/bundle')
Plug 'lervag/vimtex'
call plug#end()
let g:tex_flavor = "latex"
set completeopt+=noselect
set completeopt+=menuone
Then edit a new .tex file, add a couple of braces and type "vimtex" between the braces a couple of times. On the third time, just type "vim", do <C-X><C-N> and then type "tex". And voilà :

Yes, I can reproduce this. However, I have the same problem as described early in this thread. I think I understand it better now, though: When the completion menu is present, the CursorMovedI event is not fired when he popupmenu is open, see :h CursorMovedI:
*CursorMovedI*
CursorMovedI After the cursor was moved in Insert mode.
Not triggered when the popup menu is visible.
Otherwise the same as CursorMoved.
Thus: It seems it is near impossible to fix this problem.
But...
I've implemented a hack that uses the timer_start() function which should be available in Vim 8. It seems to work quite well, actually. Let me know what you think.
Seems perfect so far!
I was going to suggest updating the highlighting with InsertCharPre or TextChangedI + pumvisible() besides CursorMovedI, but this is already great. Thanks! :)
Great, happy to hear it works :)
I've updated to use TextChangedP when possible, since this should improve the latency somewhat (I think) and avoid running the callback loop in the background when idle.
Most helpful comment
I've updated to use
TextChangedPwhen possible, since this should improve the latency somewhat (I think) and avoid running the callback loop in the background when idle.