Undefined variable l:res #158

Closed
ivan-cukic opened this Issue Jun 19, 2012 · 14 comments

Projects

None yet

5 participants

@ivan-cukic

When using libclang 3.1, the following error message appears:
"Undefined variable l:res" in 520 function! ClangComplete(findstart, base)

The issue is raised because the line doesn't work for some reason (will investigate further why):
556 python vim.command('let l:res = ' + str(getCurrentCompletions(vim.eval('a:base'))))

This removes the error, but completion doesn't work:
554 if g:clang_use_library == 1
+555 let l:res = []
556 python vim.command('let l:res = ' + str(getCurrentCompletions(vim.eval('a:base'))))
557 else
558 let l:res = s:ClangCompleteBinary(a:base)
559 endif

Owner
Rip-Rip commented Jun 21, 2012

Did you try with the latest vim version? Because it works for me with libclang 3.1 and vim 7.3.547

Yes, vim 7.3.547 here as well. Might be a problem in 64bit version?

Unfortunately, I haven't had the time to dive deeper into the issue. Hoping I'll be able to do it soon :/

I use the latest clang_complete from git (cloned yesterday). I compiled the latest llvm/clang (svn, co yesterday) from source, and let g:clang_library_path="/usr/local/lib64", then I let g:clang_use_library=1. After trying completion of a struct member, I get these errors:

Error detected while processing function ClangComplete:                                                                        
line   35:                                                                                                                     
Traceback (most recent call last):                                                                                             
Press ENTER or type command to continue                                                                                        
Error detected while processing function ClangComplete:                                                                        
line   35:                                                                                                                     
  File "<string>", line 1, in <module>                                                                                         
Press ENTER or type command to continue                                                                                        
Error detected while processing function ClangComplete:                                                                        
line   35:                                                                                                                     
NameError: name 'vim' is not defined                                                                                           
Press ENTER or type command to continue                                                                                        
Error detected while processing function ClangComplete:                                                                        
line   40:                                                                                                                     
E121: Undefined variable: l:res                                                                                                
Press ENTER or type command to continue                                                                                        
Error detected while processing function ClangComplete:                                                                        
line   40:                                                                                                                     
E15: Invalid expression: l:res                                                                                                 
Press ENTER or type command to continue                                                                                        
Error detected while processing function ClangComplete:                                                                        
line   57:                                                                                                                     
E121: Undefined variable: l:res                                                                                                
Press ENTER or type command to continue                                                                                        
Error detected while processing function ClangComplete:                                                                        
line   57:                                                                                                                     
E15: Invalid expression: l:res

Vim version is 7.3.322

Do you have any hints for me what could be going wrong when trying to use the library?

Chewie commented Aug 7, 2012

did you set g:clang_use_library in your vimrc, or did you run it manually once your file was loaded?
I had the same problem, and after some digging, turns out this was the problem :
The use_library feature relies on a python script being loaded. This is done by the initialization function of clang_complete, but only if g:clang_use_library is set to 1. After that this function is marked as being already called and doesn't run again, so if you set g:clang_use_library afterwards, the feature will fail because the python script hasn't been loaded.

Perhaps it would be good to allow the reloading of the clang_complete environment, or at least document that behavior.

Same problem.
Vim 7.3.629
Clang 3.1-8
x86_64

I'm not certain I understand Chewie's comment. I tried with and without setting g:clang_use_library to 1 in vimrc, both before and after loading clang_complete ... no love

Edit: incidentally, clang-complete is working (and is super-awesome), error is just annoying

Owner
Rip-Rip commented Feb 3, 2013

@blak3mill3r: can you copy/paste the backtrace?

@Rip-Rip: Sorry, I may not have read the OP carefully enough. I googled "Undefined variable l:res" because after installing clang_complete and opening a new cpp file, I got the following errors in vim:

    "foo.cpp" [New File]
    Error detected while processing function <SNR>21_ClangCompleteInit..<SNR>21_initClangCompletePython:
    line   18:
    E121: Undefined variable: l:res
    E15: Invalid expression: l:res == 0
    template style is 'CPP'
    15 lines indented 

Completion was working out of the box anyway. Incidentally, it seems to be working fine even with the following lines commented out:
clang_complete.vim line 276

    if l:res == 0
      return 0
    endif
Owner
Rip-Rip commented Feb 3, 2013

Usually when the 'l:res' error happens, this indicates an error in python code. Did you see any error in python?

Okay, so ... no I don't see a python stacktrace, but on further investigation, it seems that the embedded python interpreter's STDERR/STDOUT are going nowhere obvious (in contrast to what :help python tells me, that they should show in vim messages). If I try these ex commands (in a vim started with no .vimrc)

:python raise Exception("nowhere")
:python print 1

I don't see anything in vim messages.

Edit: I did build vim with --enable-pythoninterp=yes, and configure output seems to indicate that python2.7 was detected etc ...

... clang_complete depends on vim having a working embedded python interpreter, yes?

cause completion is working...

I'm confused

Okay, I did a little more poking around. This is odd, but I put this in .vimrc

:py f=open("/home/blake/vimpythonout", 'a+')
:py sys.stdout = f
:py sys.stderr = f

Then open a .cpp file, and after the plugin has loaded I do a

:py sys.stderr.flush()

and voila, a backtrace:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/blake/.vim.cpp/bundle/clang_complete/plugin/libclang.py", line 48, in initClangComplete
    Config.set_compatibility_check(False)
  File "/home/blake/.vim.cpp/bundle/vundle/plugin/clang/cindex.py", line 3126, in set_compatibility_check
    raise Exception("compatibility_check must be set before before " \
Exception: compatibility_check must be set before before using any other functionalities in libclang.

HTH

Owner
Rip-Rip commented Feb 4, 2013

Did you check that you only have one clang_complete loaded? I already saw that error when having in bundle/ and the other in plugin/. That would also explain why completion is still working.

Yes, that was it! Thanks for your help. I don't understand how I managed to do this, this is a fresh ~/.vim/ folder, I installed clang_complete with vundle but somehow ended up with two copies of clang_complete.vim in these two places

./bundle/clang_complete/plugin/
./bundle/vundle/plugin/

Obviously I did something wrong; after I nuked bundle/ and re-ran :BundleInstall all is well. 👍

Owner
Rip-Rip commented Feb 5, 2013

Great!

@Rip-Rip Rip-Rip closed this Feb 5, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment