-
-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
98 additions
and
476 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,55 @@ | ||
local api, completion, ffi, lsp = vim.api, vim.lsp.completion, require('ffi'), vim.lsp | ||
local au = api.nvim_create_autocmd | ||
local ms, libc = vim.lsp.protocol.Methods, ffi.C | ||
local api, completion, lsp = vim.api, vim.lsp.completion, vim.lsp | ||
local ms = lsp.protocol.Methods | ||
local InsertCharPre = 'InsertCharPre' | ||
ffi.cdef([[ | ||
typedef int32_t linenr_T; | ||
char *ml_get(linenr_T lnum); | ||
bool pum_visible(void); | ||
]]) | ||
local pumvisible = libc.pum_visible | ||
local g = api.nvim_create_augroup('glepnir/completion', { clear = true }) | ||
local pumvisible = vim.fn.pumvisible | ||
local g = api.nvim_create_augroup('glepnir.completion', { clear = true }) | ||
|
||
-- completion on word which not exist in lsp client triggerCharacters | ||
local function auto_trigger(bufnr, client) | ||
au(InsertCharPre, { | ||
buffer = bufnr, | ||
group = g, | ||
callback = function() | ||
if pumvisible() then | ||
return | ||
end | ||
local triggerchars = vim.tbl_get( | ||
client, | ||
'server_capabilities', | ||
'completionProvider', | ||
'triggerCharacters' | ||
) or {} | ||
if vim.v.char:match('[%w_]') and not vim.list_contains(triggerchars, vim.v.char) then | ||
vim.schedule(function() | ||
completion.trigger() | ||
end) | ||
end | ||
end, | ||
}) | ||
end | ||
vim.opt.cot = 'menu,menuone,noinsert,fuzzy,popup' | ||
vim.opt.cia = 'kind,abbr,menu' | ||
|
||
au('LspAttach', { | ||
api.nvim_create_autocmd('LspAttach', { | ||
group = g, | ||
callback = function(args) | ||
local bufnr = args.buf | ||
local client = lsp.get_client_by_id(args.data.client_id) | ||
if not client or not client:supports_method('textDocument/completion') then | ||
if not client or not client:supports_method(ms.textDocument_completion) then | ||
return | ||
end | ||
|
||
completion.enable(true, client.id, bufnr, { | ||
autotrigger = true, | ||
convert = function(item) | ||
return { abbr = item.label:gsub('%b()', ''), kind = '', kind_hlgroup = '' } | ||
local kind = lsp.protocol.CompletionItemKind[item.kind] or 'u' | ||
return { | ||
abbr = item.label:gsub('%b()', ''), | ||
kind = kind:sub(1, 1):lower(), | ||
kind_hlgroup = ('@lsp.type.%s'):format(kind:sub(1, 1):lower() .. kind:sub(2)), | ||
} | ||
end, | ||
}) | ||
|
||
if #api.nvim_get_autocmds({ buffer = bufnr, event = 'InsertCharPre', group = g }) == 0 then | ||
auto_trigger(bufnr, client) | ||
if #api.nvim_get_autocmds({ buffer = bufnr, event = 'InsertCharPre', group = g }) ~= 0 then | ||
return | ||
end | ||
api.nvim_create_autocmd(InsertCharPre, { | ||
buffer = bufnr, | ||
group = g, | ||
callback = function() | ||
if tonumber(pumvisible()) == 1 then | ||
return | ||
end | ||
local triggerchars = vim.tbl_get( | ||
client, | ||
'server_capabilities', | ||
'completionProvider', | ||
'triggerCharacters' | ||
) or {} | ||
if vim.v.char:match('[%w_]') and not vim.list_contains(triggerchars, vim.v.char) then | ||
vim.schedule(function() | ||
completion.trigger() | ||
end) | ||
end | ||
end, | ||
desc = 'glepnir: completion on character which not exist in lsp client triggerCharacters', | ||
}) | ||
end, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.