Docs: Use tree-sitter language injection (#1350)

see:
    https://github.com/nvim-treesitter/nvim-treesitter/pull/3846
This commit is contained in:
OgaKen
2022-12-15 13:36:48 +09:00
committed by GitHub
parent 93f385c176
commit 10b1d11252

View File

@@ -44,7 +44,7 @@ A recommended configuration can be found below.
1. You must provide a `snippet.expand` function. 1. You must provide a `snippet.expand` function.
2. `cmp.setup.cmdline` won't work if you use the `native` completion menu. 2. `cmp.setup.cmdline` won't work if you use the `native` completion menu.
3. You can disable the `default` options by specifying `cmp.config.disable` value. 3. You can disable the `default` options by specifying `cmp.config.disable` value.
> >vim
call plug#begin(s:plug_dir) call plug#begin(s:plug_dir)
Plug 'neovim/nvim-lspconfig' Plug 'neovim/nvim-lspconfig'
Plug 'hrsh7th/cmp-nvim-lsp' Plug 'hrsh7th/cmp-nvim-lsp'
@@ -182,7 +182,7 @@ NOTE: `<Cmd>lua require('cmp').complete()<CR>` can be used to call these functio
Invoke completion. Invoke completion.
The following configuration defines a key mapping to show completion only for vsnip snippets. The following configuration defines a key mapping to show completion only for vsnip snippets.
> >lua
cmp.setup { cmp.setup {
mapping = { mapping = {
['<C-s>'] = cmp.mapping.complete({ ['<C-s>'] = cmp.mapping.complete({
@@ -194,14 +194,14 @@ NOTE: `<Cmd>lua require('cmp').complete()<CR>` can be used to call these functio
}) })
} }
} }
< > < >vim
inoremap <C-S> <Cmd>lua require('cmp').complete({ config = { sources = { { name = 'vsnip' } } } })<CR> inoremap <C-S> <Cmd>lua require('cmp').complete({ config = { sources = { { name = 'vsnip' } } } })<CR>
< <
NOTE: `config` in that case means a temporary setting, but `config.mapping` remains permanent. NOTE: `config` in that case means a temporary setting, but `config.mapping` remains permanent.
*cmp.complete_common_string* () *cmp.complete_common_string* ()
Complete common string (similar to shell completion behavior). Complete common string (similar to shell completion behavior).
> >lua
cmp.setup { cmp.setup {
mapping = { mapping = {
['<C-l>'] = cmp.mapping(function(fallback) ['<C-l>'] = cmp.mapping(function(fallback)
@@ -239,7 +239,7 @@ The `fallback` function can be used to call an existing mapping.
For example, typical pair-wise plugins automatically define mappings for `<CR>` and `(`. For example, typical pair-wise plugins automatically define mappings for `<CR>` and `(`.
Nvim-cmp will overwrite it if you provide a mapping. To call the existing mapping, Nvim-cmp will overwrite it if you provide a mapping. To call the existing mapping,
you would need to invoke the `fallback` function. you would need to invoke the `fallback` function.
> >lua
cmp.setup { cmp.setup {
mapping = { mapping = {
['<CR>'] = function(fallback) ['<CR>'] = function(fallback)
@@ -251,7 +251,7 @@ you would need to invoke the `fallback` function.
end end
} }
} }
< > < >lua
cmp.setup { cmp.setup {
mapping = { mapping = {
['<Tab>'] = function(fallback) ['<Tab>'] = function(fallback)
@@ -266,7 +266,7 @@ you would need to invoke the `fallback` function.
< <
It is possible to specify the modes the mapping should be active in (`i` = insert mode, `c` = command mode, `s` = select mode): It is possible to specify the modes the mapping should be active in (`i` = insert mode, `c` = command mode, `s` = select mode):
> >lua
cmp.setup { cmp.setup {
mapping = { mapping = {
['<CR>'] = cmp.mapping(your_mapping_function, { 'i', 'c' }) ['<CR>'] = cmp.mapping(your_mapping_function, { 'i', 'c' })
@@ -274,7 +274,7 @@ It is possible to specify the modes the mapping should be active in (`i` = inser
} }
< <
You can also specify different mappings for different modes by passing a table: You can also specify different mappings for different modes by passing a table:
> >lua
cmp.setup { cmp.setup {
mapping = { mapping = {
['<CR>'] = cmp.mapping({ ['<CR>'] = cmp.mapping({
@@ -350,7 +350,7 @@ NOTE: `kind` is a symbol after each completion option.
*CmpItemKind%KIND_NAME%* *CmpItemKind%KIND_NAME%*
Highlight group for the kind of the field for a specific `lsp.CompletionItemKind`. Highlight group for the kind of the field for a specific `lsp.CompletionItemKind`.
If you only want to overwrite the `method` kind's highlight group, you can do this: If you only want to overwrite the `method` kind's highlight group, you can do this:
> >vim
highlight CmpItemKindMethod guibg=NONE guifg=Orange highlight CmpItemKindMethod guibg=NONE guifg=Orange
< <
*CmpItemMenu* *CmpItemMenu*
@@ -490,7 +490,7 @@ sorting.priority_weight~
Each item's original priority (given by its corresponding source) will be Each item's original priority (given by its corresponding source) will be
increased by `#sources - (source_index - 1)` and multiplied by `priority_weight`. increased by `#sources - (source_index - 1)` and multiplied by `priority_weight`.
That is, the final priority is calculated by the following formula: That is, the final priority is calculated by the following formula:
> >lua
final_score = orig_score + ((#sources - (source_index - 1)) * sorting.priority_weight) final_score = orig_score + ((#sources - (source_index - 1)) * sorting.priority_weight)
< <
*cmp-config.sorting.comparators* *cmp-config.sorting.comparators*
@@ -547,7 +547,7 @@ sources[n].group_index~
For instance, you can set the `buffer`'s source `group_index` to a larger number For instance, you can set the `buffer`'s source `group_index` to a larger number
if you don't want to see `buffer` source items while `nvim-lsp` source is available: if you don't want to see `buffer` source items while `nvim-lsp` source is available:
> >lua
cmp.setup { cmp.setup {
sources = { sources = {
{ name = 'nvim_lsp', group_index = 1 }, { name = 'nvim_lsp', group_index = 1 },
@@ -556,7 +556,7 @@ sources[n].group_index~
} }
< <
You can also achieve this by using the built-in configuration helper like this: You can also achieve this by using the built-in configuration helper like this:
> >lua
cmp.setup { cmp.setup {
sources = cmp.config.sources({ sources = cmp.config.sources({
{ name = 'nvim_lsp' }, { name = 'nvim_lsp' },
@@ -579,7 +579,7 @@ sources[n].entry_filter~
This can be used to hide certain entries from a given source. For instance, you This can be used to hide certain entries from a given source. For instance, you
could hide all entries with kind `Text` from the `nvim_lsp` filter using the could hide all entries with kind `Text` from the `nvim_lsp` filter using the
following source definition: following source definition:
> >lua
{ {
name = 'nvim_lsp', name = 'nvim_lsp',
entry_filter = function(entry, ctx) entry_filter = function(entry, ctx)
@@ -662,7 +662,7 @@ cmp.config.compare~
cmp.config.context~ cmp.config.context~
The `cmp.config.context` can be used for context-aware completion toggling. The `cmp.config.context` can be used for context-aware completion toggling.
> >lua
cmp.setup { cmp.setup {
enabled = function() enabled = function()
-- disable completion if the cursor is `Comment` syntax group. -- disable completion if the cursor is `Comment` syntax group.
@@ -688,7 +688,7 @@ cmp.config.sources~
You can specify multiple source arrays. The sources are grouped in the You can specify multiple source arrays. The sources are grouped in the
order you specify, and the groups are displayed as a fallback, like chain order you specify, and the groups are displayed as a fallback, like chain
completion. completion.
> >lua
cmp.setup { cmp.setup {
sources = cmp.config.sources({ sources = cmp.config.sources({
{ name = 'nvim_lsp' }, { name = 'nvim_lsp' },
@@ -702,7 +702,7 @@ cmp.config.window~
*cmp.config.window.bordered* (option) *cmp.config.window.bordered* (option)
Make the completion window `bordered`. Make the completion window `bordered`.
The option is described in `cmp.ConfigSchema`. The option is described in `cmp.ConfigSchema`.
> >lua
cmp.setup { cmp.setup {
window = { window = {
completion = cmp.config.window.bordered(), completion = cmp.config.window.bordered(),
@@ -725,7 +725,7 @@ NOTE:
and if you publish it on GitHub, add the `nvim-cmp` topic so users can find it more easily. and if you publish it on GitHub, add the `nvim-cmp` topic so users can find it more easily.
Here is an example on how to create a custom source: Here is an example on how to create a custom source:
> >lua
local source = {} local source = {}
---Return whether this source is available in the current context or not (optional). ---Return whether this source is available in the current context or not (optional).
@@ -807,7 +807,7 @@ How to disable the preselect feature? ~
The LSP spec defines the `preselect` feature for completion. The LSP spec defines the `preselect` feature for completion.
You can disable the `preselect` feature like this: You can disable the `preselect` feature like this:
> >lua
cmp.setup { cmp.setup {
preselect = cmp.PreselectMode.None preselect = cmp.PreselectMode.None
} }
@@ -816,7 +816,7 @@ How to disable the preselect feature? ~
How to disable commitCharacters?~ How to disable commitCharacters?~
You can disable the commitCharacters feature (which is defined in LSP spec): You can disable the commitCharacters feature (which is defined in LSP spec):
> >lua
cmp.setup { cmp.setup {
confirmation = { confirmation = {
get_commit_characters = function(commit_characters) get_commit_characters = function(commit_characters)
@@ -831,7 +831,7 @@ How to disable auto-completion?~
How to use nvim-cmp as omnifunc?~ How to use nvim-cmp as omnifunc?~
You can disable auto-completion like this: You can disable auto-completion like this:
> >lua
cmp.setup { cmp.setup {
... ...
completion = { completion = {
@@ -841,7 +841,7 @@ How to use nvim-cmp as omnifunc?~
} }
< <
Then you will need to invoke completion manually. Then you will need to invoke completion manually.
> >vim
inoremap <C-x><C-o> <Cmd>lua require('cmp').complete()<CR> inoremap <C-x><C-o> <Cmd>lua require('cmp').complete()<CR>
< <
@@ -849,7 +849,7 @@ How to disable nvim-cmp for a specific buffer?~
How to setup nvim-cmp for a specific buffer?~ How to setup nvim-cmp for a specific buffer?~
You can setup buffer-specific configuration like this: You can setup buffer-specific configuration like this:
> >lua
cmp.setup.filetype({ 'markdown', 'help' }, { cmp.setup.filetype({ 'markdown', 'help' }, {
sources = { sources = {
{ name = 'path' }, { name = 'path' },
@@ -861,7 +861,7 @@ How to setup nvim-cmp for a specific buffer?~
How to disable the documentation window?~ How to disable the documentation window?~
Simply use the following config: Simply use the following config:
> >lua
cmp.setup.filetype({ 'markdown', 'help' }, { cmp.setup.filetype({ 'markdown', 'help' }, {
window = { window = {
documentation = cmp.config.disable documentation = cmp.config.disable
@@ -881,12 +881,12 @@ How to integrate with copilot.vim?~
Therefore, you should manage those plugins by yourself. Therefore, you should manage those plugins by yourself.
Fortunately, the copilot.vim has a feature that disables the fallback mechanism. Fortunately, the copilot.vim has a feature that disables the fallback mechanism.
> >vim
let g:copilot_no_tab_map = v:true let g:copilot_no_tab_map = v:true
imap <expr> <Plug>(vimrc:copilot-dummy-map) copilot#Accept("\<Tab>") imap <expr> <Plug>(vimrc:copilot-dummy-map) copilot#Accept("\<Tab>")
< <
You can manage copilot.vim's accept feature inside nvim-cmp's key-mapping function: You can manage copilot.vim's accept feature inside nvim-cmp's key-mapping function:
> >lua
cmp.setup { cmp.setup {
mapping = { mapping = {
['<C-g>'] = cmp.mapping(function(fallback) ['<C-g>'] = cmp.mapping(function(fallback)