Skip to content

Commit 8b697b7

Browse files
committed
fixup! chore(lsp.completion): cleanup
1 parent eeb0c4a commit 8b697b7

File tree

1 file changed

+19
-196
lines changed

1 file changed

+19
-196
lines changed

init.lua

Lines changed: 19 additions & 196 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,10 @@ vim.opt.scrolloff = 10
161161
-- See `:help 'confirm'`
162162
vim.opt.confirm = true
163163

164+
-- set options for insert completion (ins-completion)
165+
-- See `:help completeopt`
166+
vim.o.completeopt = 'noselect,menu,menuone,noinsert,popup'
167+
164168
-- [[ Basic Keymaps ]]
165169
-- See `:help vim.keymap.set()`
166170

@@ -486,8 +490,8 @@ require('lazy').setup({
486490
-- Useful status updates for LSP.
487491
{ 'j-hui/fidget.nvim', opts = {} },
488492

489-
-- Allows extra capabilities provided by nvim-cmp
490-
-- 'hrsh7th/cmp-nvim-lsp',
493+
-- Show pictograms for completion
494+
{ 'onsails/lspkind.nvim', enabled = vim.g.have_nerd_font },
491495
},
492496
config = function()
493497
-- Brief aside: **What is LSP?**
@@ -623,88 +627,25 @@ require('lazy').setup({
623627
end,
624628
})
625629

630+
-- Show pictograms for completion when Nerd fonts are enabled
631+
if vim.g.have_nerd_font then
632+
local lspkind = require 'lspkind'
633+
local kinds = vim.lsp.protocol.CompletionItemKind
634+
635+
for i, kind in ipairs(kinds) do
636+
kinds[i] = (lspkind.symbolic(kind, {
637+
mode = 'symbol',
638+
}) or '') .. ' ' .. kind
639+
end
640+
end
641+
626642
vim.api.nvim_create_autocmd('LspAttach', {
627643
group = vim.api.nvim_create_augroup('kickstart-lsp-completion', { clear = true }),
628644
callback = function(event)
629-
local function keymap(lhs, rhs, opts, mode)
630-
opts = type(opts) == 'string' and { desc = opts } or vim.tbl_extend('error', opts --[[@as table]], { buffer = event.buf })
631-
mode = mode or 'n'
632-
vim.keymap.set(mode, lhs, rhs, opts)
633-
end
634-
635-
local function feedkeys(keys)
636-
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(keys, true, false, true), 'n', true)
637-
end
638-
639-
---Is the completion menu open?
640-
local function pumvisible()
641-
return tonumber(vim.fn.pumvisible()) ~= 0
642-
end
643-
644645
local client = vim.lsp.get_client_by_id(event.data.client_id)
646+
645647
if client and client:supports_method 'textDocument/completion' then
646648
vim.lsp.completion.enable(true, client.id, event.buf, { autotrigger = true })
647-
648-
-- Use enter to accept completions.
649-
keymap('<cr>', function()
650-
return pumvisible() and '<C-y>' or '<cr>'
651-
end, { expr = true }, 'i')
652-
653-
-- Use slash to dismiss the completion menu.
654-
keymap('/', function()
655-
return pumvisible() and '<C-e>' or '/'
656-
end, { expr = true }, 'i')
657-
658-
-- Use <C-n> to navigate to the next completion or:
659-
-- - Trigger LSP completion.
660-
-- - If there's no one, fallback to vanilla omnifunc.
661-
keymap('<C-n>', function()
662-
if pumvisible() then
663-
feedkeys '<C-n>'
664-
else
665-
if next(vim.lsp.get_clients { bufnr = 0 }) then
666-
vim.lsp.completion.trigger()
667-
else
668-
if vim.bo.omnifunc == '' then
669-
feedkeys '<C-x><C-n>'
670-
else
671-
feedkeys '<C-x><C-o>'
672-
end
673-
end
674-
end
675-
end, 'Trigger/select next completion', 'i')
676-
677-
-- Buffer completions.
678-
keymap('<C-u>', '<C-x><C-n>', { desc = 'Buffer completions' }, 'i')
679-
680-
-- Use <Tab> to accept a Copilot suggestion, navigate between snippet tabstops,
681-
-- or select the next completion.
682-
-- Do something similar with <S-Tab>.
683-
keymap('<Tab>', function()
684-
local copilot = require 'copilot.suggestion'
685-
686-
if copilot.is_visible() then
687-
copilot.accept()
688-
elseif pumvisible() then
689-
feedkeys '<C-n>'
690-
elseif vim.snippet.active { direction = 1 } then
691-
vim.snippet.jump(1)
692-
else
693-
feedkeys '<Tab>'
694-
end
695-
end, {}, { 'i', 's' })
696-
keymap('<S-Tab>', function()
697-
if pumvisible() then
698-
feedkeys '<C-p>'
699-
elseif vim.snippet.active { direction = -1 } then
700-
vim.snippet.jump(-1)
701-
else
702-
feedkeys '<S-Tab>'
703-
end
704-
end, {}, { 'i', 's' })
705-
706-
-- Inside a snippet, use backspace to remove the placeholder.
707-
keymap('<BS>', '<C-o>s', {}, 's')
708649
end
709650
end,
710651
})
@@ -861,124 +802,6 @@ require('lazy').setup({
861802
},
862803
},
863804

864-
-- { -- Autocompletion
865-
-- 'hrsh7th/nvim-cmp',
866-
-- event = 'InsertEnter',
867-
-- dependencies = {
868-
-- -- Snippet Engine & its associated nvim-cmp source
869-
-- {
870-
-- 'L3MON4D3/LuaSnip',
871-
-- build = (function()
872-
-- -- Build Step is needed for regex support in snippets.
873-
-- -- This step is not supported in many windows environments.
874-
-- -- Remove the below condition to re-enable on windows.
875-
-- if vim.fn.has 'win32' == 1 or vim.fn.executable 'make' == 0 then
876-
-- return
877-
-- end
878-
-- return 'make install_jsregexp'
879-
-- end)(),
880-
-- dependencies = {
881-
-- -- `friendly-snippets` contains a variety of premade snippets.
882-
-- -- See the README about individual language/framework/plugin snippets:
883-
-- -- https://github.com/rafamadriz/friendly-snippets
884-
-- -- {
885-
-- -- 'rafamadriz/friendly-snippets',
886-
-- -- config = function()
887-
-- -- require('luasnip.loaders.from_vscode').lazy_load()
888-
-- -- end,
889-
-- -- },
890-
-- },
891-
-- },
892-
-- 'saadparwaiz1/cmp_luasnip',
893-
--
894-
-- -- Adds other completion capabilities.
895-
-- -- nvim-cmp does not ship with all sources by default. They are split
896-
-- -- into multiple repos for maintenance purposes.
897-
-- 'hrsh7th/cmp-nvim-lsp',
898-
-- 'hrsh7th/cmp-path',
899-
-- 'hrsh7th/cmp-nvim-lsp-signature-help',
900-
-- },
901-
-- config = function()
902-
-- -- See `:help cmp`
903-
-- local cmp = require 'cmp'
904-
-- local luasnip = require 'luasnip'
905-
-- luasnip.config.setup {}
906-
--
907-
-- cmp.setup {
908-
-- snippet = {
909-
-- expand = function(args)
910-
-- luasnip.lsp_expand(args.body)
911-
-- end,
912-
-- },
913-
-- completion = { completeopt = 'menu,menuone,noinsert' },
914-
--
915-
-- -- For an understanding of why these mappings were
916-
-- -- chosen, you will need to read `:help ins-completion`
917-
-- --
918-
-- -- No, but seriously. Please read `:help ins-completion`, it is really good!
919-
-- mapping = cmp.mapping.preset.insert {
920-
-- -- Select the [n]ext item
921-
-- ['<C-n>'] = cmp.mapping.select_next_item(),
922-
-- -- Select the [p]revious item
923-
-- ['<C-p>'] = cmp.mapping.select_prev_item(),
924-
--
925-
-- -- Scroll the documentation window [b]ack / [f]orward
926-
-- ['<C-b>'] = cmp.mapping.scroll_docs(-4),
927-
-- ['<C-f>'] = cmp.mapping.scroll_docs(4),
928-
--
929-
-- -- Accept ([y]es) the completion.
930-
-- -- This will auto-import if your LSP supports it.
931-
-- -- This will expand snippets if the LSP sent a snippet.
932-
-- ['<C-y>'] = cmp.mapping.confirm { select = true },
933-
--
934-
-- -- If you prefer more traditional completion keymaps,
935-
-- -- you can uncomment the following lines
936-
-- --['<CR>'] = cmp.mapping.confirm { select = true },
937-
-- --['<Tab>'] = cmp.mapping.select_next_item(),
938-
-- --['<S-Tab>'] = cmp.mapping.select_prev_item(),
939-
--
940-
-- -- Manually trigger a completion from nvim-cmp.
941-
-- -- Generally you don't need this, because nvim-cmp will display
942-
-- -- completions whenever it has completion options available.
943-
-- ['<C-Space>'] = cmp.mapping.complete {},
944-
--
945-
-- -- Think of <c-l> as moving to the right of your snippet expansion.
946-
-- -- So if you have a snippet that's like:
947-
-- -- function $name($args)
948-
-- -- $body
949-
-- -- end
950-
-- --
951-
-- -- <c-l> will move you to the right of each of the expansion locations.
952-
-- -- <c-h> is similar, except moving you backwards.
953-
-- ['<C-l>'] = cmp.mapping(function()
954-
-- if luasnip.expand_or_locally_jumpable() then
955-
-- luasnip.expand_or_jump()
956-
-- end
957-
-- end, { 'i', 's' }),
958-
-- ['<C-h>'] = cmp.mapping(function()
959-
-- if luasnip.locally_jumpable(-1) then
960-
-- luasnip.jump(-1)
961-
-- end
962-
-- end, { 'i', 's' }),
963-
--
964-
-- -- For more advanced Luasnip keymaps (e.g. selecting choice nodes, expansion) see:
965-
-- -- https://github.com/L3MON4D3/LuaSnip?tab=readme-ov-file#keymaps
966-
-- },
967-
-- sources = {
968-
-- {
969-
-- name = 'lazydev',
970-
-- -- set group index to 0 to skip loading LuaLS completions as lazydev recommends it
971-
-- group_index = 0,
972-
-- },
973-
-- { name = 'nvim_lsp' },
974-
-- { name = 'luasnip' },
975-
-- { name = 'path' },
976-
-- { name = 'nvim_lsp_signature_help' },
977-
-- },
978-
-- }
979-
-- end,
980-
-- },
981-
982805
{ -- You can easily change to a different colorscheme.
983806
-- Change the name of the colorscheme plugin below, and then
984807
-- change the command in the config to whatever the name of that colorscheme is.

0 commit comments

Comments
 (0)