Coder Social home page Coder Social logo

dishantpandya777 / completion-nvim Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nvim-lua/completion-nvim

0.0 0.0 0.0 265 KB

A async completion framework aims to provide completion to neovim's built in LSP written in Lua

License: Apache License 2.0

Lua 92.70% Vim Script 7.30%

completion-nvim's Introduction

Build Status Gitter

completion-nvim

completion-nvim is an auto completion framework that aims to provide a better completion experience with neovim's built-in LSP. Other LSP functionality is not supported.

Features

  • Asynchronous completion using the libuv api.
  • Automatically open hover windows when popupmenu is available.
  • Automatically open signature help if it's available.
  • Snippets integration with UltiSnips and Neosnippet and vim-vsnip.
  • Apply additionalTextEdits in LSP spec if it's available.
  • Chain completion support inspired by vim-mucomplete

Demo

Demo using sumneko_lua

Prerequisites

  • Neovim nightly
  • You should set up your language server of choice with the help of nvim-lsp

Install

  • Install with any plugin manager by using the path on GitHub.
Plug 'nvim-lua/completion-nvim'

Setup

  • completion-nvim requires several autocommands set up to work properly. You should set it up using the on_attach function like this.
lua require'nvim_lsp'.pyls.setup{on_attach=require'completion'.on_attach}
  • Change pyls to whichever language server you're using.
  • If you want completion-nvim to be set up for all buffers instead of only being used when lsp is enabled, call the on_attach function directly:
" Use completion-nvim in every buffer
autocmd BufEnter * lua require'completion'.on_attach()

NOTE It's okay to set up completion-nvim without lsp. It will simply use another completion source instead(Ex: snippets).

Supported Completion Source

  • built-in sources

    • lsp: completion source for neovim's built-in LSP.
    • snippet: completion source for snippet.
    • path: completion source for path from current file.
  • ins-complete sources

    • See :h ins-completion and wiki
  • external sources

Configuration

Recommended Setting

" Use <Tab> and <S-Tab> to navigate through popup menu
inoremap <expr> <Tab>   pumvisible() ? "\<C-n>" : "\<Tab>"
inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"

" Set completeopt to have a better completion experience
set completeopt=menuone,noinsert,noselect

" Avoid showing message extra message when using completion
set shortmess+=c

Enable/Disable auto popup

  • By default auto popup is enabled, turn it off by
let g:completion_enable_auto_popup = 0
  • Or you can toggle auto popup on the fly by using command CompletionToggle
  • You can manually trigger completion with mapping key by
inoremap <silent><expr> <c-p> completion#trigger_completion() "map <c-p> to manually trigger completion
  • Or you want to use <Tab> as trigger keys
function! s:check_back_space() abort
    let col = col('.') - 1
    return !col || getline('.')[col - 1]  =~ '\s'
endfunction

inoremap <silent><expr> <TAB>
  \ pumvisible() ? "\<C-n>" :
  \ <SID>check_back_space() ? "\<TAB>" :
  \ completion#trigger_completion()

Enable Snippets Support

  • By default other snippets source support are disabled, turn them on by
" possible value: 'UltiSnips', 'Neosnippet', 'vim-vsnip'
let g:completion_enable_snippet = 'UltiSnips'
  • Support UltiSnips and Neosnippet and vim-vsnip

LSP Based Snippet parsing

  • Some language server have snippet support but neovim couldn't handle that for now, completion-nvim can integrate with other LSP snippet parsing plugin for this support.

  • Right now only support vim-vsnip(require vim-vsnip-integ), it should work out of the box if you have vim-vsnip and vim-vsnip-integ installed.

Chain Completion Support

  • completion-nvim supports chain completion, which use other completion sources and ins-completion as a fallback for lsp completion.

  • See wiki for details on how to set this up.

Changing Completion Confirm key

  • By default <CR> is used to confirm completion and expand snippets, change it by
let g:completion_confirm_key = "\<C-y>"
  • Make sure to use " " and add escape key \ to avoid parsing issues.
  • If the confirm key has a fallback mapping, for example when using the auto pairs plugin, it maps to <CR>. You can avoid using the default confirm key option and use a mapping like this instead.
let g:completion_confirm_key = ""
imap <expr> <cr>  pumvisible() ? complete_info()["selected"] != "-1" ?
                 \ "\<Plug>(completion_confirm_completion)"  : "\<c-e>\<CR>" :  "\<CR>"

Enable/Disable auto hover

  • By default when navigating through completion items, LSP's hover is automatically called and displays in a floating window. Disable it by
let g:completion_enable_auto_hover = 0

Enable/Disable auto signature

  • By default signature help opens automatically whenever it's available. Disable it by
let g:completion_enable_auto_signature = 0

Sorting completion items

  • You can decide how your items being sorted in the popup menu. The default value is "alphabet", change it by
" possible value: "length", "alphabet", "none"
let g:completion_sorting = "length"
  • If you don't want any sorting, you can set this value to "none".

Matching Strategy

  • There are three different kind of matching technique implement in completion-nvim: substring, fuzzy or exact.

  • You can specify a list of matching strategy, completion-nvim will loop through the list and assign priority from high to low. For example

let g:completion_matching_strategy_list = ['exact', 'substring', 'fuzzy']

NOTE Fuzzy match highly dependent on what language server you're using. It might not work as you expect on some language server.

  • You can also enable ignore case matching by
g:completion_matching_ignore_case = 1

Trigger Characters

  • By default, completion-nvim respect the trigger character of your language server, if you want more trigger characters, add it by
let g:completion_trigger_character = ['.', '::']

NOTE use :lua print(vim.inspect(vim.lsp.buf_get_clients()[1].server_capabilities.completionProvider.triggerCharacters)) to see the trigger character of your language server.

  • If you want different trigger character for different languages, wrap it in an autocommand like
augroup CompletionTriggerCharacter
    autocmd!
    autocmd BufEnter * let g:completion_trigger_character = ['.']
    autocmd BufEnter *.c,*.cpp let g:completion_trigger_character = ['.', '::']
augroup end

Trigger keyword length

  • You can specify keyword length for triggering completion, if the current word is less then keyword length, completion won't be triggered.
let g:completion_trigger_keyword_length = 3 " default = 1

NOTE completion-nvim will ignore keyword length if you're on trigger character.

Trigger on delete

  • completion-nvim doesn't trigger completion on delete by default because sometimes I've found it annoying. However, you can enable it by
let g:completion_trigger_on_delete = 1

Timer Adjustment

  • completion-nvim uses a timer to control the rate of completion. You can adjust the timer rate by
let g:completion_timer_cycle = 200 "default value is 80

Per Server Setup

Compatibility with diagnostic-nvim

  • This plugin only focuses on the completion part of the built-in LSP. If you want similar help with diagnostics (e.g. virtual text, jump to diagnostic, open line diagnostic automatically...), take a look at diagnostic-nvim.

  • Both diagnostic-nvim and completion-nvim require setting up via on_attach. To use them together, create a wrapper function like this.

lua << EOF
local on_attach_vim = function()
  require'completion'.on_attach()
  require'diagnostic'.on_attach()
end
require'nvim_lsp'.pyls.setup{on_attach=on_attach_vim}
EOF

Trouble Shooting

  • This plugin is in the early stages and might have unexpected issues. Please follow wiki for trouble shooting.
  • Feel free to post issues on any unexpected behavior or open a feature request!

completion-nvim's People

Contributors

aca avatar ckipp01 avatar fsouza avatar halkn avatar hampustagerud avatar haorenw1025 avatar hrsh7th avatar humancalico avatar igrep avatar janvaliska avatar kdheepak avatar klauer avatar kristijanhusak avatar malept avatar nhooyr avatar travonted avatar vigoux avatar yaegassy avatar

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.