feat: finally solve ordering for cmp

This commit is contained in:
Fabio Lenherr / DashieTM 2023-05-13 21:58:54 +02:00
parent 1507a66da0
commit 1f2ee194f2
4 changed files with 61 additions and 49 deletions

View file

@ -81,14 +81,23 @@ function _G.set_terminal_maps()
vim.keymap.set("i", "<C-t>", function() vim.keymap.set("i", "<C-t>", function()
require("toggleterm").toggle(1) require("toggleterm").toggle(1)
end, opts) end, opts)
vim.keymap.set("t", "<C-t>", function()
require("toggleterm").toggle(1)
end, opts)
end end
-- if you only want these mappings for toggle term use term://*toggleterm#* instead -- if you only want these mappings for toggle term use term://*toggleterm#* instead
vim.cmd("autocmd! TermOpen term://* lua set_terminal_maps()") vim.cmd("autocmd! TermOpen term://* lua set_terminal_maps()")
map("n", "<A-j>", ":wincmd h<CR>", opts) map("t", "<A-j>", [[<Cmd>wincmd h<CR>]], opts)
map("n", "<A-k>", ":wincmd j<CR>", opts) map("t", "<A-k>", [[<Cmd>wincmd j<CR>]], opts)
map("n", "<A-l>", ":wincmd k<CR>", opts) map("t", "<A-l>", [[<Cmd>wincmd k<CR>]], opts)
map("n", "<A-;>", ":wincmd l<CR>", opts) map("t", "<A-;>", [[<Cmd>wincmd l<CR>]], opts)
map("n", "<A-j>", [[<Cmd>wincmd h<CR>]], opts)
map("n", "<A-;>", [[<Cmd>wincmd l<CR>]], opts)
map("n", "<A-t>", [[<Cmd>wincmd j<CR>]], opts)
map("i", "<A-j>", [[<Cmd>wincmd h<CR>]], opts)
map("i", "<A-;>", [[<Cmd>wincmd l<CR>]], opts)
map("i", "<A-k>", [[<Cmd>wincmd j<CR>]], opts)
-- harpoon man -- harpoon man
map("n", "<leader>h1", function() map("n", "<leader>h1", function()
@ -116,7 +125,7 @@ map("n", "<leader>ff", function()
require("telescope.builtin").find_files() require("telescope.builtin").find_files()
end, { desc = "Find Files" }) end, { desc = "Find Files" })
map("n", "<leader>fg", function() map("n", "<leader>fg", function()
live_grep_from_project_git_root() Live_grep_from_project_git_root()
end, { desc = "Live Grep (root)" }) end, { desc = "Live Grep (root)" })
map("n", "<leader>fG", function() map("n", "<leader>fG", function()
require("telescope.builtin").live_grep() require("telescope.builtin").live_grep()
@ -167,25 +176,24 @@ end)
vim.g.neovide_input_use_logo = 1 vim.g.neovide_input_use_logo = 1
vim.api.nvim_set_keymap("i", "<C-S-V>", "<ESC>p<CR>I", { noremap = true, silent = true }) vim.api.nvim_set_keymap("i", "<C-S-V>", "<ESC>p<CR>I", { noremap = true, silent = true })
function live_grep_from_project_git_root() function Get_git_root()
local opts = {}
local function is_git_repo() local function is_git_repo()
vim.fn.system("git rev-parse --is-inside-work-tree") vim.fn.system("git rev-parse --is-inside-work-tree")
return vim.v.shell_error == 0 return vim.v.shell_error == 0
end end
local function get_git_root()
local dot_git_path = vim.fn.finddir(".git", ".;")
return vim.fn.fnamemodify(dot_git_path, ":h")
end
local opts = {}
if is_git_repo() then if is_git_repo() then
local dot_git_path = vim.fn.finddir(".git", ".;")
local root = vim.fn.fnamemodify(dot_git_path, ":h")
opts = { opts = {
cwd = get_git_root(), cwd = root,
} }
end end
return opts
end
function Live_grep_from_project_git_root()
local opts = Get_git_root()
require("telescope.builtin").live_grep(opts) require("telescope.builtin").live_grep(opts)
end end

View file

@ -3,7 +3,7 @@ return {
"L3MON4D3/LuaSnip", "L3MON4D3/LuaSnip",
build = (not jit.os:find("Windows")) build = (not jit.os:find("Windows"))
and "echo -e 'NOTE: jsregexp is optional, so not a big deal if it fails to build\n'; make install_jsregexp" and "echo -e 'NOTE: jsregexp is optional, so not a big deal if it fails to build\n'; make install_jsregexp"
or nil, or nil,
dependencies = { dependencies = {
"rafamadriz/friendly-snippets", "rafamadriz/friendly-snippets",
config = function() config = function()
@ -37,7 +37,7 @@ return {
opts = function() opts = function()
local cmp = require("cmp") local cmp = require("cmp")
local luasnip = require("luasnip") local luasnip = require("luasnip")
local compare = require('cmp.config.compare') local compare = require("cmp.config.compare")
return { return {
preselect = cmp.PreselectMode.None, preselect = cmp.PreselectMode.None,
completion = { completion = {
@ -98,28 +98,22 @@ return {
"s", "s",
}), }),
}, },
sorting = {
priority_weight = 2,
comparators = {
compare.offset,
compare.exact,
-- compare.scopes,
compare.kind,
compare.score,
compare.recently_used,
compare.locality,
-- compare.sort_text,
compare.length,
compare.order,
},
},
sources = cmp.config.sources({ sources = cmp.config.sources({
{ name = "nvim_lsp", priority = 99 }, { name = "nvim_lsp", priority = 99 },
{ name = "luasnip", priority = 10, max_item_count = 3 }, { name = "luasnip", priority = 3, max_item_count = 3 },
{ name = "buffer", priority = 5, max_item_count = 2, keyword_length = 5 }, { name = "buffer", priority = 2, max_item_count = 2, keyword_length = 5 },
{ name = "async_path", priority = 0, max_item_count = 2, keyword_length = 3, trigger_characters = {} }, { name = "async_path", priority = 1, max_item_count = 2, keyword_length = 3, trigger_characters = {} },
{ name = "crates" }, { name = "crates" },
}), }),
sorting = {
priority_weight = 1,
comparators = {
compare.exact,
compare.score,
compare.offset,
compare.kind,
},
},
formatting = { formatting = {
preselect = cmp.PreselectMode.None, preselect = cmp.PreselectMode.None,
format = function(entry, item) format = function(entry, item)

View file

@ -46,7 +46,7 @@ return {
name = "bashdb", name = "bashdb",
} }
local rust_dap = vim.fn.getcwd() local rust_dap = Get_git_root().cwd
local filename = "" local filename = ""
for w in rust_dap:gmatch("([^/]+)") do for w in rust_dap:gmatch("([^/]+)") do
filename = w filename = w
@ -61,8 +61,26 @@ return {
end, end,
--program = '${fileDirname}/${fileBasenameNoExtension}', --program = '${fileDirname}/${fileBasenameNoExtension}',
cwd = "${workspaceFolder}", cwd = "${workspaceFolder}",
stopOnEntry = true,
terminal = "integrated", terminal = "integrated",
initCommands = function()
-- Find out where to look for the pretty printer Python module
local rustc_sysroot = vim.fn.trim(vim.fn.system("rustc --print sysroot"))
local script_import = 'command script import "' .. rustc_sysroot .. '/lib/rustlib/etc/lldb_lookup.py"'
local commands_file = rustc_sysroot .. "/lib/rustlib/etc/lldb_commands"
local commands = {}
local file = io.open(commands_file, "r")
if file then
for line in file:lines() do
table.insert(commands, line)
end
file:close()
end
table.insert(commands, 1, script_import)
return commands
end,
}, },
} }
@ -72,10 +90,9 @@ return {
type = "lldb", type = "lldb",
request = "launch", request = "launch",
program = function() program = function()
return vim.fn.input("Path to executable: ", vim.fn.getcwd() .. "/build/", "file") return vim.fn.input("Path to executable: ", Get_git_root().cwd .. "/build/", "file")
end, end,
cwd = "${workspaceFolder}", cwd = "${workspaceFolder}",
stopOnEntry = true,
terminal = "integrated", terminal = "integrated",
}, },
} }
@ -253,4 +270,3 @@ return {
end, end,
}, },
} }

View file

@ -4,8 +4,8 @@ return {
lazy = true, lazy = true,
event = { "BufReadPre", "BufNewFile" }, event = { "BufReadPre", "BufNewFile" },
dependencies = { dependencies = {
{ "folke/neoconf.nvim", cmd = "Neoconf", config = true }, { "folke/neoconf.nvim", cmd = "Neoconf", config = true },
{ "folke/neodev.nvim", opts = { experimental = { pathStrict = true } } }, { "folke/neodev.nvim", opts = { experimental = { pathStrict = true } } },
"mason.nvim", "mason.nvim",
"williamboman/mason-lspconfig.nvim", "williamboman/mason-lspconfig.nvim",
"lvimuser/lsp-inlayhints.nvim", "lvimuser/lsp-inlayhints.nvim",
@ -70,13 +70,6 @@ return {
marksman = {}, marksman = {},
asm_lsp = {}, asm_lsp = {},
omnisharp = {}, omnisharp = {},
-- csharp_ls = {
-- cmd = { "/home/dashie/.local/share/nvim/mason/bin/csharp-ls" },
-- filetypes = { "cs" },
-- init_options = {
-- AutomaticWorkspaceInit = true,
-- },
-- },
tsserver = { tsserver = {
settings = { settings = {
typescript = { typescript = {
@ -176,6 +169,7 @@ return {
local capabilities = require("cmp_nvim_lsp").default_capabilities(vim.lsp.protocol.make_client_capabilities()) local capabilities = require("cmp_nvim_lsp").default_capabilities(vim.lsp.protocol.make_client_capabilities())
local on_attach = function(client, bufnr) local on_attach = function(client, bufnr)
vim.api.nvim_buf_set_option(bufnr, "omnifunc", "v:lua.vim.lsp.omnifunc") vim.api.nvim_buf_set_option(bufnr, "omnifunc", "v:lua.vim.lsp.omnifunc")
vim.api.nvim_buf_set_option(bufnr, "tagfunc", "v:lua.vim.lsp.tagfunc")
local optslsp = { noremap = false, silent = true, buffer = bufnr } local optslsp = { noremap = false, silent = true, buffer = bufnr }
require("lsp-inlayhints").on_attach(client, bufnr) require("lsp-inlayhints").on_attach(client, bufnr)
-- keymaps -- keymaps