diff --git a/lua/colorschemes.lua b/lua/colorschemes.lua index f70505f..e58e730 100644 --- a/lua/colorschemes.lua +++ b/lua/colorschemes.lua @@ -42,7 +42,7 @@ if colorscheme == "onedark" then }) -- Load One Dark - require("onedark").load() + onedark.load() end if colorscheme == "catppuccin" then @@ -96,7 +96,7 @@ if colorscheme == "catppuccin" then }) -- Load Catppuccin - require("catppuccin").load() + catppuccin.load() end if colorscheme == "gruvbox" then @@ -126,5 +126,5 @@ if colorscheme == "gruvbox" then }) -- Load Gruvbox - require("gruvbox").load() + gruvbox.load() end diff --git a/lua/completions.lua b/lua/completions.lua index 1f7151b..27dee09 100644 --- a/lua/completions.lua +++ b/lua/completions.lua @@ -1,82 +1,86 @@ local ok, cmp = pcall(require, "cmp") if not ok then - return + return end local luasnip_ok, luasnip = pcall(require, "luasnip") if not luasnip_ok then - return + return end local luasnip_vscode_ok, luasnip_vscode = pcall(require, "luasnip/loaders/from_vscode") if not luasnip_vscode_ok then - return + return end local has_words_before = function() - unpack = unpack or table.unpack - local line, col = unpack(vim.api.nvim_win_get_cursor(0)) - return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil + unpack = unpack or table.unpack + local line, col = unpack(vim.api.nvim_win_get_cursor(0)) + return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil end luasnip_vscode.lazy_load() cmp.setup({ - view = { - --entries = { name = "custom", selection_order = "near_cursor" }, - }, - snippet = { - expand = function(args) - luasnip.lsp_expand(args.body) -- For `luasnip` users. - end, - }, - mapping = { - [""] = cmp.mapping.confirm({ select = true }), - [""] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_next_item() - -- You could replace the expand_or_jumpable() calls with expand_or_locally_jumpable() - -- they way you will only jump inside the snippet region - elseif luasnip.expand_or_jumpable() then - luasnip.expand_or_jump() - elseif has_words_before() then - cmp.complete() - else - fallback() - end - end, { "i", "s" }), - [""] = 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 "") .. ")" + view = { + --entries = { name = "custom", selection_order = "near_cursor" }, + }, + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) -- For `luasnip` users. + end, + }, + mapping = { + [""] = cmp.mapping.confirm({ select = true }), + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + -- You could replace the expand_or_jumpable() calls with expand_or_locally_jumpable() + -- they way you will only jump inside the snippet region + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + elseif has_words_before() then + cmp.complete() + else + fallback() + end + end, { "i", "s" }), + [""] = 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" }), + }, + sources = { + { name = "nvim_lsp" }, + { name = "luasnip" }, + { name = "buffer" }, + { name = "path" }, + }, + confirm_opts = { + behavior = cmp.ConfirmBehavior.Replace, + select = false, + }, + experimental = { + ghost_text = false, + }, + formatting = { + fields = { "kind", "abbr", "menu" }, + format = function(entry, vim_item) + local lk_ok, lspkind = pcall(require, "lspkind") + if not lk_ok then + return + end + local kind = 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, - }, - experimental = { - ghost_text = false, - }, + return kind + end, + }, }) diff --git a/lua/file-tree.lua b/lua/file-tree.lua index 3610a47..e7c4f17 100644 --- a/lua/file-tree.lua +++ b/lua/file-tree.lua @@ -1,5 +1,5 @@ -- disable netrw -vim.g.loaded_netrw = 1 + vim.g.loaded_netrw = 1 vim.g.loaded_netrwPlugin = 1 -- set termguicolors to enable highlight groups diff --git a/lua/lsp-config.lua b/lua/lsp-config.lua index 239f559..7929164 100644 --- a/lua/lsp-config.lua +++ b/lua/lsp-config.lua @@ -19,7 +19,12 @@ mason_lspconfig.setup({ ensure_installed = { "lua_ls", "rust_analyzer", "clangd" }, }) -local capabilities = require("cmp_nvim_lsp").default_capabilities() +local cnl_ok, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp") +if not cnl_ok then + return +end + +local capabilities = cmp_nvim_lsp.default_capabilities() mason_lspconfig.setup_handlers({ function(server) diff --git a/lua/lsp-format.lua b/lua/lsp-format.lua index 0ec2dec..7dd69e1 100644 --- a/lua/lsp-format.lua +++ b/lua/lsp-format.lua @@ -1,29 +1,29 @@ local ok, null_ls = pcall(require, "null-ls") if not ok then - return + return end local formatting = null_ls.builtins.formatting local augroup = vim.api.nvim_create_augroup("LspFormatting", {}) null_ls.setup({ - sources = { - formatting.rustfmt, - formatting.stylua, - formatting.black, + sources = { + formatting.rustfmt, + formatting.stylua, + formatting.black, formatting.prettier, - }, -- you can reuse a shared lspconfig on_attach callback here - on_attach = function(client, bufnr) - if client.supports_method("textDocument/formatting") then - vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr }) - vim.api.nvim_create_autocmd("BufWritePre", { - group = augroup, - buffer = bufnr, - callback = function() - -- on 0.8, you should use vim.lsp.buf.format({ bufnr = bufnr }) instead - vim.lsp.buf.format({ bufnr = bufnr }) - end, - }) - end - end, + }, -- you can reuse a shared lspconfig on_attach callback here + on_attach = function(client, bufnr) + if client.supports_method("textDocument/formatting") then + vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr }) + vim.api.nvim_create_autocmd("BufWritePre", { + group = augroup, + buffer = bufnr, + callback = function() + -- on 0.8, you should use vim.lsp.buf.format({ bufnr = bufnr }) instead + vim.lsp.buf.format({ bufnr = bufnr }) + end, + }) + end + end, }) diff --git a/lua/plugins.lua b/lua/plugins.lua index 4a28c17..c6b33a8 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -68,8 +68,11 @@ packer.startup(function(use) use({ "nvim-treesitter/nvim-treesitter", run = function() - local ts_update = require("nvim-treesitter.install").update({ with_sync = true }) - ts_update() + local ntsi_ok, nvim_treesitter_install = pcall(require, "nvim-treesitter.install") + if ntsi_ok then + local ts_update = nvim_treesitter_install.install.update({ with_sync = true }) + ts_update() + end end, }) diff --git a/lua/statusline.lua b/lua/statusline.lua index 515443d..12c1eef 100644 --- a/lua/statusline.lua +++ b/lua/statusline.lua @@ -1,45 +1,45 @@ local ok, lualine = pcall(require, "lualine") if not ok then - return + return end lualine.setup({ - options = { - icons_enabled = true, - theme = "auto", - component_separators = { left = "", right = "" }, - section_separators = { left = "", right = "" }, - disabled_filetypes = { - statusline = {}, - winbar = {}, - }, - ignore_focus = {}, - always_divide_middle = true, - globalstatus = false, - refresh = { - statusline = 1000, - tabline = 1000, - winbar = 1000, - }, - }, - sections = { - lualine_a = { "mode" }, - lualine_b = { "branch", "diff", "diagnostics" }, - lualine_c = { "filename" }, - lualine_x = { "encoding", "fileformat", "filetype" }, - lualine_y = { "progress" }, - lualine_z = { "location" }, - }, - inactive_sections = { - lualine_a = {}, - lualine_b = {}, - lualine_c = { "filename" }, - lualine_x = { "location" }, - lualine_y = {}, - lualine_z = {}, - }, - tabline = {}, - winbar = {}, - inactive_winbar = {}, - extensions = {}, + options = { + icons_enabled = true, + theme = "auto", + component_separators = { left = "", right = "" }, + section_separators = { left = "", right = "" }, + disabled_filetypes = { + statusline = {}, + winbar = {}, + }, + ignore_focus = {}, + always_divide_middle = true, + globalstatus = false, + refresh = { + statusline = 1000, + tabline = 1000, + winbar = 1000, + }, + }, + sections = { + lualine_a = { "mode" }, + lualine_b = { "branch", "diff", "diagnostics" }, + lualine_c = { "filename" }, + lualine_x = { "encoding", "fileformat", "filetype" }, + lualine_y = { "progress" }, + lualine_z = { "location" }, + }, + inactive_sections = { + lualine_a = {}, + lualine_b = {}, + lualine_c = { "filename" }, + lualine_x = { "location" }, + lualine_y = {}, + lualine_z = {}, + }, + tabline = {}, + winbar = {}, + inactive_winbar = {}, + extensions = {}, })