Giter Site home page Giter Site logo

ncm2-pyclang's Introduction

Introduction

NCM2, formerly known as nvim-completion-manager, is a slim, fast and hackable completion framework for neovim.

Main features:

  1. Fast and asynchronous completion support, with vimscript friendly API.
  2. Smart on files with different languages, for example, css/javascript completion in html style/script tag.
  3. Function parameter expansion support using ncm2-snippet plugins.
  4. Language server protocol plugin integration.

Read our wiki page for a list of extensions and programming languages support for NCM2.

peek 2018-07-17 18-15

View demo vimrc at #19

Requirements

  • :echo has("nvim-0.2.2") prints 1. Older versions has not been tested
  • :echo has("python3") prints 1. This is usually set by python3 -m pip install pynvim in shell and let g:python3_host_prog=/path/to/python/executable/ in vimrc.
  • Plugin nvim-yarp

For vim8 user, read the nvim-yarp README. Note that vim8 support is simply a bonus. It's not the goal of NCM2.

Install

    " assuming you're using vim-plug: https://github.com/junegunn/vim-plug
    Plug 'ncm2/ncm2'
    Plug 'roxma/nvim-yarp'

    " enable ncm2 for all buffers
    autocmd BufEnter * call ncm2#enable_for_buffer()

    " IMPORTANT: :help Ncm2PopupOpen for more information
    set completeopt=noinsert,menuone,noselect

    " NOTE: you need to install completion sources to get completions. Check
    " our wiki page for a list of sources: https://github.com/ncm2/ncm2/wiki
    Plug 'ncm2/ncm2-bufword'
    Plug 'ncm2/ncm2-path'

Optional Vimrc Tips

    " suppress the annoying 'match x of y', 'The only match' and 'Pattern not
    " found' messages
    set shortmess+=c

    " CTRL-C doesn't trigger the InsertLeave autocmd . map to <ESC> instead.
    inoremap <c-c> <ESC>

    " When the <Enter> key is pressed while the popup menu is visible, it only
    " hides the menu. Use this mapping to close the menu and also start a new
    " line.
    inoremap <expr> <CR> (pumvisible() ? "\<c-y>\<cr>" : "\<CR>")

    " Use <TAB> to select the popup menu:
    inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>"
    inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"

    " wrap existing omnifunc
    " Note that omnifunc does not run in background and may probably block the
    " editor. If you don't want to be blocked by omnifunc too often, you could
    " add 180ms delay before the omni wrapper:
    "  'on_complete': ['ncm2#on_complete#delay', 180,
    "               \ 'ncm2#on_complete#omni', 'csscomplete#CompleteCSS'],
    au User Ncm2Plugin call ncm2#register_source({
            \ 'name' : 'css',
            \ 'priority': 9,
            \ 'subscope_enable': 1,
            \ 'scope': ['css','scss'],
            \ 'mark': 'css',
            \ 'word_pattern': '[\w\-]+',
            \ 'complete_pattern': ':\s*',
            \ 'on_complete': ['ncm2#on_complete#omni', 'csscomplete#CompleteCSS'],
            \ })

How Do I write Ncm2 Source?

One important step is to understand how and when completion gets triggered. Read :help ncm2#register_source carefully, or :help ncm2#register_source-example for quick start.

In case you don't know what tool you should use for async support. Here are some options available:

Debugging

Refer to the debugging section of nvim-yarp

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

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.

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

[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.

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.

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 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'
\ ]

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.

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?

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.

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.

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?

[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!

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

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.