roxma / nvim-completion-manager

:warning: PLEASE USE https://github.com/ncm2/ncm2 INSTEAD
MIT License
917 stars 49 forks source link

PHP language server causes regexp errors #100

Closed weirdan closed 7 years ago

weirdan commented 7 years ago

I was trying to get php completions working, and stumbled across this error in the debug log:

2017-07-15 06:03:39,140 [ERROR @ cm_core.py:cm_refresh:351] 29193 - cm_refresh exception: bad escape (end of pattern) at position 2                                                           
Traceback (most recent call last):                                                                                                                                                            
  File "/home/weirdan/.config/nvim/bundle/nvim-completion-manager/pythonx/cm_core.py", line 313, in cm_refresh                                                                                
    if not self._check_refresh_patterns(info,ctx,force):                                                                                                                                      
  File "/home/weirdan/.config/nvim/bundle/nvim-completion-manager/pythonx/cm_core.py", line 443, in _check_refresh_patterns                                                                   
    matched = re.search(pattern, typed)                                                                                                                                                       
  File "/usr/lib/python3.5/re.py", line 173, in search                                                                                                                                        
    return _compile(pattern, flags).search(string)                                                                                                                                            
  File "/usr/lib/python3.5/re.py", line 293, in _compile                                                                                                                                      
    p = sre_compile.compile(pattern, flags)                                                                                                                                                   
  File "/usr/lib/python3.5/sre_compile.py", line 536, in compile                                                                                                                              
    p = sre_parse.parse(p, flags)                                                                                                                                                             
  File "/usr/lib/python3.5/sre_parse.py", line 829, in parse                                                                                                                                  
    p = _parse_sub(source, pattern, 0)                                                                                                                                                        
  File "/usr/lib/python3.5/sre_parse.py", line 437, in _parse_sub                                                                                                                             
    itemsappend(_parse(source, state, nested + 1))                                                                                                                                            
  File "/usr/lib/python3.5/sre_parse.py", line 510, in _parse                                                                                                                                 
    sourceget()                                                                                                                                                                               
  File "/usr/lib/python3.5/sre_parse.py", line 249, in get                                                                                                                                    
    self.__next()                                                                                                                                                                             
  File "/usr/lib/python3.5/sre_parse.py", line 239, in __next                                                                                                                                 
    self.string, len(self.string) - 1) from None                                                                                                                                              
sre_constants.error: bad escape (end of pattern) at position 2                  
  1. PHP language server reports the following triggerCharacters: "triggerCharacters":["$",">"]
  2. LanguageClient-neovim registers them as cm_refresh_patterns: https://github.com/autozimu/LanguageClient-neovim/blob/90e31840dd70863c9130df2df4dd7e254fd66d3f/rplugin/python3/LanguageClient/LanguageClient.py#L326 , resulting in the following regexp: \$$
  3. nvim-completion-manager adds .* and strips trailing dollar signs here: https://github.com/roxma/nvim-completion-manager/blob/5c50c0699a2e0b63216bb9e3d22a5774d46ebe66/pythonx/cm_core.py#L439 , resulting in the following invalid regexp: .*\ (regexp ends with escape character, which should never happen)

This could be fixed on the LanguageClient-neovim's side by wrapping the escaped trigger character into parenthesis, or dealt with in nvim-completion-manager

/cc @autozimu

roxma commented 7 years ago

Sorry for the late reply. (I've been busy babysitting my new child)

This bug was brought by me. I'll fix it when I have some free time.

weirdan commented 7 years ago

No problem, I know how it is. Children are a lot of fun. In retrospective, at least :smile: