Giter Club home page Giter Club logo

ncm2-pyclang's Introduction

Introduction

C/C++ code completion plugin for ncm2

This plugin is based on libclang python binding. Inspired by clang_complete.

Features:

  • Support CMake or similar build systems that generate compile_commands.json
  • Support .clang_complete like clang-complete
  • Support Kbuild for linux kernel and u-boot, it generates something like init/.main.o.cmd
  • Support goto declaration. (not goto definition)
  • Support #include completion.

Config

g:ncm2_pyclang#library_path

Use g:ncm2_pyclang#library_path to specify the directory of libclang library or the file itself, e.g., for Linux:

" path to directory where libclang.so can be found
let g:ncm2_pyclang#library_path = '/usr/lib/llvm-5.0/lib'

" or path to the libclang.so file
let g:ncm2_pyclang#library_path = '/usr/lib64/libclang.so.5.0'

Notes:

  • Different operating systems normally have their own extensions for the libclang file.

    • Linux: libclang.so
    • macOS: libclang.dylib
    • Windows: libclang.dll
  • Sometimes ncm2-pyclang still works even you don't set g:ncm2_pyclang#library_path, that's because another libclang is found, which is probably the system libclang. The system libclang is often a bit old and is not guranteed to always be found, so I highly recommend set g:ncm_clang#library_path explicitly.

g:ncm2_pyclang#database_path

Usually, invoking cmake with option -DCMAKE_EXPORT_COMPILE_COMMANDS=ON generates the compilation database compile_commands.json.

The config g:ncm2_pyclang#database_path tells this plugin where to look for compilation database.

" a list of relative paths for compile_commands.json
let g:ncm2_pyclang#database_path = [
            \ 'compile_commands.json',
            \ 'build/compile_commands.json'
            \ ]

g:ncm2_pyclang#args_file_path

If your build system doesn't generate compile_commands.json, you could put a .clang_complete file into your project directory, which sould contain something like:

-DDEBUG
-include ../config.h
-I../common
" a list of relative paths looking for .clang_complete
let g:ncm2_pyclang#args_file_path = ['.clang_complete']

g:ncm2_pyclang#gcc_path

This option defaults to gcc. For some reason (I don't know), clang does not handle c++ builtin headers. This plugin uses gcc -xc++ -E -Wp,-v - to get a list of system header path.

If gcc is not available on your system, this plugin fallbacks to options definged in g:ncm2_pyclang#sys_inc_args_fallback.

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.

Goto Declaration

    autocmd FileType c,cpp nnoremap <buffer> gd :<c-u>call ncm2_pyclang#goto_declaration()<cr>

ncm2-pyclang's People

Contributors

ilya-biryukov avatar liuchengxu avatar roxma avatar tvatter avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

qix-

ncm2-pyclang's Issues

Behavior when using auto

Let's assume that I have the following:

auto obj1 = MyClass;
MyClass obj2;

Then, when typing obj1., a popup menu appears with the methods of MyClass, but not when typing obj2..

Is it intended? Is there something that I can/should do to get the popup menu for objects declared using the auto keyword?

Return types seem to be entirely missing.

Is there a way to get return types showing up in the menu and/or the scratch area?

image
image

P.S. I've used this plugin for ages now and it has singlehandedly improved my development times more than anything else, so thank you for doing it.

goto-declaration does not work

#include <iostream>

using namespace std;

int main() {
    cout << endl;
}

When I put my cursor on endl and type gd, I get

[ncm2_pyclang_proc@yarp] /usr/include/wchar.h:35:10: fatal error: 'stddef.h' file not found                                      
[ncm2_pyclang_proc@yarp] /usr/include/wchar.h:38:10: fatal error: 'stdarg.h' file not found
[ncm2_pyclang_proc@yarp] /usr/include/wchar.h:93:38: error: unknown type name 'size_t'
[ncm2_pyclang_proc@yarp] /usr/include/wchar.h:102:38: error: unknown type name 'size_t'
[ncm2_pyclang_proc@yarp] /usr/include/wchar.h:109:63: error: unknown type name 'size_t'
[ncm2_pyclang_proc@yarp] /usr/include/wchar.h:118:4: error: unknown type name 'size_t'
[ncm2_pyclang_proc@yarp] /usr/include/wchar.h:123:5: error: unknown type name 'locale_t'
[ncm2_pyclang_proc@yarp] /usr/include/wchar.h:126:6: error: unknown type name 'size_t'
[ncm2_pyclang_proc@yarp] /usr/include/wchar.h:126:18: error: unknown type name 'locale_t'
[ncm2_pyclang_proc@yarp] /usr/include/wchar.h:135:8: error: unknown type name 'size_t'
[ncm2_pyclang_proc@yarp] /usr/include/wchar.h:136:42: error: unknown type name 'size_t'
[ncm2_pyclang_proc@yarp] /usr/include/wchar.h:145:9: error: unknown type name 'locale_t'
[ncm2_pyclang_proc@yarp] /usr/include/wchar.h:150:8: error: unknown type name 'size_t'
[ncm2_pyclang_proc@yarp] /usr/include/wchar.h:151:5: error: unknown type name 'size_t'
[ncm2_pyclang_proc@yarp] /usr/include/wchar.h:151:17: error: unknown type name 'locale_t'
[ncm2_pyclang_proc@yarp] /usr/include/wchar.h:187:8: error: unknown type name 'size_t'
[ncm2_pyclang_proc@yarp] /usr/include/wchar.h:191:8: error: unknown type name 'size_t'
[ncm2_pyclang_proc@yarp] /usr/include/wchar.h:222:8: error: unknown type name 'size_t'
[ncm2_pyclang_proc@yarp] /usr/include/wchar.h:240:8: error: unknown type name 'size_t'
[ncm2_pyclang_proc@yarp] /tmp/1/1.cpp:6:13: error: reference to overloaded function could not be resolved; did you mean to call it?
Cannot find declaration

I am on ArchLinux. I did not use any compile_commands.json and clang++ compiles this code.

How to hide certain macros?

Is there a way to filter or hide specific macros like the ones that begin with underscores? I currently have no use for most of these and they clutter the autocompletion.

Imgur

pop up error when I write func parameter

when I write a struct var in func parameter, pop up error.
write same word in new line work fine.

reproduce way:

vim src/a.c
3G
o
test_func(te
[ncm2_pyclang_proc@yarp] error caught while executing async callback:
[ncm2_pyclang_proc@yarp] TypeError('exceptions must derive from BaseException',)
[ncm2_pyclang_proc@yarp] Traceback (most recent call last):
[ncm2_pyclang_proc@yarp]   File "/home/fcying/.vim/plugged/ncm2-pyclang/pythonx/ncm2_pyclang_proc.py", line 73, in raise_ex
[ncm2_pyclang_proc@yarp]     raise ex
[ncm2_pyclang_proc@yarp] TypeError: exceptions must derive from BaseException
[ncm2_pyclang_proc@yarp]  
[ncm2_pyclang_proc@yarp] the call was requested at
[ncm2_pyclang_proc@yarp]   File "/home/fcying/.pyenv/versions/3.6-dev/lib/python3.6/threading.py", line 884, in _bootstrap
[ncm2_pyclang_proc@yarp]     self._bootstrap_inner()
[ncm2_pyclang_proc@yarp]   File "/home/fcying/.pyenv/versions/3.6-dev/lib/python3.6/threading.py", line 916, in _bootstrap_inner
[ncm2_pyclang_proc@yarp]     self.run()
[ncm2_pyclang_proc@yarp]   File "/home/fcying/.pyenv/versions/3.6-dev/lib/python3.6/threading.py", line 864, in run
[ncm2_pyclang_proc@yarp]     self._target(*self._args, **self._kwargs)
[ncm2_pyclang_proc@yarp]   File "/home/fcying/.vim/plugged/ncm2-pyclang/pythonx/ncm2_pyclang_proc.py", line 74, in worker_loop
[ncm2_pyclang_proc@yarp]     nvim.async_call(raise_ex)

image

image

clang_test.zip

support `platformio.ini`

Hello, I use platformio to compile projects for embedded software and I think it would be nice to support it for automatic completion for library included and flags.

Currently i use .clang_complete but all the information required are in the platformio .ini file.

Goto in a new split

Hi and thanks for ncm2-pyclang, it works like a charm :)

Apologies for writing here, as it's definitely not an issue, but I'm still new to neovim and I'm not sure where to ask this.

I'm using the following line for the goto command:

autocmd FileType c,cpp nnoremap <buffer> gd :<c-u>call ncm2_pyclang#goto_declaration()<cr>

It works fine, but it opens the file in the split from where the command was called. Is there any way to have the goto automatically open a new split or something similar?

include file completion dosen't work

First, I got an error when typing a include file's name.

[ncm2_pyclang_proc@yarp] neovim.api.nvim.NvimError: request from non-main thread

image

The completion about the functions in the include file doesn't work, and the completion about works.

I got the clang installed and set the variables follow readme:

let g:ncm2_pyclang#library_path = '/usr/local/lib/'
let g:ncm2_pyclang#database_path = [
\ 'compile_commands.json',
\ 'build/compile_commands.json'
\ ]

[TODO] improve neovim quit time

When the parsing process takes a long time, it also affects neovim's quit behavior.

This plugin is stateless, is should be fine to use some detach property.

[ncm2_pyclang_proc@yarp] Job is dead.

I'm having trouble interpreting this error when trying to edit a .cpp file in nvim using this plugin.
The error is:

[ncm2_pyclang_proc@yarp] Job is dead. cmd=['/usr/bin/python3', '-u', '/home/user/.local/share/nvim/plugged/nvim-yarp/pythonx/yarp.py', '/tmp/nvimMQ7gCF/0', 5, 'ncm2_pyclang_proc']

My config looks like this:

" For ncm2-pyclang: A list of relative paths for compile_commands.json
" path to directory where libclang.so can be found
let g:ncm2_pyclang#library_path = '/usr/lib/llvm-6.0/lib'
let g:ncm2_pyclang#database_path = [
            \ 'compile_commands.json',
            \ 'build/compile_commands.json'
            \ ]

The compile_commands.json file exists in current directory and is generated by this tool

Any help is appreciated!

Non-relative/-absolute includes are ignored

$ ls
CMakeLists.txt	build		ext		src

$ ls build/*.json
build/compile_commands.json

$ cat ~/.config/nvim/init.vim | grep -A2 -B2 'compile_commands'
let g:ncm2_pyclang#library_path = '/usr/local/opt/llvm/lib'
let g:ncm2_pyclang#database_path = [
            \ 'compile_commands.json',
            \ 'build/compile_commands.json'
            \ ]
autocmd FileType c,cpp nnoremap <buffer> gd :<c-u>call ncm2_pyclang#goto_declaration()<cr>

Running nvim in the same directory as my CMakeLists.txt file (shown in the first ls above), I can #include a relative/absolute path to the header in question and get valid suggestions - however, relying on the include path set by include_directories() in CMake (emitting -I ../path/to/lib options in compile_commands.json, which I've verified exist) does not.

Either compile_commands.json is being ignored entirely, or for some reason this plugin isn't honoring -I.

Job is dead: FileNotFoundError

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.

Variable members are not displayed when using clangd 6

Hi, I was surprised to find out that there is no completion for variable when running with clangd 6.0.1. On my work machine I have clangd 5.0.2 (ubuntu 16) and completion for a variable is displayed. At home, on ArchLinux, it's not.

LLVM (http://llvm.org/):
  LLVM version 6.0.1
  Optimized build.
  Default target: x86_64-pc-linux-gnu
  Host CPU: sandybridge
let g:ncm2_pyclang#library_path = '/usr/lib/libclang.so.6.0'

Sample program:

#include <vector>
using namespace std;
int main() {
    vector<int> items;
    items.
    return 0;
}

no completion is displayed after items. On the other hand, completion for std:: is working fine.

Code completion for CUDA files

Hi,
I would like to use this plugin in CUDA files (.cuh and .cu), but it seems that filetypes are kinda hardwired into the source code. Do you have any hint on how to use this plugin with cuda files?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.