diff --git a/config/nvim/init.lua b/config/nvim/init.lua index f0e30f5..ede6f9d 100644 --- a/config/nvim/init.lua +++ b/config/nvim/init.lua @@ -1,58 +1,68 @@ require("packer").startup(function(use) - use({ "wbthomason/packer.nvim" }) + use({"wbthomason/packer.nvim"}) - -- Colorscheme - use({ "EdenEast/nightfox.nvim" }) + -- Colorscheme + use({"EdenEast/nightfox.nvim"}) - -- Treesitter - use({ "nvim-treesitter/nvim-treesitter", run = ":TSUpdate", { - { "p00f/nvim-ts-rainbow" }, - { "JoosepAlviste/nvim-ts-context-commentstring" }, - { "nvim-treesitter/playground" } - }}) + -- Treesitter + use({ + "nvim-treesitter/nvim-treesitter", + run = ":TSUpdate", + { + {"p00f/nvim-ts-rainbow"}, + {"JoosepAlviste/nvim-ts-context-commentstring"}, + {"nvim-treesitter/playground"} + } + }) - -- Make commenting code great - use({ "tpope/vim-commentary" }) + -- Make commenting code great + use({"tpope/vim-commentary"}) - -- File tree - use({ "kyazdani42/nvim-tree.lua", requires = { "kyazdani42/nvim-web-devicons" } }) + -- File tree + use({ + "kyazdani42/nvim-tree.lua", + requires = {"kyazdani42/nvim-web-devicons"} + }) - -- Automatically close brackets and quotes - use({ "windwp/nvim-autopairs" }) + -- Automatically close brackets and quotes + use({"windwp/nvim-autopairs"}) - -- Telescope - use({ "nvim-telescope/telescope.nvim", requires = { "nvim-lua/plenary.nvim" } }) - use({ "nvim-telescope/telescope-symbols.nvim" }) + -- Telescope + use({"nvim-telescope/telescope.nvim", requires = {"nvim-lua/plenary.nvim"}}) + use({"nvim-telescope/telescope-symbols.nvim"}) - -- Statusline - use({ "nvim-lualine/lualine.nvim", requires = { "kyazdani42/nvim-web-devicons" } }) + -- Statusline + use({ + "nvim-lualine/lualine.nvim", + requires = {"kyazdani42/nvim-web-devicons"} + }) - use({ "iamcco/markdown-preview.nvim", run = "cd app && yarn install" }) + use({"iamcco/markdown-preview.nvim", run = "cd app && yarn install"}) - -- Highlight colors in editor - use({ "norcalli/nvim-colorizer.lua" }) + -- Highlight colors in editor + use({"norcalli/nvim-colorizer.lua"}) - -- LSP - use({ "neovim/nvim-lspconfig" }) - use({ "hrsh7th/nvim-cmp" }) - use({ "L3MON4D3/LuaSnip" }) - use({ - "hrsh7th/cmp-nvim-lsp", - "hrsh7th/cmp-buffer", - "hrsh7th/cmp-path", - "hrsh7th/cmp-cmdline", - "hrsh7th/cmp-nvim-lua", - "saadparwaiz1/cmp_luasnip" - }) - use({ "ray-x/lsp_signature.nvim" }) - use({ "dense-analysis/ale" }) + -- LSP + use({"neovim/nvim-lspconfig", "williamboman/nvim-lsp-installer"}) + use({"hrsh7th/nvim-cmp"}) + use({"L3MON4D3/LuaSnip"}) + use({ + "hrsh7th/cmp-nvim-lsp", "hrsh7th/cmp-buffer", "hrsh7th/cmp-path", + "hrsh7th/cmp-cmdline", "hrsh7th/cmp-nvim-lua", + "saadparwaiz1/cmp_luasnip" + }) + use({"ray-x/lsp_signature.nvim"}) + use({"dense-analysis/ale"}) - -- Tabs - use({ "romgrk/barbar.nvim" }) + -- Tabs + use({"romgrk/barbar.nvim"}) - -- Git - use({ "lewis6991/gitsigns.nvim", requires = { "nvim-lua/plenary.nvim" } }) - use({ "tpope/vim-fugitive" }) + -- Git + use({"lewis6991/gitsigns.nvim", requires = {"nvim-lua/plenary.nvim"}}) + use({"tpope/vim-fugitive"}) + + -- Formatter + use({"sbdchd/neoformat"}) end) require("nightfox").load() @@ -64,7 +74,7 @@ vim.o.autoindent = true vim.o.number = true vim.o.relativenumber = true vim.o.wrap = true -vim.o.swapfile = true +vim.o.swapfile = false vim.o.encoding = "utf-8" vim.o.hidden = true vim.o.writebackup = false @@ -81,64 +91,64 @@ vim.o.signcolumn = "yes" vim.g.mapleader = " " +vim.cmd([[autocmd BufWritePre * undojoin | Neoformat]]) + require("lsp") -vim.cmd("let g:ale_fixers = {'javascript': ['prettier', 'eslint'], 'typescript': ['prettier', 'eslint'], 'python': ['autopep8', 'remove_trailing_lines', 'reorder-python-imports', 'trim_whitespace']}") +vim.cmd( + "let g:ale_fixers = {'javascript': ['prettier', 'eslint'], 'typescript': ['prettier', 'eslint'], 'python': ['autopep8', 'remove_trailing_lines', 'reorder-python-imports', 'trim_whitespace']}") vim.cmd("let g:ale_fix_on_save = 1") require("nvim-treesitter.configs").setup({ - ensure_installed = "maintained", - highlight = { - enable = true - }, - incremental_selection = { - enable = true, - keymaps = { - init_selection = "", - scope_incremental = "", - node_incremental = "", - node_decremental = "" - } - }, - rainbow = { - enable = true, - extended_mode = true, - disable = { "html" } - }, - context_commentstring = { - enable = true - } + ensure_installed = "maintained", + highlight = {enable = true}, + incremental_selection = { + enable = true, + keymaps = { + init_selection = "", + scope_incremental = "", + node_incremental = "", + node_decremental = "" + } + }, + rainbow = {enable = true, extended_mode = true, disable = {"html"}}, + context_commentstring = {enable = true} }) require("nvim-tree").setup({ - open_on_setup = true, - hijack_cursor = true, - auto_close = true, - open_on_tab = true, - update_cwd = true, - update_focused_file = { enable = true }, - view = { width = 30, side = "left", auto_resize = true }, - filters = { custom = { ".git" } } + open_on_setup = true, + hijack_cursor = true, + auto_close = true, + open_on_tab = true, + update_cwd = true, + update_focused_file = {enable = true}, + view = {width = 30, side = "left", auto_resize = true}, + filters = {custom = {".git"}} }) vim.g.nvim_tree_add_trailing = 1 vim.g.nvim_tree_indent_markers = 1 -vim.g.nvim_tree_show_icons = { git = 0, folders = 0, files = 0, folder_arrows = 0 } +vim.g.nvim_tree_show_icons = { + git = 0, + folders = 0, + files = 0, + folder_arrows = 0 +} require("telescope").setup({ - defaults = { - sorting_strategy = "ascending", - file_ignore_patterns = { ".git", "node_modules" } - } + defaults = { + sorting_strategy = "ascending", + file_ignore_patterns = {".git", "node_modules"} + } }) require("gitsigns").setup({ - current_line_blame = true, - keymaps = { - noremap = true, - ["n gs"] = [[:lua require("gitsigns").stage_hunk()]], - ["n gu"] = [[:lua require("gitsigns").undo_stage_hunk()]], - ["n gr"] = [[:lua require("gitsigns").reset_hunk()]], - } + current_line_blame = true, + keymaps = { + noremap = true, + ["n gs"] = [[:lua require("gitsigns").stage_hunk()]], + ["n gu"] = [[:lua require("gitsigns").undo_stage_hunk()]], + ["n gr"] = [[:lua require("gitsigns").reset_hunk()]] + } }) require("nvim-autopairs").setup() diff --git a/config/nvim/lua/lsp.lua b/config/nvim/lua/lsp.lua index df4a838..8fc7a25 100644 --- a/config/nvim/lua/lsp.lua +++ b/config/nvim/lua/lsp.lua @@ -1,150 +1,115 @@ -local nvim_lsp = require("lspconfig") +local lsp_installer = require("nvim-lsp-installer") local cmp = require("cmp") 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 = "" } cmp.setup({ - snippet = { - expand = function(args) - require("luasnip").lsp_expand(args.body) + 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.complete(), + [""] = cmp.mapping.confirm({ + select = true, + behavior = cmp.SelectBehavior.Insert + }), + [""] = cmp.mapping.confirm({ + select = true, + behavior = cmp.SelectBehavior.Insert + }) + }, + sources = cmp.config.sources({ + {name = "nvim_lsp"}, {name = "luasnip"}, {name = "nvim_lua"} + }, {{name = "path"}, {name = "buffer"}}), + completion = {completeopt = "menu,menuone,noselect,noinsert,preview"}, + experimental = {ghost_text = true}, + sorting = { + comparators = { + cmp.config.compare.exact, cmp.config.compare.score, + cmp.config.compare.recently_used, cmp.config.compare.kind, + cmp.config.compare.offset + } + }, + documentation = { + border = {"╭", "─", "╮", "│", "╯", "─", "╰", "│"}, + zindex = 999 + }, + 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]", + nvim_lsp = "[LSP]", + luasnip = "[Snippet]", + nvim_lua = "[Lua]", + path = "[File]" + })[entry.source.name] + return vim_item + end + } +}) + +cmp.setup.cmdline("/", {sources = {{name = "buffer"}}}) + +cmp.setup.cmdline(":", {sources = {{name = "path"}, {name = "cmdline"}}}) + +local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp + .protocol + .make_client_capabilities()) +capabilities.textDocument.completion.completionItem.snippetSupport = true + +lsp_installer.on_server_ready(function(server) + local opts = {} + + 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 = {globals = {"vim"}}, + workspace = {library = vim.api.nvim_get_runtime_file("", true)}, + telemetry = {enable = false} + } + } end - }, - mapping = { - [""] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Select }), - [""] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Select }), - [""] = cmp.mapping.complete(), - [""] = cmp.mapping.confirm({ select = true, behavior = cmp.SelectBehavior.Insert }), - [""] = cmp.mapping.confirm({ select = true, behavior = cmp.SelectBehavior.Insert }) - }, - sources = cmp.config.sources({ - { name = "nvim_lsp" }, - { name = "luasnip" }, - { name = "nvim_lua" } - }, { - { name = "path" }, - { name = "buffer" } - }), - completion = { - completeopt = "menu,menuone,noselect,noinsert" - }, - experimental = { - ghost_text = true - }, - sorting = { - comparators = { - cmp.config.compare.exact, - cmp.config.compare.score, - cmp.config.compare.recently_used, - cmp.config.compare.kind, - cmp.config.compare.offset - } - }, - documentation = { - border = { "╭", "─", "╮", "│", "╯", "─", "╰", "│" }, - zindex = 999 - }, - 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]", nvim_lsp = "[LSP]", luasnip = "[Snippet]", nvim_lua = "[Lua]", path = "[File]" })[entry.source.name] - return vim_item - end - } -}) -cmp.setup.cmdline("/", { - sources = { - { name = "buffer" } - } -}) - -cmp.setup.cmdline(":", { - sources = { - { name = "path" }, - { name = "cmdline" } - } -}) - -local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities()) - -local on_attach = function(_, bufnr) - require("lsp_signature").on_attach({}, bufnr) -end - -local servers = { "tsserver", "pyright" } - -for _, server in ipairs(servers) do - nvim_lsp[server].setup({ - capabilities = capabilities, - on_attach = on_attach, - flags = { - debounce_text_changes = 150 - } - }) -end - -nvim_lsp.gopls.setup({ - capabilities = capabilities, - on_attach = on_attach, - settings = { - gopls = { - } - } -}) - -local runtime_path = vim.split(package.path, ';') -table.insert(runtime_path, "lua/?.lua") -table.insert(runtime_path, "lua/?/init.lua") -nvim_lsp.sumneko_lua.setup({ - capabilities = capabilities, - on_attach = on_attach, - cmd = { "/sbin/lua-language-server", "-E", "/usr/lib/lua-language-server/main.lua" }, - settings = { - Lua = { - runtime = { - version = "LuaJIT", - path = runtime_path - }, - diagnostics = { - globals = { "vim" } - }, - workspace = { - library = vim.api.nvim_get_runtime_file("", true) - }, - telemetry = { - enable = false - } - } - } -}) + server:setup(opts) +end) require("luasnip/loaders/from_vscode").lazy_load() - --- Auto formatting -vim.cmd([[autocmd BufWritePre * lua vim.lsp.buf.formatting_sync(nil, 1000)]]) -vim.cmd([[autocmd BufWritePre *.ts,*.js,*.jsx,*.tsx,*.py ALEFix]]) diff --git a/config/nvim/lua/remaps.lua b/config/nvim/lua/remaps.lua index 07a5acf..da6c83a 100644 --- a/config/nvim/lua/remaps.lua +++ b/config/nvim/lua/remaps.lua @@ -1,14 +1,11 @@ local function map(mode, shortcut, command) - vim.api.nvim_set_keymap(mode, shortcut, command, { noremap = true, silent = true }) + vim.api.nvim_set_keymap(mode, shortcut, command, + {noremap = true, silent = true}) end -local function nmap(shortcut, command) - map("n", shortcut, command) -end +local function nmap(shortcut, command) map("n", shortcut, command) end -local function vmap(shortcut, command) - map("v", shortcut, command) -end +local function vmap(shortcut, command) map("v", shortcut, command) end -- Quickly save/quit vim nmap("w", ":w")