diff --git a/lua/plugins/conform.lua b/lua/plugins/conform.lua index 1c9fd0f..397e679 100644 --- a/lua/plugins/conform.lua +++ b/lua/plugins/conform.lua @@ -1,76 +1,69 @@ -vim.api.nvim_create_user_command("FormatDisable", function(args) - if args.bang then - -- FormatDisable! will disable formatting just for this buffer - vim.b.disable_autoformat = true - else - vim.g.disable_autoformat = true - end -end, { - desc = "Disable autoformat-on-save", - bang = true -}) - -vim.api.nvim_create_user_command("FormatEnable", function() - vim.b.disable_autoformat = false - vim.g.disable_autoformat = false -end, { - desc = "Re-enable autoformat-on-save" -}) - -local options = { - lsp_fallback = true, - - formatters_by_ft = { - lua = { - "stylua" - }, - - sh = { - "shfmt" - }, - - cpp = { - "clang-format" - }, - - c = { - "clang-format" - }, - - python = { - "black" - } - }, - - format_on_save = function(bufnr) - if vim.g.disable_autoformat or vim.b[bufnr].disable_autoformat then - return - end - return { - timeout_ms = 3000, - lsp_fallback = true - } - end -} - return { - "stevearc/conform.nvim", - -- for users those who want auto-save conform + lazyloading! - event = "BufWritePre", - cmd = { - "ConformInfo" - }, - config = function() - require("conform").setup(options) - end, + "stevearc/conform.nvim", + event = { + "BufWritePre", + }, + cmd = { + "ConformInfo", + }, + keys = { + { + -- Customize or remove this keymap to your liking + "fm", + function() + require("conform").format({ + async = true, + }) + end, + mode = "", + desc = "Format buffer", + }, + }, + -- This will provide type hinting with LuaLS + ---@module "conform" + ---@type conform.setupOpts + opts = { + -- Define your formatters + formatters_by_ft = { + lua = { + "stylua", + config = "~/.config/nvim/lua/stylua.toml", + }, + python = { + -- "isort", + "black", + }, + -- javascript = { "prettierd", "prettier", stop_after_first = true }, + sh = { + "shfmt", + }, + + cpp = { + "clang-format", + }, - -- Keymap - vim.keymap.set("n", "fm", function() - vim.lsp.buf.format { - async = true - } - end, { - desc = "Formating", - silent = true - }) + c = { + "clang-format", + }, + }, + -- Set default options + default_format_opts = { + lsp_format = "fallback", + }, + -- Set up format-on-save + format_on_save = { + timeout_ms = 500, + }, + -- Customize formatters + -- formatters = { + -- shfmt = { + -- prepend_args = { "-i", "2" }, + -- }, + -- }, + }, + init = function() + -- If you want the formatexpr, here is the place to set it + vim.o.formatexpr = + "v:lua.require'conform'.formatexpr()" + end, } diff --git a/lua/plugins/lsp_signature.lua b/lua/plugins/lsp_signature.lua deleted file mode 100644 index 43aecd2..0000000 --- a/lua/plugins/lsp_signature.lua +++ /dev/null @@ -1,14 +0,0 @@ -return { - 'ray-x/lsp_signature.nvim', - event = 'VeryLazy', - config = function() - require('lsp_signature').on_attach({ - bind = true, - floating_window = true, - transpancy = 80, - handler_opts = { - border = 'rounded' - } - }) - end -} diff --git a/lua/plugins/lspconfig.lua b/lua/plugins/lspconfig.lua index 25b5469..81d6424 100644 --- a/lua/plugins/lspconfig.lua +++ b/lua/plugins/lspconfig.lua @@ -1,137 +1,165 @@ return { - "neovim/nvim-lspconfig", - event = { - "BufReadPost", - "BufNewFile", - "BufWritePre" - }, - dependencies = { - "hrsh7th/cmp-nvim-lsp", - { - "antosha417/nvim-lsp-file-operations", - config = true - } - }, - config = function() - -- import lspconfig plugin - local lspconfig = require("lspconfig") - - -- import cmp-nvim-lsp plugin - local cmp_nvim_lsp = require("cmp_nvim_lsp") - - local keymap = vim.keymap -- for conciseness - - local opts = { - noremap = true, - silent = true - } - local on_attach = function(client, bufnr) - opts.buffer = bufnr - - -- set keybinds - opts.desc = "Show LSP references" - keymap.set("n", "gR", "Telescope lsp_references", opts) -- show definition, references - - opts.desc = "Go to declaration" - keymap.set("n", "gD", vim.lsp.buf.declaration, opts) -- go to declaration - - opts.desc = "Show LSP definitions" - keymap.set("n", "gd", "Telescope lsp_definitions", opts) -- show lsp definitions - - opts.desc = "Show LSP implementations" - keymap.set("n", "gi", "Telescope lsp_implementations", opts) -- show lsp implementations - - opts.desc = "Show LSP type definitions" - keymap.set("n", "gt", "Telescope lsp_type_definitions", opts) -- show lsp type definitions - - opts.desc = "See available code actions" - keymap.set({ - "n", - "v" - }, "ca", vim.lsp.buf.code_action, opts) -- see available code actions, in visual mode will apply to selection - - opts.desc = "Smart rename" - keymap.set("n", "rn", vim.lsp.buf.rename, opts) -- smart rename - - opts.desc = "Show buffer diagnostics" - keymap.set("n", "D", "Telescope diagnostics bufnr=0", opts) -- show diagnostics for file - - opts.desc = "Show line diagnostics" - keymap.set("n", "d", vim.diagnostic.open_float, opts) -- show diagnostics for line - - opts.desc = "Go to previous diagnostic" - keymap.set("n", "[d", vim.diagnostic.goto_prev, opts) -- jump to previous diagnostic in buffer - - opts.desc = "Go to next diagnostic" - keymap.set("n", "]d", vim.diagnostic.goto_next, opts) -- jump to next diagnostic in buffer - - opts.desc = "Show documentation for what is under cursor" - keymap.set("n", "K", vim.lsp.buf.hover, opts) -- show documentation for what is under cursor - - opts.desc = "Restart LSP" - keymap.set("n", "rs", ":LspRestart", opts) -- mapping to restart lsp if necessary - end - - -- used to enable autocompletion (assign to every lsp server config) - local capabilities = cmp_nvim_lsp.default_capabilities() - - -- Change the Diagnostic symbols in the sign column (gutter) - -- (not in youtube nvim video) - local signs = { - Error = " ", - Warn = " ", - Hint = "󰠠 ", - Info = " " - } - for type, icon in pairs(signs) do - local hl = "DiagnosticSign" .. type - vim.fn.sign_define(hl, { - text = icon, - texthl = hl, - numhl = "" - }) - end - - -- configure clangd server - lspconfig["clangd"].setup({ - capabilities = capabilities, - on_attach = on_attach, - cmd = { - "clangd", - "--background-index", - "--suggest-missing-includes", - "--clang-tidy", - "--offset-encoding=utf-16" - } - }) - - -- configure python server - lspconfig["pyright"].setup({ - capabilities = capabilities, - on_attach = on_attach - }) - - -- configure lua server (with special settings) - lspconfig["lua_ls"].setup({ - capabilities = capabilities, - on_attach = on_attach, - settings = { -- custom settings for lua - Lua = { - -- make the language server recognize "vim" global - diagnostics = { - globals = { - "vim" - } - }, - workspace = { - -- make language server aware of runtime files - library = { - [vim.fn.expand("$VIMRUNTIME/lua")] = true, - [vim.fn.stdpath("config") .. "/lua"] = true - } - } - } - } - }) - end + "neovim/nvim-lspconfig", + event = { + "BufReadPost", + "BufNewFile", + "BufWritePre", + }, + dependencies = { + "hrsh7th/cmp-nvim-lsp", + { + "antosha417/nvim-lsp-file-operations", + config = true, + }, + "ray-x/lsp_signature.nvim", + }, + config = function() + -- import lspconfig plugin + local lspconfig = require("lspconfig") + + -- import cmp-nvim-lsp plugin + local cmp_nvim_lsp = require("cmp_nvim_lsp") + + local lsp_signature = require("lsp_signature") + + local keymap = vim.keymap -- for conciseness + + vim.api.nvim_create_autocmd("LspAttach", { + callback = function(args) + local bufnr = args.buf + local client = vim.lsp.get_client_by_id(args.data.client_id) + -- if vim.tbl_contains({ + -- 'null-ls' + -- }, client.name) then -- blacklist lsp + -- return + -- end + + -- Buffer local mappings. + -- See `:help vim.lsp.*` for documentation on any of the below functions + local opts = { buffer = bufnr, silent = true } + + -- set keybinds + opts.desc = "Show LSP references" + keymap.set("n", "gR", "Telescope lsp_references", opts) -- show definition, references + + opts.desc = "Go to declaration" + keymap.set("n", "gD", vim.lsp.buf.declaration, opts) -- go to declaration + + opts.desc = "Show LSP definitions" + keymap.set("n", "gd", "Telescope lsp_definitions", opts) -- show lsp definitions + + opts.desc = "Show LSP implementations" + keymap.set("n", "gi", "Telescope lsp_implementations", opts) -- show lsp implementations + + opts.desc = "Show LSP type definitions" + keymap.set("n", "gt", "Telescope lsp_type_definitions", opts) -- show lsp type definitions + + opts.desc = "See available code actions" + keymap.set({ "n", "v" }, "ca", vim.lsp.buf.code_action, opts) -- see available code actions, in visual mode will apply to selection + + opts.desc = "Smart rename" + keymap.set("n", "rn", vim.lsp.buf.rename, opts) -- smart rename + + opts.desc = "Show buffer diagnostics" + keymap.set("n", "D", "Telescope diagnostics bufnr=0", opts) -- show diagnostics for file + + opts.desc = "Show line diagnostics" + keymap.set("n", "d", vim.diagnostic.open_float, opts) -- show diagnostics for line + + opts.desc = "Go to previous diagnostic" + keymap.set("n", "[d", vim.diagnostic.goto_prev, opts) -- jump to previous diagnostic in buffer + + opts.desc = "Go to next diagnostic" + keymap.set("n", "]d", vim.diagnostic.goto_next, opts) -- jump to next diagnostic in buffer + + opts.desc = "Show documentation for what is under cursor" + keymap.set("n", "K", vim.lsp.buf.hover, opts) -- show documentation for what is under cursor + + opts.desc = "Restart LSP" + keymap.set("n", "rs", ":LspRestart", opts) -- mapping to restart lsp if necessary + + require("lsp_signature").on_attach({ + bind = true, + floating_window = true, + transpancy = 60, + handler_opts = { + border = "rounded", + }, + doc_lines = 4, + hint_enable = true, + hint_prefix = "🐼 ", + }, bufnr) + end, + }) + + -- used to enable autocompletion (assign to every lsp server config) + local capabilities = cmp_nvim_lsp.default_capabilities() + + -- Change the Diagnostic symbols in the sign column (gutter) + -- (not in youtube nvim video) + local signs = { + Error = " ", + Warn = " ", + Hint = "󰠠 ", + Info = " ", + } + for type, icon in pairs(signs) do + local hl = "DiagnosticSign" .. type + vim.fn.sign_define(hl, { + text = icon, + texthl = hl, + numhl = "", + }) + end + + -- configure clangd server + lspconfig["clangd"].setup({ + capabilities = capabilities, + cmd = { + "clangd", + "--background-index", + "--suggest-missing-includes", + "--clang-tidy", + "--offset-encoding=utf-16", + }, + }) + + -- configure python server + lspconfig["pyright"].setup({ + capabilities = capabilities, + settings = { + python = { + analysis = { + autoSearchPaths = true, + useLibraryCodeForTypes = true, + }, + }, + }, + }) + + -- configure lua server (with special settings) + lspconfig["lua_ls"].setup({ + capabilities = capabilities, + settings = { -- custom settings for lua + Lua = { + -- make the language server recognize "vim" global + diagnostics = { + globals = { + "vim", + }, + }, + workspace = { + -- make language server aware of runtime files + library = { + [vim.fn.expand("$VIMRUNTIME/lua")] = true, + [vim.fn.stdpath("config") .. "/lua"] = true, + }, + }, + format = { + enable = false, + }, + }, + }, + }) + end, } diff --git a/lua/plugins/lualine.lua b/lua/plugins/lualine.lua index e728d5f..414ad38 100644 --- a/lua/plugins/lualine.lua +++ b/lua/plugins/lualine.lua @@ -13,160 +13,160 @@ local colors = { } local bubbles_theme = { - normal = { - a = { - fg = colors.black, - bg = colors.violet - }, - b = { - fg = colors.white, - bg = colors.grey - }, - c = { - fg = colors.white - } - }, + normal = { + a = { + fg = colors.black, + bg = colors.violet, + }, + b = { + fg = colors.white, + bg = colors.grey, + }, + c = { + fg = colors.white, + }, + }, - insert = { - a = { - fg = colors.black, - bg = colors.blue - } - }, - visual = { - a = { - fg = colors.black, - bg = colors.cyan - } - }, - replace = { - a = { - fg = colors.black, - bg = colors.red - } - }, + insert = { + a = { + fg = colors.black, + bg = colors.blue, + }, + }, + visual = { + a = { + fg = colors.black, + bg = colors.cyan, + }, + }, + replace = { + a = { + fg = colors.black, + bg = colors.red, + }, + }, - inactive = { - a = { - fg = colors.white, - bg = colors.black - }, - b = { - fg = colors.white, - bg = colors.black - }, - c = { - fg = colors.white - } - } + inactive = { + a = { + fg = colors.white, + bg = colors.black, + }, + b = { + fg = colors.white, + bg = colors.black, + }, + c = { + fg = colors.white, + }, + }, } return { - "nvim-lualine/lualine.nvim", - dependencies = { - "nvim-tree/nvim-web-devicons" - }, + "nvim-lualine/lualine.nvim", + dependencies = { + "nvim-tree/nvim-web-devicons", + }, - config = function() - require("lualine").setup({ - options = { - theme = bubbles_theme, - component_separators = { - left = "", - right = "" - }, - section_separators = { - left = "", - right = "" - }, - -- section_separators = { left = "", right = "" }, - icons_enabled = true, - disabled_filetypes = { - "neo-tree", - "NvimTree", - "Outline", - "packer" - } - }, - sections = { - lualine_a = { - { - "mode", - separator = { - left = "", - right = "" - }, - padding = { - left = 0, - right = 0 - } - } - }, - lualine_b = { - { - "filename", - path = 1 - }, - "branch" - }, - lualine_c = { - { - "diagnostics", - sources = { - "nvim_lsp" - }, - symbols = { - error = " ", - warn = " ", - info = " " - }, - color_error = colors.red, - color_warn = colors.violet, - color_info = colors.blue - } - }, - lualine_x = {}, - lualine_y = { - "filetype", - "progress" - }, - lualine_z = { - { - "location", - separator = { - right = "" - } - } - } - }, - inactive_sections = { - lualine_a = { - { - "filename", - separator = { - left = "", - right = "" - } - } - }, - lualine_b = {}, - lualine_c = {}, - lualine_x = {}, - lualine_y = {}, - lualine_z = { - { - "location", - separator = { - left = "", - right = "" - } - } - } - }, - tabline = {}, - extensions = {} - }) - vim.cmd("highlight statusline guifg=white guibg=NONE gui=NONE") - vim.cmd("highlight statuslineNC guifg=black guibg=NONE gui=NONE") - end + config = function() + require("lualine").setup({ + options = { + theme = bubbles_theme, + component_separators = { + left = "", + right = "", + }, + section_separators = { + left = "", + right = "", + }, + -- section_separators = { left = "", right = "" }, + icons_enabled = true, + disabled_filetypes = { + "neo-tree", + "NvimTree", + "Outline", + "packer", + }, + }, + sections = { + lualine_a = { + { + "mode", + separator = { + left = "", + right = "", + }, + padding = { + left = 0, + right = 0, + }, + }, + }, + lualine_b = { + { + "filename", + path = 1, + }, + "branch", + }, + lualine_c = { + { + "diagnostics", + sources = { + "nvim_lsp", + }, + symbols = { + error = " ", + warn = " ", + info = " ", + }, + color_error = colors.red, + color_warn = colors.violet, + color_info = colors.blue, + }, + }, + lualine_x = {}, + lualine_y = { + "filetype", + "progress", + }, + lualine_z = { + { + "location", + separator = { + right = "", + }, + }, + }, + }, + inactive_sections = { + lualine_a = { + { + "filename", + separator = { + left = "", + right = "", + }, + }, + }, + lualine_b = {}, + lualine_c = {}, + lualine_x = {}, + lualine_y = {}, + lualine_z = { + { + "location", + separator = { + left = "", + right = "", + }, + }, + }, + }, + tabline = {}, + extensions = {}, + }) + vim.cmd("highlight statusline guifg=white guibg=NONE gui=NONE") + vim.cmd("highlight statuslineNC guifg=black guibg=NONE gui=NONE") + end, }