Skip to content

Commit

Permalink
init refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
lipeeeee committed Apr 4, 2024
1 parent 5364b91 commit f4c5e0e
Show file tree
Hide file tree
Showing 5 changed files with 216 additions and 147 deletions.
147 changes: 147 additions & 0 deletions lua/lipe/plugins/lsp.bak/cmp.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
-- Handles everything cmp related
return {
{
"L3MON4D3/LuaSnip",
version = "v2.*",
lazy = true, -- nvim-cmp will load luasnip
dependencies = {
"rafamadriz/friendly-snippets",
},
config = function()
require("luasnip/loaders/from_vscode").lazy_load()
end,
build = "make install_jsregexp", -- Optional
},
{
"hrsh7th/nvim-cmp",
event = "InsertEnter",
dependencies = {
"L3MON4D3/LuaSnip", -- Snippet engine
"saadparwaiz1/cmp_luasnip", -- Snippet completion
"hrsh7th/cmp-buffer", -- Buffer completion
"hrsh7th/cmp-path", -- Path completion
"windwp/nvim-autopairs", -- Autopair
"hrsh7th/cmp-nvim-lsp", -- LSP completion
"onsails/lspkind.nvim", -- LSP completion formatter
},
config = function()
local cmp = require("cmp")
local luasnip = require("luasnip")

-- Utility function to check backspace in "magic tab snippet"
local check_backspace = function()
local col = vim.fn.col "." - 1
return col == 0 or vim.fn.getline("."):sub(col, col):match "%s"
end

cmp.setup {
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
mapping = {
["<C-k>"] = cmp.mapping.select_prev_item(),
["<C-j>"] = cmp.mapping.select_next_item(),
["<C-b>"] = cmp.mapping(cmp.mapping.scroll_docs(-1), { "i", "c" }),
["<C-f>"] = cmp.mapping(cmp.mapping.scroll_docs(1), { "i", "c" }),
["<C-Space>"] = cmp.mapping(cmp.mapping.complete(), { "i", "c" }),
["<C-y>"] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `<C-y>` mapping.
["<C-e>"] = cmp.mapping {
i = cmp.mapping.abort(),
c = cmp.mapping.close(),
},
-- Accept currently selected item. If none selected, `select` first item.
-- Set `select` to `false` to only confirm explicitly selected items.
["<CR>"] = cmp.mapping.confirm { select = true },
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expandable() then
luasnip.expand()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
elseif check_backspace() then
fallback()
else
fallback()
end
end, {
"i",
"s",
}),
["<S-Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, {
"i",
"s",
}),
},
formatting = {
fields = { "kind", "abbr", "menu" },
format = function(entry, vim_item)
local kind = require("lspkind").cmp_format({ mode = "symbol_text", maxwidth = 50 })(entry, vim_item)
local strings = vim.split(kind.kind, "%s", { trimempty = true })
kind.kind = " " .. (strings[1] or "") .. " "
kind.menu = " (" .. (strings[2] or "") .. ")"

return kind
end,
},
sources = {
{ name = "nvim_lsp" },
{ name = "luasnip" },
{ name = "buffer" },
{ name = "path" },
},
confirm_opts = {
behavior = cmp.ConfirmBehavior.Replace,
select = false,
},
window = {
completion = cmp.config.window.bordered({
border = "single",
}),
documentation = cmp.config.window.bordered({
border = { "", "", "", "", "", "", "", "" },
}),
},
experimental = {
ghost_text = false,
native_menu = false,
},
}

-- Link autocompt with cmp
local cmp_autopairs = require('nvim-autopairs.completion.cmp')
cmp.event:on(
'confirm_done',
cmp_autopairs.on_confirm_done()
)

-- -- gray
-- vim.api.nvim_set_hl(0, 'CmpItemAbbrDeprecated', { bg = 'NONE', strikethrough = true, fg = '#808080' })
-- -- blue
-- vim.api.nvim_set_hl(0, 'CmpItemAbbrMatch', { bg = 'NONE', fg = '#569CD6' })
-- vim.api.nvim_set_hl(0, 'CmpItemAbbrMatchFuzzy', { link = 'CmpIntemAbbrMatch' })
-- -- light blue
-- vim.api.nvim_set_hl(0, 'CmpItemKindVariable', { bg = 'NONE', fg = '#9CDCFE' })
-- vim.api.nvim_set_hl(0, 'CmpItemKindVariable', { bg = 'NONE', fg = '#FF00FF' })
-- vim.api.nvim_set_hl(0, 'CmpItemKindInterface', { link = 'CmpItemKindVariable' })
-- vim.api.nvim_set_hl(0, 'CmpItemKindText', { link = 'CmpItemKindVariable' })
-- -- pink
-- vim.api.nvim_set_hl(0, 'CmpItemKindFunction', { bg = 'NONE', fg = '#C586C0' })
-- vim.api.nvim_set_hl(0, 'CmpItemKindMethod', { link = 'CmpItemKindFunction' })
-- -- front
-- vim.api.nvim_set_hl(0, 'CmpItemKindKeyword', { bg = 'NONE', fg = '#D4D4D4' })
-- vim.api.nvim_set_hl(0, 'CmpItemKindProperty', { link = 'CmpItemKindKeyword' })
-- vim.api.nvim_set_hl(0, 'CmpItemKindUnit', { link = 'CmpItemKindKeyword' })
end,
},
}
69 changes: 69 additions & 0 deletions lua/lipe/plugins/lsp.bak/lsp.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
-- Handles config for core lsp packages:
-- nvim-lspconfig, mason, mason-lspconfig
return {
{
"neovim/nvim-lspconfig",
lazy = true, -- mason-lspconfig will load this
},
{
"williamboman/mason.nvim",
lazy = true, -- mason-lspconfig will load this
config = function()
local mason = require("mason")

mason.setup({
ui = {
icons = {
package_installed = ICONS.ui.Check,
package_pending = ICONS.ui.BoldArrowRight,
package_uninstalled = ICONS.ui.Close
}
},
})
end,
},
{
"williamboman/mason-lspconfig.nvim",
dependencies = {
"neovim/nvim-lspconfig",
"williamboman/mason.nvim",
},
config = function()
local mason_lspconfig = require("mason-lspconfig")
local lspconfig = require("lspconfig")
-- mason-lspconfig Setup
local ensure_installed = require("lipe.lsp.servers")
mason_lspconfig.setup({
ensure_installed = ensure_installed,
automatic_installation = true,
})

-- Handlers & server options
local handlers = require("lipe.lsp.handlers")
local opts = {
on_attach = handlers.on_attach,
capabilities = handlers.capabilities
}

-- Specific server options
for _, server in pairs(ensure_installed) do
-- Reset opts just in case they were extended
opts = {
on_attach = handlers.on_attach,
capabilities = handlers.capabilities
}

server = vim.split(server, "@")[1]

local require_ok, conf_opts = pcall(require, ("lipe.lsp.settings." .. server))
if require_ok then
opts = vim.tbl_deep_extend("force", conf_opts, opts)
end

lspconfig[server].setup(opts)
end

handlers.setup()
end,
},
}
File renamed without changes.
File renamed without changes.
147 changes: 0 additions & 147 deletions lua/lipe/plugins/lsp/cmp.lua
Original file line number Diff line number Diff line change
@@ -1,147 +0,0 @@
-- Handles everything cmp related
return {
{
"L3MON4D3/LuaSnip",
version = "v2.*",
lazy = true, -- nvim-cmp will load luasnip
dependencies = {
"rafamadriz/friendly-snippets",
},
config = function()
require("luasnip/loaders/from_vscode").lazy_load()
end,
build = "make install_jsregexp", -- Optional
},
{
"hrsh7th/nvim-cmp",
event = "InsertEnter",
dependencies = {
"L3MON4D3/LuaSnip", -- Snippet engine
"saadparwaiz1/cmp_luasnip", -- Snippet completion
"hrsh7th/cmp-buffer", -- Buffer completion
"hrsh7th/cmp-path", -- Path completion
"windwp/nvim-autopairs", -- Autopair
"hrsh7th/cmp-nvim-lsp", -- LSP completion
"onsails/lspkind.nvim", -- LSP completion formatter
},
config = function()
local cmp = require("cmp")
local luasnip = require("luasnip")

-- Utility function to check backspace in "magic tab snippet"
local check_backspace = function()
local col = vim.fn.col "." - 1
return col == 0 or vim.fn.getline("."):sub(col, col):match "%s"
end

cmp.setup {
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
mapping = {
["<C-k>"] = cmp.mapping.select_prev_item(),
["<C-j>"] = cmp.mapping.select_next_item(),
["<C-b>"] = cmp.mapping(cmp.mapping.scroll_docs(-1), { "i", "c" }),
["<C-f>"] = cmp.mapping(cmp.mapping.scroll_docs(1), { "i", "c" }),
["<C-Space>"] = cmp.mapping(cmp.mapping.complete(), { "i", "c" }),
["<C-y>"] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `<C-y>` mapping.
["<C-e>"] = cmp.mapping {
i = cmp.mapping.abort(),
c = cmp.mapping.close(),
},
-- Accept currently selected item. If none selected, `select` first item.
-- Set `select` to `false` to only confirm explicitly selected items.
["<CR>"] = cmp.mapping.confirm { select = true },
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expandable() then
luasnip.expand()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
elseif check_backspace() then
fallback()
else
fallback()
end
end, {
"i",
"s",
}),
["<S-Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, {
"i",
"s",
}),
},
formatting = {
fields = { "kind", "abbr", "menu" },
format = function(entry, vim_item)
local kind = require("lspkind").cmp_format({ mode = "symbol_text", maxwidth = 50 })(entry, vim_item)
local strings = vim.split(kind.kind, "%s", { trimempty = true })
kind.kind = " " .. (strings[1] or "") .. " "
kind.menu = " (" .. (strings[2] or "") .. ")"

return kind
end,
},
sources = {
{ name = "nvim_lsp" },
{ name = "luasnip" },
{ name = "buffer" },
{ name = "path" },
},
confirm_opts = {
behavior = cmp.ConfirmBehavior.Replace,
select = false,
},
window = {
completion = cmp.config.window.bordered({
border = "single",
}),
documentation = cmp.config.window.bordered({
border = { "", "", "", "", "", "", "", "" },
}),
},
experimental = {
ghost_text = false,
native_menu = false,
},
}

-- Link autocompt with cmp
local cmp_autopairs = require('nvim-autopairs.completion.cmp')
cmp.event:on(
'confirm_done',
cmp_autopairs.on_confirm_done()
)

-- -- gray
-- vim.api.nvim_set_hl(0, 'CmpItemAbbrDeprecated', { bg = 'NONE', strikethrough = true, fg = '#808080' })
-- -- blue
-- vim.api.nvim_set_hl(0, 'CmpItemAbbrMatch', { bg = 'NONE', fg = '#569CD6' })
-- vim.api.nvim_set_hl(0, 'CmpItemAbbrMatchFuzzy', { link = 'CmpIntemAbbrMatch' })
-- -- light blue
-- vim.api.nvim_set_hl(0, 'CmpItemKindVariable', { bg = 'NONE', fg = '#9CDCFE' })
-- vim.api.nvim_set_hl(0, 'CmpItemKindVariable', { bg = 'NONE', fg = '#FF00FF' })
-- vim.api.nvim_set_hl(0, 'CmpItemKindInterface', { link = 'CmpItemKindVariable' })
-- vim.api.nvim_set_hl(0, 'CmpItemKindText', { link = 'CmpItemKindVariable' })
-- -- pink
-- vim.api.nvim_set_hl(0, 'CmpItemKindFunction', { bg = 'NONE', fg = '#C586C0' })
-- vim.api.nvim_set_hl(0, 'CmpItemKindMethod', { link = 'CmpItemKindFunction' })
-- -- front
-- vim.api.nvim_set_hl(0, 'CmpItemKindKeyword', { bg = 'NONE', fg = '#D4D4D4' })
-- vim.api.nvim_set_hl(0, 'CmpItemKindProperty', { link = 'CmpItemKindKeyword' })
-- vim.api.nvim_set_hl(0, 'CmpItemKindUnit', { link = 'CmpItemKindKeyword' })
end,
},
}

0 comments on commit f4c5e0e

Please sign in to comment.