Skip to content

Commit

Permalink
Finished?
Browse files Browse the repository at this point in the history
  • Loading branch information
lipeeeee committed Apr 5, 2024
1 parent f4c5e0e commit 7351650
Show file tree
Hide file tree
Showing 4 changed files with 215 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lua/lipe/plugins/lsp.bak/cmp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ return {
"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
"windwp/nvim-autopairs", -- Autopair
},
config = function()
local cmp = require("cmp")
Expand Down
135 changes: 135 additions & 0 deletions lua/lipe/plugins/lsp/cmp.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
return {
{
"hrsh7th/nvim-cmp",
-- event = "InsertEnter", -- lazy-load this if want a faster startup time
dependencies = {
"L3MON4D3/LuaSnip", -- Snippet engine
"saadparwaiz1/cmp_luasnip", -- Snippet completion
"hrsh7th/cmp-buffer", -- Buffer completion
"hrsh7th/cmp-path", -- Path completion
"hrsh7th/cmp-nvim-lsp", -- LSP completion
"onsails/lspkind.nvim", -- LSP completion formatter
"windwp/nvim-autopairs", -- Autopair
},
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,
},

}
18 changes: 18 additions & 0 deletions lua/lipe/plugins/lsp/snippets.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
return {
{
"rafamadriz/friendly-snippets",
lazy = true, -- luasnip will load friendly-snippets
},
{
"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
},
}
61 changes: 61 additions & 0 deletions lua/lipe/plugins/lsp/trouble.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
return {
"folke/trouble.nvim",
cmd = "TroubleToggle",
dependencies = { "nvim-tree/nvim-web-devicons" },
opts = {
position = "bottom", -- position of the list can be: bottom, top, left, right
height = 10, -- height of the trouble list when position is top or bottom
width = 50, -- width of the list when position is left or right
icons = true, -- use devicons for filenames
mode = "workspace_diagnostics", -- "workspace_diagnostics", "document_diagnostics", "quickfix", "lsp_references", "loclist"
severity = nil, -- nil (ALL) or vim.diagnostic.severity.ERROR | WARN | INFO | HINT
fold_open = "", -- icon used for open folds
fold_closed = "", -- icon used for closed folds
group = true, -- group results by file
padding = true, -- add an extra new line on top of the list
cycle_results = true, -- cycle item list when reaching beginning or end of list
action_keys = { -- key mappings for actions in the trouble list

-- map to {} to remove a mapping, for example:
-- close = {},
close = "q", -- close the list
cancel = "<esc>", -- cancel the preview and get back to your last window / buffer / cursor
refresh = "r", -- manually refresh
jump = { "<cr>", "<tab>", "<2-leftmouse>" }, -- jump to the diagnostic or open / close folds
open_split = { "<c-x>" }, -- open buffer in new split
open_vsplit = { "<c-v>" }, -- open buffer in new vsplit
open_tab = { "<c-t>" }, -- open buffer in new tab
jump_close = { "o" }, -- jump to the diagnostic and close the list
toggle_mode = "m", -- toggle between "workspace" and "document" diagnostics mode
switch_severity = "s", -- switch "diagnostics" severity filter level to HINT / INFO / WARN / ERROR
toggle_preview = "P", -- toggle auto_preview
hover = "K", -- opens a small popup with the full multiline message
preview = "p", -- preview the diagnostic location
open_code_href = "c", -- if present, open a URI with more information about the diagnostic error
close_folds = { "zM", "zm" }, -- close all folds
open_folds = { "zR", "zr" }, -- open all folds
toggle_fold = { "zA", "za" }, -- toggle fold of current file
previous = "k", -- previous item
next = "j", -- next item
help = "?" -- help menu
},
multiline = true, -- render multi-line messages
indent_lines = true, -- add an indent guide below the fold icons
win_config = { border = "single" }, -- window configuration for floating windows. See |nvim_open_win()|.
auto_open = false, -- automatically open the list when you have diagnostics
auto_close = false, -- automatically close the list when you have no diagnostics
auto_preview = true, -- automatically preview the location of the diagnostic. <esc> to close preview and go back to last window
auto_fold = false, -- automatically fold a file trouble list at creation
auto_jump = { "lsp_definitions" }, -- for the given modes, automatically jump if there is only a single result
include_declaration = { "lsp_references", "lsp_implementations", "lsp_definitions" }, -- for the given modes, include the declaration of the current symbol in the results
signs = {
-- icons / text used for a diagnostic
error = ICONS.diagnostics.Error,
warning = ICONS.diagnostics.Warning,
hint = ICONS.diagnostics.Hint,
information = ICONS.diagnostics.Information,
other = ICONS.diagnostics.Information,
},
use_diagnostic_signs = false -- enabling this will use the signs defined in your lsp client
},
}

0 comments on commit 7351650

Please sign in to comment.