diff --git a/configs/nvim/init.lua b/configs/nvim/init.lua index a05b25c..dcbe2b5 100644 --- a/configs/nvim/init.lua +++ b/configs/nvim/init.lua @@ -32,6 +32,7 @@ end) later(function() add("neovim/nvim-lspconfig") add("stevearc/conform.nvim") + require("plugins.telescope") require("config.lsp") require("config.fmt") diff --git a/configs/nvim/lua/config/autocmds.lua b/configs/nvim/lua/config/autocmds.lua index 5d1fb95..098e30e 100644 --- a/configs/nvim/lua/config/autocmds.lua +++ b/configs/nvim/lua/config/autocmds.lua @@ -23,12 +23,3 @@ local function open_folder(data) end vim.api.nvim_create_autocmd({ "VimEnter" }, { callback = open_folder }) - --- For now I see no reason to update the plugins everytime I open neovim -- UPDATE: I do now, constantly having notifs abt outdated stuff is annoying -vim.api.nvim_create_autocmd("VimEnter", { - callback = function() - vim.defer_fn(function() - require("lazy").update({ show = false }) - end, 5000) - end, -}) diff --git a/configs/nvim/lua/config/lsp.lua b/configs/nvim/lua/config/lsp.lua index 8d4d449..5a41c30 100644 --- a/configs/nvim/lua/config/lsp.lua +++ b/configs/nvim/lua/config/lsp.lua @@ -1,39 +1,165 @@ -local servers = { "nil_ls", "rust_analyzer", "gleam", "lua_ls", "zls", "taplo", "tailwindcss", "cssls", "biome", "prettier" } - -for _, server in ipairs(servers) do - local config = vim.lsp.config[server] - - -- It failed to load w my careful approach so here we go just enabling all of em like yeet - vim.lsp.enable(server) - - if config and config.default_config then - local cmd = config.default_config.cmd - if cmd and cmd[1] and vim.fn.executable(cmd[1]) == 1 then - vim.lsp.config(server, { - root_dir = vim.fs.root( - 0, - { ".git", ".jj", "gleam.toml", "Cargo.toml", "package.json", "flake.nix", "default.nix" } - ) or vim.fn.getcwd(), - }) - vim.lsp.enable(server) - end - end -end - -vim.api.nvim_create_autocmd("LspAttach", { - callback = function(args) - local client = vim.lsp.get_client_by_id(args.data.client_id) - if - client - -- and client.supports_method("textDocument/completion") - then - vim.lsp.completion.enable(true, client.id, args.buf) - end - end, +vim.pack.add({ + { src = "https://github.com/neovim/nvim-lspconfig" }, + { src = "https://github.com/folke/lazydev.nvim" }, + { src = "https://github.com/Bilal2453/luvit-meta" }, + { src = "https://github.com/mason-org/mason.nvim" }, }) +local servers = { + "rust_analyzer", + "gleam", + "elp", + "zls", + "lua_ls", + + -- python + "ruff", + "ty", + + -- nix + "nil_ls", + + -- inclusivity + "woke", + + -- web + "prettier", + "biome", + "cssls", + -- "tailwindcss", + + -- rust + "rust_analyzer", + + -- markdown + "markdown_oxide", + + -- toml + "taplo", +} + +-- My poor setup +-- for _, server in ipairs(servers) do +-- local config = vim.lsp.config[server] +-- +-- -- It failed to load w my careful approach so here we go just enabling all of em like yeet +-- vim.lsp.enable(server) +-- +-- if config and config.default_config then +-- local cmd = config.default_config.cmd +-- if cmd and cmd[1] and vim.fn.executable(cmd[1]) == 1 then +-- vim.lsp.config(server, { +-- root_dir = vim.fs.root( +-- 0, +-- { ".git", ".jj", "gleam.toml", "Cargo.toml", "package.json", "flake.nix", "default.nix" } +-- ) or vim.fn.getcwd(), +-- }) +-- vim.lsp.enable(server) +-- end +-- end +-- end + +-- vim.api.nvim_create_autocmd("LspAttach", { +-- callback = function(args) +-- local client = vim.lsp.get_client_by_id(args.data.client_id) +-- if +-- client +-- -- and client.supports_method("textDocument/completion") +-- then +-- vim.lsp.completion.enable(true, client.id, args.buf) +-- end +-- end, +-- }) vim.opt.completeopt = { "menu", "menuone", "noselect" } vim.api.nvim_set_hl(0, "Pmenu", { bg = "#1f2335", fg = "#c0caf5" }) vim.api.nvim_set_hl(0, "PmenuSel", { bg = "#364a82", bold = true }) vim.opt.pumheight = 10 vim.opt.pumblend = 10 + +-- Setup I kinda stole from ollie +-- ...using lazydev because we both seem to be a lil lazy! +-- lazydev ----------------------------------------- +require("lazydev").setup({ + ft = "lua", + library = { + -- See the configuration section for more details + -- Load luvit types when the `vim.uv` word is found + { path = "${3rd}/luv/library", words = { "vim%.uv" } }, + }, +}) + +require("mason").setup({}) + +-- lsp setup --------------------------------------- +vim.lsp.enable(servers) + +-- keybinds / settings +vim.keymap.set("n", "ff", vim.lsp.buf.format, { desc = "Format File" }) + +vim.lsp.inlay_hint.enable(true) + +-- format on write +vim.api.nvim_create_autocmd("BufWritePre", { + callback = function(event) + vim.lsp.buf.format({ bufnr = event.buf }) + end, +}) + +vim.api.nvim_create_autocmd("LspAttach", { + group = vim.api.nvim_create_augroup("kickstart-lsp-attach", { clear = true }), + callback = function(event) + -- Function to map specific lsp related items + local map = function(keys, func, desc, mode) + mode = mode or "n" + vim.keymap.set(mode, keys, func, { buffer = event.buf, desc = "LSP: " .. desc }) + end + + map("gd", vim.lsp.buf.definition, "[G]oto [D]efinition") + map("gb", "''", "[G]o [B]ack") + map("gr", require("telescope.builtin").lsp_references, "[G]oto [R]eferences") + map("gI", require("telescope.builtin").lsp_implementations, "[G]oto [I]mplementation") + map("D", require("telescope.builtin").lsp_type_definitions, "Type [D]efinition") + map("ds", require("telescope.builtin").lsp_document_symbols, "[D]ocument [S]ymbols") + map("ws", require("telescope.builtin").lsp_dynamic_workspace_symbols, "[W]orkspace [S]ymbols") + map("rn", vim.lsp.buf.rename, "[R]e[n]ame") + map("ca", vim.lsp.buf.code_action, "[C]ode [A]ction") + map("ca", vim.lsp.buf.code_action, "[C]ode [A]ction", "v") + map("gD", vim.lsp.buf.declaration, "[G]oto [D]eclartion") + + local client = vim.lsp.get_client_by_id(event.data.client_id) + if client and client:supports_method(vim.lsp.protocol.Methods.textDocument_documentHighlight) then + local highlight_augroup = vim.api.nvim_create_augroup("kickstart-lsp-highlight", { clear = true }) + + -- Highlight references of the word under cursor when cursor rests for a little while + ---@diagnostic disable-next-line: param-type-mismatch + vim.api.nvim_create_autocmd({ "CursorHold", "CursorHoldI" }, { + buffer = event.buf, + group = highlight_augroup, + callback = vim.lsp.buf.document_highlight, + }) + + -- Clear highlights when cursor moves again + ---@diagnostic disable-next-line: param-type-mismatch + vim.api.nvim_create_autocmd({ "CursorMoved", "CursorMovedI" }, { + buffer = event.buf, + group = highlight_augroup, + callback = vim.lsp.buf.clear_references, + }) + + -- handle LspDetach + ---@diagnostic disable-next-line: param-type-mismatch + vim.api.nvim_create_autocmd({ "LspDetach" }, { + group = vim.api.nvim_create_augroup("kickstart-lsp-detach", { clear = true }), + callback = function(event2) + vim.lsp.buf.clear_references() + vim.api.nvim_clear_autocmds({ group = "kickstart-lsp-highlight", buffer = event2.buf }) + end, + }) + end + if client and client:supports_method(vim.lsp.protocol.Methods.textDocument_inlayHint) then + map("th", function() + vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled({ bufnr = event.buf })) + end, "[T]oggle Inlay [H]ints") + end + end, +}) diff --git a/configs/nvim/lua/plugins/telescope.lua b/configs/nvim/lua/plugins/telescope.lua new file mode 100644 index 0000000..ec46cc9 --- /dev/null +++ b/configs/nvim/lua/plugins/telescope.lua @@ -0,0 +1,32 @@ +vim.pack.add({ + { src = "https://github.com/nvim-telescope/telescope.nvim" }, + { src = "https://github.com/nvim-lua/plenary.nvim" }, +}) + +local actions = require("telescope.actions") +require("telescope").setup({ + defaults = { + mappings = { + i = { + [""] = actions.move_selection_previous, + [""] = actions.move_selection_next, + }, + n = { + [""] = actions.preview_scrolling_up, + [""] = actions.preview_scrolling_down, + }, + }, + }, +}) + +local builtin = require("telescope.builtin") +vim.keymap.set("n", "sh", builtin.help_tags, { desc = "[S]earch [H]elp" }) +vim.keymap.set("n", "sk", builtin.keymaps, { desc = "[S]earch [K]eymaps" }) +vim.keymap.set("n", "sf", builtin.find_files, { desc = "[S]earch [F]iles" }) +vim.keymap.set("n", "ss", builtin.builtin, { desc = "[S]earch [S]elect Telescope" }) +vim.keymap.set("n", "sw", builtin.grep_string, { desc = "[S]earch current [W]ord" }) +vim.keymap.set("n", "sg", builtin.live_grep, { desc = "[S]earch by [G]rep" }) +vim.keymap.set("n", "sd", builtin.diagnostics, { desc = "[S]earch [D]iagnostics" }) +vim.keymap.set("n", "sr", builtin.resume, { desc = "[S]earch [R]esume" }) +vim.keymap.set("n", "s.", builtin.oldfiles, { desc = '[S]earch Recent Files ("." for repeat)' }) +vim.keymap.set("n", "", builtin.buffers, { desc = "[ ] Find existing buffers" })