* dev

* Improve sync design

* Support buffer local mapping

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* stylua

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* integration

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* update

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp
This commit is contained in:
hrsh7th
2021-08-04 01:07:12 +09:00
committed by GitHub
parent b32a6e7e77
commit d23d3533cf
53 changed files with 4681 additions and 0 deletions

View File

@@ -0,0 +1,88 @@
local types = require'cmp.types'
local misc = require 'cmp.utils.misc'
local compare = {}
-- offset
compare.offset = function(entry1, entry2)
local diff = entry1:get_offset() - entry2:get_offset()
if diff < 0 then
return true
elseif diff > 0 then
return false
end
end
-- exact
compare.exact = function(entry1, entry2)
if entry1.exact ~= entry2.exact then
return entry1.exact
end
end
-- score
compare.score = function(entry1, entry2)
local diff = entry2.score - entry1.score
if diff < 0 then
return true
elseif diff > 0 then
return false
end
end
-- kind
compare.kind = function(entry1, entry2)
local kind1 = entry1:get_kind()
kind1 = kind1 == types.lsp.CompletionItemKind.Text and 100 or kind1
local kind2 = entry2:get_kind()
kind2 = kind2 == types.lsp.CompletionItemKind.Text and 100 or kind2
if kind1 ~= kind2 then
if kind1 == types.lsp.CompletionItemKind.Snippet then
return true
end
if kind2 == types.lsp.CompletionItemKind.Snippet then
return false
end
local diff = kind1 - kind2
if diff < 0 then
return true
elseif diff > 0 then
return false
end
end
end
-- sortText
compare.sort_text = function(entry1, entry2)
if misc.safe(entry1.completion_item.sortText) and misc.safe(entry2.completion_item.sortText) then
local diff = vim.stricmp(entry1.completion_item.sortText, entry2.completion_item.sortText)
if diff < 0 then
return true
elseif diff > 0 then
return false
end
end
end
-- length
compare.length = function(entry1, entry2)
local diff = #entry1.completion_item.label - #entry2.completion_item.label
if diff < 0 then
return true
elseif diff > 0 then
return false
end
end
-- order
compare.order = function(entry1, entry2)
local diff = entry1.id - entry2.id
if diff < 0 then
return true
elseif diff > 0 then
return false
end
end
return compare

119
lua/cmp/config/default.lua Normal file
View File

@@ -0,0 +1,119 @@
local str = require('cmp.utils.str')
local misc = require('cmp.utils.misc')
local compare = require('cmp.config.compare')
local types = require('cmp.types')
local WIDE_HEIGHT = 40
---@return cmp.ConfigSchema
return function()
return {
completion = {
autocomplete = {
types.cmp.TriggerEvent.InsertEnter,
types.cmp.TriggerEvent.TextChanged,
},
completeopt = 'menu,menuone,noselect',
keyword_pattern = [[\%(-\?\d\+\%(\.\d\+\)\?\|\h\w*\%(-\w*\)*\)]],
keyword_length = 1,
},
snippet = {
expand = function()
error('snippet engine does not configured.')
end,
},
documentation = {
border = { '', '', '', ' ', '', '', '', ' ' },
winhighlight = 'NormalFloat:CmpDocumentation,FloatBorder:CmpDocumentationBorder',
maxwidth = math.floor((WIDE_HEIGHT * 2) * (vim.o.columns / (WIDE_HEIGHT * 2 * 16 / 9))),
maxheight = math.floor(WIDE_HEIGHT * (WIDE_HEIGHT / vim.o.lines)),
},
confirmation = {
default_behavior = types.cmp.ConfirmBehavior.Replace,
mapping = {
['<CR>'] = {
behavior = types.cmp.ConfirmBehavior.Replace,
select = true,
},
}
},
sorting = {
sort = function(entries)
table.sort(entries, function(entry1, entry2)
for _, fn in ipairs({
compare.offset,
compare.exact,
compare.score,
compare.kind,
compare.sort_text,
compare.length,
compare.order,
}) do
local diff = fn(entry1, entry2)
if diff ~= nil then
return diff
end
end
return true
end)
return entries
end
},
formatting = {
format = function(e, suggest_offset)
local item = e:get_completion_item()
local word = e:get_word()
local abbr = str.trim(item.label)
-- ~ indicator
if #(misc.safe(item.additionalTextEdits) or {}) > 0 then
abbr = abbr .. '~'
elseif item.insertTextFormat == types.lsp.InsertTextFormat.Snippet then
local insert_text = e:get_insert_text()
if word ~= insert_text then
abbr = abbr .. '~'
end
end
-- deprecated
if item.deprecated or vim.tbl_contains(item.tags or {}, types.lsp.CompletionItemTag.Deprecated) then
abbr = str.strikethrough(abbr)
end
-- append delta text
if suggest_offset < e:get_offset() then
word = string.sub(e.context.cursor_before_line, suggest_offset, e:get_offset() - 1) .. word
end
-- labelDetails.
local menu = nil
if misc.safe(item.labelDetails) then
menu = ''
if misc.safe(item.labelDetails.parameters) then
menu = menu .. item.labelDetails.parameters
end
if misc.safe(item.labelDetails.type) then
menu = menu .. item.labelDetails.type
end
if misc.safe(item.labelDetails.qualifier) then
menu = menu .. item.labelDetails.qualifier
end
end
return {
word = word,
abbr = abbr,
kind = types.lsp.CompletionItemKind[e:get_kind()] or types.lsp.CompletionItemKind[1],
menu = menu,
}
end
},
sources = {},
}
end