Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
glepnir committed Feb 4, 2025
1 parent d6ebe32 commit 92ad077
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 476 deletions.
28 changes: 0 additions & 28 deletions lua/core/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,3 @@ if vim.env.COLORSCHEME then
vim.cmd.colorscheme(vim.env.COLORSCHEME)
return
end

if not vim.g.colors_name then
vim.cmd([[
hi EndOfBuffer guifg=#14161b
hi Function guifg=#a6dbff
hi link @property @variable
hi Type guifg=#fce094
hi link @type.builtin Type
hi link @type Type
hi link Delimiter Comment
hi DiagnosticUnderlineError guisp=#ffc0b9 cterm=undercurl gui=undercurl
hi DiagnosticUnderlineWarn guisp=#fce094 cterm=undercurl gui=undercurl
hi DiagnosticUnderlineInfo guisp=#8cf8f7 cterm=undercurl gui=undercurl
hi DiagnosticUnderlineHint guisp=#a6dbff cterm=undercurl gui=undercurl
hi DiagnosticUnderlineOk guisp=#b3f6c0 cterm=underline gui=underline
hi IndentLine guifg=#2c2e33
hi IndentLineCurrent guifg=#9b9ea4
hi netrwTreeBar guifg=#2c2e33
hi DashboardHeader guifg=#b3f6c0
hi GitSignsAdd guifg=#005523
hi GitSignsChange guifg=#007373
hi GitSignsDelete guifg=#590008
]])
end
1 change: 0 additions & 1 deletion lua/core/options.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ opt.smartcase = true
opt.infercase = true
opt.cursorline = true

opt.completeopt = 'menu,menuone,noinsert,fuzzy,popup'
opt.showmode = false
opt.shortmess = 'aoOTIcF'
opt.scrolloff = 2
Expand Down
76 changes: 37 additions & 39 deletions lua/internal/completion.lua
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,
})
7 changes: 0 additions & 7 deletions lua/internal/event.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,6 @@ au('TermOpen', {
end,
})

au('InsertEnter', {
group = group,
callback = function()
require('internal.pairs').setup({})
end,
})

au('LspAttach', {
callback = function(args)
if vim.bo[args.buf].filetype == 'lua' and api.nvim_buf_get_name(args.buf):find('_spec') then
Expand Down
Loading

0 comments on commit 92ad077

Please sign in to comment.