From 1f2ee194f28768572c2b1eb9f955e492531e9bba Mon Sep 17 00:00:00 2001 From: Fabio Lenherr / DashieTM Date: Sat, 13 May 2023 21:58:54 +0200 Subject: [PATCH] feat: finally solve ordering for cmp --- nvim/lua/config/keymaps.lua | 38 ++++++++++++++++++++++--------------- nvim/lua/plugins/cmp.lua | 34 ++++++++++++++------------------- nvim/lua/plugins/dap.lua | 26 ++++++++++++++++++++----- nvim/lua/plugins/lsp.lua | 12 +++--------- 4 files changed, 61 insertions(+), 49 deletions(-) diff --git a/nvim/lua/config/keymaps.lua b/nvim/lua/config/keymaps.lua index 2195b15..9961bd6 100644 --- a/nvim/lua/config/keymaps.lua +++ b/nvim/lua/config/keymaps.lua @@ -81,14 +81,23 @@ function _G.set_terminal_maps() vim.keymap.set("i", "", function() require("toggleterm").toggle(1) end, opts) + vim.keymap.set("t", "", function() + require("toggleterm").toggle(1) + end, opts) end -- if you only want these mappings for toggle term use term://*toggleterm#* instead vim.cmd("autocmd! TermOpen term://* lua set_terminal_maps()") -map("n", "", ":wincmd h", opts) -map("n", "", ":wincmd j", opts) -map("n", "", ":wincmd k", opts) -map("n", "", ":wincmd l", opts) +map("t", "", [[wincmd h]], opts) +map("t", "", [[wincmd j]], opts) +map("t", "", [[wincmd k]], opts) +map("t", "", [[wincmd l]], opts) +map("n", "", [[wincmd h]], opts) +map("n", "", [[wincmd l]], opts) +map("n", "", [[wincmd j]], opts) +map("i", "", [[wincmd h]], opts) +map("i", "", [[wincmd l]], opts) +map("i", "", [[wincmd j]], opts) -- harpoon man map("n", "h1", function() @@ -116,7 +125,7 @@ map("n", "ff", function() require("telescope.builtin").find_files() end, { desc = "Find Files" }) map("n", "fg", function() - live_grep_from_project_git_root() + Live_grep_from_project_git_root() end, { desc = "Live Grep (root)" }) map("n", "fG", function() require("telescope.builtin").live_grep() @@ -167,25 +176,24 @@ end) vim.g.neovide_input_use_logo = 1 vim.api.nvim_set_keymap("i", "", "pI", { noremap = true, silent = true }) -function live_grep_from_project_git_root() +function Get_git_root() + local opts = {} local function is_git_repo() vim.fn.system("git rev-parse --is-inside-work-tree") return vim.v.shell_error == 0 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 + local dot_git_path = vim.fn.finddir(".git", ".;") + local root = vim.fn.fnamemodify(dot_git_path, ":h") opts = { - cwd = get_git_root(), + cwd = root, } end + return opts +end +function Live_grep_from_project_git_root() + local opts = Get_git_root() require("telescope.builtin").live_grep(opts) end diff --git a/nvim/lua/plugins/cmp.lua b/nvim/lua/plugins/cmp.lua index d21fe7a..7de8404 100644 --- a/nvim/lua/plugins/cmp.lua +++ b/nvim/lua/plugins/cmp.lua @@ -3,7 +3,7 @@ return { "L3MON4D3/LuaSnip", 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" - or nil, + or nil, dependencies = { "rafamadriz/friendly-snippets", config = function() @@ -37,7 +37,7 @@ return { opts = function() local cmp = require("cmp") local luasnip = require("luasnip") - local compare = require('cmp.config.compare') + local compare = require("cmp.config.compare") return { preselect = cmp.PreselectMode.None, completion = { @@ -98,28 +98,22 @@ return { "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({ { name = "nvim_lsp", priority = 99 }, - { name = "luasnip", priority = 10, max_item_count = 3 }, - { name = "buffer", priority = 5, max_item_count = 2, keyword_length = 5 }, - { name = "async_path", priority = 0, max_item_count = 2, keyword_length = 3, trigger_characters = {} }, + { name = "luasnip", priority = 3, max_item_count = 3 }, + { name = "buffer", priority = 2, max_item_count = 2, keyword_length = 5 }, + { name = "async_path", priority = 1, max_item_count = 2, keyword_length = 3, trigger_characters = {} }, { name = "crates" }, }), + sorting = { + priority_weight = 1, + comparators = { + compare.exact, + compare.score, + compare.offset, + compare.kind, + }, + }, formatting = { preselect = cmp.PreselectMode.None, format = function(entry, item) diff --git a/nvim/lua/plugins/dap.lua b/nvim/lua/plugins/dap.lua index cd6b24e..1c1eb60 100644 --- a/nvim/lua/plugins/dap.lua +++ b/nvim/lua/plugins/dap.lua @@ -46,7 +46,7 @@ return { name = "bashdb", } - local rust_dap = vim.fn.getcwd() + local rust_dap = Get_git_root().cwd local filename = "" for w in rust_dap:gmatch("([^/]+)") do filename = w @@ -61,8 +61,26 @@ return { end, --program = '${fileDirname}/${fileBasenameNoExtension}', cwd = "${workspaceFolder}", - stopOnEntry = true, 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", request = "launch", 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, cwd = "${workspaceFolder}", - stopOnEntry = true, terminal = "integrated", }, } @@ -253,4 +270,3 @@ return { end, }, } - diff --git a/nvim/lua/plugins/lsp.lua b/nvim/lua/plugins/lsp.lua index ef76387..e9aa528 100644 --- a/nvim/lua/plugins/lsp.lua +++ b/nvim/lua/plugins/lsp.lua @@ -4,8 +4,8 @@ return { lazy = true, event = { "BufReadPre", "BufNewFile" }, dependencies = { - { "folke/neoconf.nvim", cmd = "Neoconf", config = true }, - { "folke/neodev.nvim", opts = { experimental = { pathStrict = true } } }, + { "folke/neoconf.nvim", cmd = "Neoconf", config = true }, + { "folke/neodev.nvim", opts = { experimental = { pathStrict = true } } }, "mason.nvim", "williamboman/mason-lspconfig.nvim", "lvimuser/lsp-inlayhints.nvim", @@ -70,13 +70,6 @@ return { marksman = {}, asm_lsp = {}, omnisharp = {}, - -- csharp_ls = { - -- cmd = { "/home/dashie/.local/share/nvim/mason/bin/csharp-ls" }, - -- filetypes = { "cs" }, - -- init_options = { - -- AutomaticWorkspaceInit = true, - -- }, - -- }, tsserver = { settings = { typescript = { @@ -176,6 +169,7 @@ return { local capabilities = require("cmp_nvim_lsp").default_capabilities(vim.lsp.protocol.make_client_capabilities()) 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, "tagfunc", "v:lua.vim.lsp.tagfunc") local optslsp = { noremap = false, silent = true, buffer = bufnr } require("lsp-inlayhints").on_attach(client, bufnr) -- keymaps