From 8b75b3b1ead6b78b697eff12c3d2cfbf80792d06 Mon Sep 17 00:00:00 2001 From: Daniil Tsivinsky Date: Sat, 22 Jan 2022 12:10:28 +0300 Subject: [PATCH] Format neovim config with stylua using new stylua.toml config --- config/nvim/init.lua | 140 +++++++-------- config/nvim/lua/user/cmds.lua | 12 +- config/nvim/lua/user/file-tree.lua | 83 +++++---- config/nvim/lua/user/git.lua | 28 +-- config/nvim/lua/user/lsp.lua | 260 ++++++++++++++-------------- config/nvim/lua/user/lualine.lua | 52 +++--- config/nvim/lua/user/telescope.lua | 8 +- config/nvim/lua/user/theme.lua | 10 -- config/nvim/lua/user/treesitter.lua | 14 +- config/nvim/lua/user/utils.lua | 34 ++-- 10 files changed, 324 insertions(+), 317 deletions(-) diff --git a/config/nvim/init.lua b/config/nvim/init.lua index f66c1ae..e175168 100644 --- a/config/nvim/init.lua +++ b/config/nvim/init.lua @@ -4,94 +4,94 @@ local fn = vim.fn -- Install packer automagically local install_path = fn.stdpath("data") .. "/site/pack/packer/start/packer.nvim" if fn.empty(fn.glob(install_path)) > 0 then - PACKER_BOOTSTRAP = fn.system({ - "git", - "clone", - "--depth", - "1", - "https://github.com/wbthomason/packer.nvim", - install_path, - }) + PACKER_BOOTSTRAP = fn.system({ + "git", + "clone", + "--depth", + "1", + "https://github.com/wbthomason/packer.nvim", + install_path, + }) end require("packer").startup(function(use) - use({ "wbthomason/packer.nvim" }) + use({ "wbthomason/packer.nvim" }) - use({ "nvim-lua/popup.nvim" }) - use({ "nvim-lua/plenary.nvim" }) + use({ "nvim-lua/popup.nvim" }) + use({ "nvim-lua/plenary.nvim" }) - -- Colorschemes go here - use({ "folke/tokyonight.nvim" }) + -- Colorschemes go here + use({ "folke/tokyonight.nvim" }) - -- Make commenting code great - use({ "tpope/vim-commentary" }) + -- Make commenting code great + use({ "tpope/vim-commentary" }) - -- Icons used by many plugins - use({ "kyazdani42/nvim-web-devicons" }) + -- Icons used by many plugins + use({ "kyazdani42/nvim-web-devicons" }) - -- Auto pairs plugin that automatically closes brackets and quotes - use({ "windwp/nvim-autopairs" }) + -- Auto pairs plugin that automatically closes brackets and quotes + use({ "windwp/nvim-autopairs" }) - -- File tree - use({ "kyazdani42/nvim-tree.lua" }) + -- File tree + use({ "kyazdani42/nvim-tree.lua" }) - -- Treesitter for better syntax highlighting - use({ - "nvim-treesitter/nvim-treesitter", - run = ":TSUpdate", - { - { "JoosepAlviste/nvim-ts-context-commentstring" }, - { "nvim-treesitter/playground" }, - { "windwp/nvim-ts-autotag" }, - }, - }) + -- Treesitter for better syntax highlighting + use({ + "nvim-treesitter/nvim-treesitter", + run = ":TSUpdate", + { + { "JoosepAlviste/nvim-ts-context-commentstring" }, + { "nvim-treesitter/playground" }, + { "windwp/nvim-ts-autotag" }, + }, + }) - -- Git things - use({ "lewis6991/gitsigns.nvim" }) - use({ "tpope/vim-fugitive" }) + -- Git things + use({ "lewis6991/gitsigns.nvim" }) + use({ "tpope/vim-fugitive" }) - -- LSP stuff - use({ "neovim/nvim-lspconfig" }) - use({ "williamboman/nvim-lsp-installer" }) - use({ "jose-elias-alvarez/null-ls.nvim" }) + -- LSP stuff + use({ "neovim/nvim-lspconfig" }) + use({ "williamboman/nvim-lsp-installer" }) + use({ "jose-elias-alvarez/null-ls.nvim" }) - -- Completion, snippets, etc - use({ - "hrsh7th/nvim-cmp", - { - { "hrsh7th/cmp-nvim-lsp" }, - { "hrsh7th/cmp-buffer" }, - { "hrsh7th/cmp-path" }, - { "hrsh7th/cmp-cmdline" }, - }, - }) - use({ "L3MON4D3/LuaSnip", { - "saadparwaiz1/cmp_luasnip", - } }) + -- Completion, snippets, etc + use({ + "hrsh7th/nvim-cmp", + { + { "hrsh7th/cmp-nvim-lsp" }, + { "hrsh7th/cmp-buffer" }, + { "hrsh7th/cmp-path" }, + { "hrsh7th/cmp-cmdline" }, + }, + }) + use({ "L3MON4D3/LuaSnip", { + "saadparwaiz1/cmp_luasnip", + } }) - use({ "nvim-telescope/telescope.nvim" }) + use({ "nvim-telescope/telescope.nvim" }) - -- Statusline - use({ "nvim-lualine/lualine.nvim" }) + -- Statusline + use({ "nvim-lualine/lualine.nvim" }) - -- Highlight todo comments - use({ - "folke/todo-comments.nvim", - config = function() - require("todo-comments").setup({}) - end, - }) + -- Highlight todo comments + use({ + "folke/todo-comments.nvim", + config = function() + require("todo-comments").setup({}) + end, + }) - use({ - "folke/trouble.nvim", - config = function() - require("trouble").setup({}) - end, - }) + use({ + "folke/trouble.nvim", + config = function() + require("trouble").setup({}) + end, + }) - if PACKER_BOOTSTRAP then - require("packer").sync() - end + if PACKER_BOOTSTRAP then + require("packer").sync() + end end) vim.g.mapleader = " " diff --git a/config/nvim/lua/user/cmds.lua b/config/nvim/lua/user/cmds.lua index 45efdee..75aa8fc 100644 --- a/config/nvim/lua/user/cmds.lua +++ b/config/nvim/lua/user/cmds.lua @@ -1,9 +1,9 @@ function open_terminal(vertically) - vertically = vertically or false + vertically = vertically or false - if vertically then - vim.cmd(":vs term://bash") - else - vim.cmd(":split term://bash") - end + if vertically then + vim.cmd(":vs term://bash") + else + vim.cmd(":split term://bash") + end end diff --git a/config/nvim/lua/user/file-tree.lua b/config/nvim/lua/user/file-tree.lua index 400b7b4..2102d78 100644 --- a/config/nvim/lua/user/file-tree.lua +++ b/config/nvim/lua/user/file-tree.lua @@ -1,40 +1,57 @@ local tree_cb = require("nvim-tree.config").nvim_tree_callback local nmap = require("user.utils").nmap -require("nvim-tree").setup({ - disable_netrw = true, - hijack_netrw = true, - open_on_setup = true, - hijack_cursor = true, - open_on_tab = true, - update_cwd = true, - auto_close = true, - update_focused_file = { - enable = true, - }, - view = { - width = 30, - side = "left", - auto_resize = true, - mappings = { - list = { - { - key = "", - cb = tree_cb("tabnew"), - }, - }, - }, - }, - filters = { - custom = { ".git" }, - }, - git = { - ignore = false, - }, -}) - +vim.g.nvim_tree_show_icons = { + git = 1, + files = 1, + folders = 1, +} +vim.g.nvim_tree_icons = { + default = "", + symlink = "", + git = { + unstaged = "U", + staged = "S", + unmerged = "M", + renamed = "R", + untracked = "N", + deleted = "D", + }, +} +vim.g.nvim_tree_git_hl = 1 vim.g.nvim_tree_add_trailing = 1 vim.g.nvim_tree_indent_markers = 1 --- TODO: Change git icons to something similar to vscode + +require("nvim-tree").setup({ + disable_netrw = true, + hijack_netrw = true, + open_on_setup = true, + hijack_cursor = true, + open_on_tab = true, + update_cwd = true, + auto_close = true, + update_focused_file = { + enable = true, + }, + view = { + width = 30, + side = "left", + auto_resize = true, + mappings = { + list = { + { + key = "", + cb = tree_cb("tabnew"), + }, + }, + }, + }, + filters = { + custom = { ".git" }, + }, + git = { + ignore = false, + }, +}) nmap("b", ":NvimTreeToggle") diff --git a/config/nvim/lua/user/git.lua b/config/nvim/lua/user/git.lua index b539d46..a55399d 100644 --- a/config/nvim/lua/user/git.lua +++ b/config/nvim/lua/user/git.lua @@ -1,17 +1,17 @@ require("gitsigns").setup({ - signcolumn = true, - keymaps = { - noremap = true, + signcolumn = true, + keymaps = { + noremap = true, - ["n gs"] = ":Gitsigns stage_hunk", - ["n gu"] = ":Gitsigns undo_stage_hunk", - ["n gr"] = ":Gitsigns reset_hunk", - }, - current_line_blame = true, - current_line_blame_opts = { - delay = 1000, - }, - current_line_blame_formatter_opts = { - relative_time = true, - }, + ["n gs"] = ":Gitsigns stage_hunk", + ["n gu"] = ":Gitsigns undo_stage_hunk", + ["n gr"] = ":Gitsigns reset_hunk", + }, + current_line_blame = true, + current_line_blame_opts = { + delay = 1000, + }, + current_line_blame_formatter_opts = { + relative_time = true, + }, }) diff --git a/config/nvim/lua/user/lsp.lua b/config/nvim/lua/user/lsp.lua index 2d4ad0d..46de38e 100644 --- a/config/nvim/lua/user/lsp.lua +++ b/config/nvim/lua/user/lsp.lua @@ -4,129 +4,129 @@ local null_ls = require("null-ls") local list_includes_item = require("user.utils").list_includes_item local kind_icons = { - Text = "", - Method = "", - Function = "", - Constructor = "", - Field = "", - Variable = "", - Class = "ﴯ", - Interface = "", - Module = "", - Property = "ﰠ", - Unit = "", - Value = "", - Enum = "", - Keyword = "", - Snippet = "", - Color = "", - File = "", - Reference = "", - Folder = "", - EnumMember = "", - Constant = "", - Struct = "", - Event = "", - Operator = "", - TypeParameter = "", + Text = "", + Method = "", + Function = "", + Constructor = "", + Field = "", + Variable = "", + Class = "ﴯ", + Interface = "", + Module = "", + Property = "ﰠ", + Unit = "", + Value = "", + Enum = "", + Keyword = "", + Snippet = "", + Color = "", + File = "", + Reference = "", + Folder = "", + EnumMember = "", + Constant = "", + Struct = "", + Event = "", + Operator = "", + TypeParameter = "", } local formatting = null_ls.builtins.formatting local diagnostics = null_ls.builtins.diagnostics null_ls.setup({ - sources = { - formatting.prettierd, - formatting.stylua, - formatting.black, - formatting.gofmt, - formatting.goimports, - formatting.shfmt, - }, - on_attach = function() - vim.cmd([[ + sources = { + formatting.prettierd, + formatting.stylua, + formatting.black, + formatting.gofmt, + formatting.goimports, + formatting.shfmt, + }, + on_attach = function() + vim.cmd([[ augroup LspFormatting autocmd! * autocmd BufWritePre lua vim.lsp.buf.formatting_sync() augroup END ]]) - end, + end, }) -- Other formats that work weird with null_ls vim.cmd([[autocmd BufWritePre *.svelte lua vim.lsp.buf.formatting_sync(nil, 1000)]]) cmp.setup({ - snippet = { - expand = function(args) - require("luasnip").lsp_expand(args.body) - end, - }, - mapping = { - [""] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Select }), - [""] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Select }), - [""] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.close() - else - cmp.complete() - end - end), - [""] = cmp.mapping.confirm({ - select = true, - behavior = cmp.SelectBehavior.Insert, - }), - }, - sources = cmp.config.sources({ - { name = "nvim_lsp" }, - { name = "luasnip" }, - }, { - { name = "path" }, - { name = "buffer" }, - }), - completion = { - completeopt = "menu,menuone,noselect,noinsert,preview", - }, - experimental = { - ghost_text = true, - }, - sorting = { - comparators = { - cmp.config.compare.score, - cmp.config.compare.sort_text, - cmp.config.compare.kind, - }, - }, - documentation = { - border = { "╭", "─", "╮", "│", "╯", "─", "╰", "│" }, - zindex = 999, - format = { "markdown" }, - }, - formatting = { - format = function(entry, vim_item) - vim_item.kind = string.format("%s %s", kind_icons[vim_item.kind], vim_item.kind) - vim_item.menu = ({ - buffer = "[Buffer]", - luasnip = "[Snippet]", - nvim_lua = "[Lua]", - path = "[File]", - })[entry.source.name] + snippet = { + expand = function(args) + require("luasnip").lsp_expand(args.body) + end, + }, + mapping = { + [""] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Select }), + [""] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Select }), + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.close() + else + cmp.complete() + end + end), + [""] = cmp.mapping.confirm({ + select = true, + behavior = cmp.SelectBehavior.Insert, + }), + }, + sources = cmp.config.sources({ + { name = "nvim_lsp" }, + { name = "luasnip" }, + }, { + { name = "path" }, + { name = "buffer" }, + }), + completion = { + completeopt = "menu,menuone,noselect,noinsert,preview", + }, + experimental = { + ghost_text = true, + }, + sorting = { + comparators = { + cmp.config.compare.score, + cmp.config.compare.sort_text, + cmp.config.compare.kind, + }, + }, + documentation = { + border = { "╭", "─", "╮", "│", "╯", "─", "╰", "│" }, + zindex = 999, + format = { "markdown" }, + }, + formatting = { + format = function(entry, vim_item) + vim_item.kind = string.format("%s %s", kind_icons[vim_item.kind], vim_item.kind) + vim_item.menu = ({ + buffer = "[Buffer]", + luasnip = "[Snippet]", + nvim_lua = "[Lua]", + path = "[File]", + })[entry.source.name] - return vim_item - end, - }, + return vim_item + end, + }, }) cmp.setup.cmdline("/", { - sources = { - { name = "cmdline" }, - }, + sources = { + { name = "cmdline" }, + }, }) cmp.setup.cmdline(":", { - sources = { - { name = "cmdline" }, - }, + sources = { + { name = "cmdline" }, + }, }) local capabilities = require("cmp_nvim_lsp").update_capabilities(vim.lsp.protocol.make_client_capabilities()) @@ -134,47 +134,47 @@ local capabilities = require("cmp_nvim_lsp").update_capabilities(vim.lsp.protoco local lsps_with_disabled_formatting = { "tsserver", "gopls" } local on_attach = function(client) - if list_includes_item(lsps_with_disabled_formatting, client.name) then - client.resolved_capabilities.document_formatting = false - client.resolved_capabilities.document_range_formatting = false - end + if list_includes_item(lsps_with_disabled_formatting, client.name) then + client.resolved_capabilities.document_formatting = false + client.resolved_capabilities.document_range_formatting = false + end end lsp_installer.on_server_ready(function(server) - local opts = { - capabilities = capabilities, - on_attach = on_attach, - } + local opts = { + capabilities = capabilities, + on_attach = on_attach, + } - if server.name == "sumneko_lua" then - local runtime_path = vim.split(package.path, ";") - table.insert(runtime_path, "lua/?.lua") - table.insert(runtime_path, "lua/?/init/lua") + if server.name == "sumneko_lua" then + local runtime_path = vim.split(package.path, ";") + table.insert(runtime_path, "lua/?.lua") + table.insert(runtime_path, "lua/?/init/lua") - opts.settings = { - Lua = { - runtime = { - version = "LuaJIT", - path = runtime_path, - }, - diagnostics = { - library = vim.api.nvim_get_runtime_file("", true), - }, - telemetry = { - enable = false, - }, - }, - } - end + opts.settings = { + Lua = { + runtime = { + version = "LuaJIT", + path = runtime_path, + }, + diagnostics = { + library = vim.api.nvim_get_runtime_file("", true), + }, + telemetry = { + enable = false, + }, + }, + } + end - server:setup(opts) + server:setup(opts) end) -- Don't show diagnostics as virtual text vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, { - update_in_insert = true, - virtual_text = false, - signs = false, + update_in_insert = true, + virtual_text = false, + signs = false, }) require("luasnip.loaders.from_vscode").load() diff --git a/config/nvim/lua/user/lualine.lua b/config/nvim/lua/user/lualine.lua index 03ab038..cfe7a84 100644 --- a/config/nvim/lua/user/lualine.lua +++ b/config/nvim/lua/user/lualine.lua @@ -1,46 +1,46 @@ local lualine = require("lualine") local branch = { - "branch", - icons_enabled = true, - icon = "", + "branch", + icons_enabled = true, + icon = "", } local diagnostics = { - "diagnostics", - sections = { "error", "warn" }, - symbols = { error = " ", warn = " " }, - colored = false, - update_in_insert = false, - always_visible = true, + "diagnostics", + sections = { "error", "warn" }, + symbols = { error = " ", warn = " " }, + colored = false, + update_in_insert = false, + always_visible = true, } local mode = { - "mode", + "mode", } local filetype = { - "filetype", + "filetype", } local location = function() - local line, column = unpack(vim.api.nvim_win_get_cursor(0)) + local line, column = unpack(vim.api.nvim_win_get_cursor(0)) - return "Ln " .. line .. ", Col " .. column + return "Ln " .. line .. ", Col " .. column end lualine.setup({ - options = { - disabled_filetypes = { "NvimTree" }, - component_separators = { left = "", right = "" }, - section_separators = { left = "", right = "" }, - }, - sections = { - lualine_a = { branch, diagnostics }, - lualine_b = { mode }, - lualine_c = {}, - lualine_x = { location }, - lualine_y = { "encoding", filetype }, - lualine_z = {}, - }, + options = { + disabled_filetypes = { "NvimTree" }, + component_separators = { left = "", right = "" }, + section_separators = { left = "", right = "" }, + }, + sections = { + lualine_a = { branch, diagnostics }, + lualine_b = { mode }, + lualine_c = {}, + lualine_x = { location }, + lualine_y = { "encoding", filetype }, + lualine_z = {}, + }, }) diff --git a/config/nvim/lua/user/telescope.lua b/config/nvim/lua/user/telescope.lua index 1fb86a5..cba33bf 100644 --- a/config/nvim/lua/user/telescope.lua +++ b/config/nvim/lua/user/telescope.lua @@ -1,6 +1,6 @@ require("telescope").setup({ - defaults = { - sorting_strategy = "ascending", - file_ignore_patterns = { ".git/", "node_modules/" }, - }, + defaults = { + sorting_strategy = "ascending", + file_ignore_patterns = { ".git/", "node_modules/" }, + }, }) diff --git a/config/nvim/lua/user/theme.lua b/config/nvim/lua/user/theme.lua index 948f5eb..d9fff45 100644 --- a/config/nvim/lua/user/theme.lua +++ b/config/nvim/lua/user/theme.lua @@ -2,13 +2,3 @@ local cmd = vim.cmd vim.g.tokyonight_style = "night" cmd([[colorscheme tokyonight]]) - -cmd([[ -hi NvimTreeGitNew guifg=green -hi NvimTreeGitStaged guifg=lightgreen -hi NvimTreeGitDeleted guifg=red -hi NvimTreeGitDirty guifg=lightblue -hi NvimTreeGitMerge guifg=yellow -hi NvimTreeGitIgnored guifg=gray -hi NvimTreeOpenedFolderName gui=italic,bold -]]) diff --git a/config/nvim/lua/user/treesitter.lua b/config/nvim/lua/user/treesitter.lua index 795dd6b..1e5463a 100644 --- a/config/nvim/lua/user/treesitter.lua +++ b/config/nvim/lua/user/treesitter.lua @@ -1,9 +1,9 @@ require("nvim-treesitter.configs").setup({ - ensure_installed = "maintained", - highlight = { - enable = true, - }, - context_commentstring = { - enable = true, - }, + ensure_installed = "maintained", + highlight = { + enable = true, + }, + context_commentstring = { + enable = true, + }, }) diff --git a/config/nvim/lua/user/utils.lua b/config/nvim/lua/user/utils.lua index 35883cf..0edf583 100644 --- a/config/nvim/lua/user/utils.lua +++ b/config/nvim/lua/user/utils.lua @@ -1,41 +1,41 @@ local M = {} local function map(mode, shortcut, command, additional_opts) - local opts = { noremap = true, silent = true } + local opts = { noremap = true, silent = true } - if opts then - opts = vim.tbl_extend("force", opts, additional_opts) - end + if opts then + opts = vim.tbl_extend("force", opts, additional_opts) + end - vim.api.nvim_set_keymap(mode, shortcut, command, opts) + vim.api.nvim_set_keymap(mode, shortcut, command, opts) end M.nmap = function(shortcut, command, opts) - opts = opts or {} + opts = opts or {} - map("n", shortcut, command, opts) + map("n", shortcut, command, opts) end M.vmap = function(shortcut, command, opts) - opts = opts or {} + opts = opts or {} - map("v", shortcut, command, opts) + map("v", shortcut, command, opts) end M.tmap = function(shortcut, command, opts) - opts = opts or {} + opts = opts or {} - map("t", shortcut, command, opts) + map("t", shortcut, command, opts) end M.list_includes_item = function(list, item) - for _, value in pairs(list) do - if value == item then - return true - end - end + for _, value in pairs(list) do + if value == item then + return true + end + end - return false + return false end return M