This repository has been archived by the owner on Jan 27, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 52
Home
hrsh7th edited this page Oct 25, 2020
·
17 revisions
nvim-compe provides the custom source register API.
The custom source can be written in Vim script or Lua.
- The custom source is dictionary.
- The custom source must have
get_metadata
,datermine
,complete
.
This method should return the source's metadata.
The metadata can have...
- dup: 1/0
- see
:help complete-items
- see
- menu: string
- see
:help complete-items
- see
- priority: number
- This uses nvim-compe's filtering implementation.
- The items always sort priority order.
- sort: boolean
- This uses nvim-compe's filtering implementation.
- The items do not sort so the source should sort items manually.
The datermine
method should return { keyword_pattern_offset?: number, trigger_character_offset?: number }
.
If the datermine
return an empty object, nvim-compe does not trigger completion.
The keyword_pattern_offset
means pum position
.
In PHP, When the line is $|
, keyword_pattern_offset should 1.
The complete
method should complete items and callback it.
The most simple source can be created by the below example of codes.
function! s:get_metadata(...) abort
return {
\ 'priority': 10,
\ 'menu': '[MY CUSTOM SOURCE]',
\ }
endfunction
function! s:datermine(context) abort
let l:keyword_pattern_offset = compe#pattern#get_keyword_pattern_offset(a:context)
if l:keyword_pattern_offset > 0
return {
\ 'keyword_pattern_offset': l:keyword_pattern_offset
\ }
endif
return {}
endfunction
function! s:complete(context) abort
call a:context.callback({
\ 'items': [
\ { 'word': 'January' },
\ { 'word': 'February' },
\ { 'word': 'March' },
\ { 'word': 'April' },
\ { 'word': 'May' },
\ { 'word': 'June' },
\ { 'word': 'July' },
\ { 'word': 'August' },
\ { 'word': 'September' },
\ { 'word': 'October' },
\ { 'word': 'November' },
\ { 'word': 'December' },
\ ]
\ })
endfunction
let s:source = {
\ 'get_metadata': function('s:get_metadata'),
\ 'datermine': function('s:datermine'),
\ 'complete': function('s:complete'),
\ }
" Register your custom source.
call compe#source#vim_bridge#register('month', s:source)
The most simple source can be created by the below example of codes.
local Source = {}
function Source.new()
return setmetatable({}, { __index = Source })
end
function Source.get_metadata(self)
-- similar to vim.
end
function Source.datermine(self, context)
-- similar to vim.
end
function Source.complete(self, context)
-- similar to vim.
end
-- Register your custom source.
require'compe':register_lua_source('month', Source)