ncm2 / ncm2-pyclang

Cached, fast C/C++ completion for ncm2
MIT License
45 stars 1 forks source link

Job is dead: FileNotFoundError #26

Closed qige96 closed 5 years ago

qige96 commented 5 years ago

Hi, I meet ncm2 today and tried it. It was incredibly cool and useful, even on Windows system. Everything went well when I set up my Python and JavaScript support, until I went into ncm2-pyclang. Below is the error message when I run :message

[ncm2_pyclang_proc@yarp] Traceback (most recent call last):^M
[ncm2_pyclang_proc@yarp]   File "C:\Users\v_rickyzhu\.local\share\nvim\plugged\nvim-yarp\pythonx\yarp.py", line 65, in <module>^M
[ncm2_pyclang_proc@yarp]     module_obj = importlib.import_module(module)^M
[ncm2_pyclang_proc@yarp]   File "C:\Users\v_rickyzhu\AppData\Local\Programs\Python\Python37\lib\importlib\__init__.py", line 127, in import_module^M
[ncm2_pyclang_proc@yarp]     return _bootstrap._gcd_import(name[level:], package, level)^M
[ncm2_pyclang_proc@yarp]   File "<frozen importlib._bootstrap>", line 1006, in _gcd_import^M
[ncm2_pyclang_proc@yarp]   File "<frozen importlib._bootstrap>", line 983, in _find_and_load^M
[ncm2_pyclang_proc@yarp]   File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked^M
[ncm2_pyclang_proc@yarp]   File "<frozen importlib._bootstrap>", line 677, in _load_unlocked^M
[ncm2_pyclang_proc@yarp]   File "<frozen importlib._bootstrap_external>", line 728, in exec_module^M
[ncm2_pyclang_proc@yarp]   File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed^M
[ncm2_pyclang_proc@yarp]   File "C:\Users\v_rickyzhu\.local\share\nvim\plugged\ncm2-pyclang\pythonx\ncm2_pyclang_proc.py", line 530, in <module>^M
[ncm2_pyclang_proc@yarp]     source = Source(vim)^M
[ncm2_pyclang_proc@yarp]   File "C:\Users\v_rickyzhu\.local\share\nvim\plugged\ncm2-pyclang\pythonx\ncm2_pyclang_proc.py", line 56, in __init__^M
[ncm2_pyclang_proc@yarp]     sys_include['cpp'] = self.get_system_include(gcc_path, ['-xc++'])^M
[ncm2_pyclang_proc@yarp]   File "C:\Users\v_rickyzhu\.local\share\nvim\plugged\ncm2-pyclang\pythonx\ncm2_pyclang_proc.py", line 67, in get_system_include^M
[ncm2_pyclang_proc@yarp]     stderr=subprocess.PIPE)^M
[ncm2_pyclang_proc@yarp]   File "C:\Users\v_rickyzhu\.local\share\nvim\plugged\ncm2\pythonx\ncm2.py", line 26, in __init__^M
[ncm2_pyclang_proc@yarp]     cls.__init__(self, *args, **keys)^M
[ncm2_pyclang_proc@yarp]   File "C:\Users\v_rickyzhu\AppData\Local\Programs\Python\Python37\lib\subprocess.py", line 775, in __init__^M
[ncm2_pyclang_proc@yarp]     restore_signals, start_new_session)^M
[ncm2_pyclang_proc@yarp]   File "C:\Users\v_rickyzhu\AppData\Local\Programs\Python\Python37\lib\subprocess.py", line 1178, in _execute_child^M
[ncm2_pyclang_proc@yarp]     startupinfo)^M
[ncm2_pyclang_proc@yarp] FileNotFoundError: [WinError 2] ϵͳ<d5>Ҳ<bb><b5><bd><b6><a8><b5><c4><ce>ļ<fe><a1><a3>^M
[ncm2_pyclang_proc@yarp] Job is dead. cmd=['C:\Users\v_rickyzhu\AppData\Local\Programs\Python\Python37\python.exe', '-u', 'C:\Users\v_rickyzhu\.local\share\nvim\plugged\nvim-yarp\pythonx\yarp.py',
 '\\.\pipe\nvim-11156-0', 6, 'ncm2_pyclang_proc']
Press ENTER or type command to continue

For more information, I paste my whole init.vim file here:

call plug#begin('~/.local/share/nvim/plugged')

Plug 'scrooloose/nerdtree', { 'on':  'NERDTreeToggle' }
Plug 'nsf/gocode'
Plug 'tpope/vim-commentary'
Plug 'jiangmiao/auto-pairs'

" ncm2 
Plug 'roxma/nvim-yarp'
Plug 'ncm2/ncm2'
Plug 'ncm2/ncm2-bufword'
Plug 'ncm2/ncm2-path'
Plug 'ncm2/ncm2-jedi'
Plug 'ncm2/ncm2-pyclang'
Plug 'ncm2/ncm2-go'
Plug 'ncm2/ncm2-tern',  {'do': 'npm install'}
call plug#end()

" ncm2 
autocmd BufEnter * call ncm2#enable_for_buffer()
set completeopt=noinsert,menuone,noselect
set shortmess+=c
let g:ncm2_pyclang#library_path = 'D:/Program Files/LLVM/bin/libclang.dll'
let g:ncm2_pyclang#args_file_path = ['.clang_complete']

set ruler
set backspace=indent,eol,start

I spent hours trying to work around the problem in vain. However, after I switch the github repo to an earlier branch feature-fixits, the problem is solved. Thus, I think this should be a bug.

roxma commented 5 years ago

This plugin also needs g:ncm2#gcc_path to auto detect the system header directories.

libclang does not detect system header directories. If gcc is not possible on your system, we need a fallback approach for detecting system header directories.

roxma commented 5 years ago

However, after I switch the github repo to an earlier branch feature-fixits, the problem is solved. Thus, I think this should be a bug.

It's actually a recent change of behavior. What is the location of your c/c++ system headers? We need a reliable way to detect the system header directories.

qige96 commented 5 years ago

I have gcc on my system (cygwin64), but I didn't add it to my environment variables. Just now I add it, and the problem solved! Yet it still cannot find header files. Below ar locations of my headers files

So what should I put in g:ncm2#gcc_path ?

roxma commented 5 years ago

You can open a C/C++ file, then execute :echo ncm2_pyclang#get_args_dir() to
print the compiler arguments picked and passed to libclang.

roxma commented 5 years ago

I also need the result of gcc -xc++ -E -Wp,-v - on your cmd.exe. I guess it's using /usr/include style path instead of D:\cygwin\...

qige96 commented 5 years ago

Er......I open a C file, then execute :echo ncm2_pyclang#get_args_dir(), here is the print-out

[['-include', '../config.h', '-I../common', '-I/usr/include/c++/4.5.3/', '-I/usr/include/c++/4.5.3/x86_64-slackware-linux/', '-ferror-limit=99999999', '-xc', '-isystem', '/usr/lib/gcc/x86_64-pc-cy
gwin/7.4.0/include', '-isystem', '/usr/include', '-isystem', '/usr/lib/gcc/x86_64-pc-cygwin/7.4.0/../../../../lib/../include/w32api'], 'C:\Users\v_rickyzhu\AppData\Local\nvim']

The result of gcc -xc++ -E -Wp,-v - is like this:

C:\>gcc -xc++ -E -Wp,-v -
ignoring nonexistent directory "/usr/local/include"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-pc-cygwin/7.4.0/include-fixed"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-pc-cygwin/7.4.0/../../../../x86_64-pc-cygwin/include"
ignoring duplicate directory "/usr/lib/gcc/x86_64-pc-cygwin/7.4.0/../../../../x86_64-pc-cygwin/lib/../lib/../../include/w32api"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc/x86_64-pc-cygwin/7.4.0/include/c++
 /usr/lib/gcc/x86_64-pc-cygwin/7.4.0/include/c++/x86_64-pc-cygwin
 /usr/lib/gcc/x86_64-pc-cygwin/7.4.0/include/c++/backward
 /usr/lib/gcc/x86_64-pc-cygwin/7.4.0/include
 /usr/include
 /usr/lib/gcc/x86_64-pc-cygwin/7.4.0/../../../../lib/../include/w32api
End of search list.

So, do I need to pick one of the path above as my g:ncm2#gcc_path? image

qige96 commented 5 years ago

The latest branch find no header files, but the old branch does get some results: the old branch get C headers of Clang and MSVC image

also C++ headers of MSVC image

Problem is that both of them cannot find C++ headers of Gcc and Clang, and C headers of Gcc. (I didn't set g:ncm2#gcc_path option )

roxma commented 5 years ago

Is it possible to install gcc on Windows directly instead of on Cygwin? I think it should work in this case.

roxma commented 5 years ago

It seems it is not possible https://gcc.gnu.org/install/binaries.html

roxma commented 5 years ago

OK. I've got two possible solution. Wait for my PR.

qige96 commented 5 years ago

So currently we have a just-so-so solution: use the old branch and install Clang and MSVC. Actually it is not so cool because MSVC is somewhat annoying, and both of their lib have no stdio.h and stdlib.h, etc.

qige96 commented 5 years ago

Dinner on around 18:00. Sorry if I didn't reply to you on time.

roxma commented 5 years ago

@qige96 Please test #27

I don't have windows vim environment setup on my PC. Not sure that branch gonna work without further debugging...

qige96 commented 5 years ago

Congratulations, seems you are successful in finding C headers, but still C++ headers not found.

image

The new program can locate headers under D:\cygwin64\usr\include, where most C headers stay, but C++ headers are inside D:\cygwin64\lib\gcc\x86_64-pc-cygwin\7.4.0\include

image

roxma commented 5 years ago

Test https://github.com/ncm2/ncm2-pyclang/commit/9a45aeefb754b36a0fa3b960cca1b19f4ecf5a7c

By the way, since you already have cygwin, why not use the neovim inside cygwin? It's easier to get things working in cygwin.

qige96 commented 5 years ago

Still it can find C headers but not C++ headers. image Well, not a big problem for me, since I hardly write C++ code. You can close the issue now. By the way, I prefer software built for specific platform, so I seldom use tools in cygwin.

After all, Thanks for your great tools and helpful work!