From 7cf73775036c3424dd5e2a85effe3883cf0b0ca8 Mon Sep 17 00:00:00 2001 From: Gustaf Rydholm Date: Wed, 12 Jan 2022 21:22:47 +0100 Subject: Refactor the file structure --- lua/config/autopairs.lua | 34 ++++++ lua/config/bufferline.lua | 167 +++++++++++++++++++++++++++++ lua/config/cmp.lua | 132 +++++++++++++++++++++++ lua/config/colorscheme.lua | 9 ++ lua/config/comment.lua | 24 +++++ lua/config/gitsigns.lua | 50 +++++++++ lua/config/init.lua | 12 +++ lua/config/lsp/handlers.lua | 106 ++++++++++++++++++ lua/config/lsp/init.lua | 9 ++ lua/config/lsp/lsp-installer.lua | 34 ++++++ lua/config/lsp/settings/jsonls.lua | 178 +++++++++++++++++++++++++++++++ lua/config/lsp/settings/pyright.lua | 12 +++ lua/config/lsp/settings/sumneko_lua.lua | 18 ++++ lua/config/nvim-tree.lua | 100 +++++++++++++++++ lua/config/telescope.lua | 100 +++++++++++++++++ lua/config/treesitter.lua | 22 ++++ lua/installer.lua | 55 ++++++++++ lua/plugins.lua | 53 +++++++++ lua/plugins/config/cmp.lua | 132 ----------------------- lua/plugins/config/colorscheme.lua | 9 -- lua/plugins/config/init.lua | 6 -- lua/plugins/config/telescope.lua | 100 ----------------- lua/plugins/config/treesitter.lua | 19 ---- lua/plugins/installer.lua | 55 ---------- lua/plugins/lsp/handlers.lua | 106 ------------------ lua/plugins/lsp/init.lua | 9 -- lua/plugins/lsp/lsp-installer.lua | 34 ------ lua/plugins/lsp/settings/jsonls.lua | 178 ------------------------------- lua/plugins/lsp/settings/pyright.lua | 12 --- lua/plugins/lsp/settings/sumneko_lua.lua | 18 ---- lua/plugins/plugins.lua | 36 ------- 31 files changed, 1115 insertions(+), 714 deletions(-) create mode 100644 lua/config/autopairs.lua create mode 100644 lua/config/bufferline.lua create mode 100644 lua/config/cmp.lua create mode 100644 lua/config/colorscheme.lua create mode 100644 lua/config/comment.lua create mode 100644 lua/config/gitsigns.lua create mode 100644 lua/config/init.lua create mode 100644 lua/config/lsp/handlers.lua create mode 100644 lua/config/lsp/init.lua create mode 100644 lua/config/lsp/lsp-installer.lua create mode 100644 lua/config/lsp/settings/jsonls.lua create mode 100644 lua/config/lsp/settings/pyright.lua create mode 100644 lua/config/lsp/settings/sumneko_lua.lua create mode 100644 lua/config/nvim-tree.lua create mode 100644 lua/config/telescope.lua create mode 100644 lua/config/treesitter.lua create mode 100644 lua/installer.lua create mode 100644 lua/plugins.lua delete mode 100644 lua/plugins/config/cmp.lua delete mode 100644 lua/plugins/config/colorscheme.lua delete mode 100644 lua/plugins/config/init.lua delete mode 100644 lua/plugins/config/telescope.lua delete mode 100644 lua/plugins/config/treesitter.lua delete mode 100644 lua/plugins/installer.lua delete mode 100644 lua/plugins/lsp/handlers.lua delete mode 100644 lua/plugins/lsp/init.lua delete mode 100644 lua/plugins/lsp/lsp-installer.lua delete mode 100644 lua/plugins/lsp/settings/jsonls.lua delete mode 100644 lua/plugins/lsp/settings/pyright.lua delete mode 100644 lua/plugins/lsp/settings/sumneko_lua.lua delete mode 100644 lua/plugins/plugins.lua diff --git a/lua/config/autopairs.lua b/lua/config/autopairs.lua new file mode 100644 index 0000000..027135b --- /dev/null +++ b/lua/config/autopairs.lua @@ -0,0 +1,34 @@ +-- Autopair for brackets and quote symbols. + +local status_ok, npairs = pcall(require, "nvim-autopairs") +if not status_ok then + return +end + +npairs.setup({ + check_ts = true, + ts_config = { + lua = { "string", "source" }, + javascript = { "string", "template_string" }, + java = false, + }, + disable_filetype = { "TelescopePrompt", "spectre_panel" }, + fast_wrap = { + map = "", + chars = { "{", "[", "(", '"', "'" }, + pattern = string.gsub([[ [%'%"%)%>%]%)%}%,] ]], "%s+", ""), + offset = 0, -- Offset from pattern match + end_key = "$", + keys = "qwertyuiopzxcvbnmasdfghjkl", + check_comma = true, + highlight = "PmenuSel", + highlight_grey = "LineNr", + }, +}) + +local cmp_autopairs = require("nvim-autopairs.completion.cmp") +local cmp_status_ok, cmp = pcall(require, "cmp") +if not cmp_status_ok then + return +end +cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done({ map_char = { tex = "" } })) diff --git a/lua/config/bufferline.lua b/lua/config/bufferline.lua new file mode 100644 index 0000000..1259af3 --- /dev/null +++ b/lua/config/bufferline.lua @@ -0,0 +1,167 @@ +-- Adds a bar that displays open buffers. + +local status_ok, bufferline = pcall(require, "bufferline") +if not status_ok then + return +end + +bufferline.setup({ + options = { + numbers = "none", -- | "ordinal" | "buffer_id" | "both" | function({ ordinal, id, lower, raise }): string, + close_command = "Bdelete! %d", -- can be a string | function, see "Mouse actions" + right_mouse_command = nil, -- can be a string | function, see "Mouse actions" + left_mouse_command = nil, -- can be a string | function, see "Mouse actions" + middle_mouse_command = nil, -- can be a string | function, see "Mouse actions" + -- NOTE: this plugin is designed with this icon in mind, + -- and so changing this is NOT recommended, this is intended + -- as an escape hatch for people who cannot bear it for whatever reason + indicator_icon = "▎", + buffer_close_icon = "", + modified_icon = "●", + close_icon = "", + left_trunc_marker = "", + right_trunc_marker = "", + --- name_formatter can be used to change the buffer's label in the bufferline. + --- Please note some names can/will break the + --- bufferline so use this at your discretion knowing that it has + --- some limitations that will *NOT* be fixed. + -- name_formatter = function(buf) -- buf contains a "name", "path" and "bufnr" + -- -- remove extension from markdown files for example + -- if buf.name:match('%.md') then + -- return vim.fn.fnamemodify(buf.name, ':t:r') + -- end + -- end, + max_name_length = 30, + max_prefix_length = 30, -- prefix used when a buffer is de-duplicated + tab_size = 21, + diagnostics = false, -- | "nvim_lsp" | "coc", + diagnostics_update_in_insert = false, + -- diagnostics_indicator = function(count, level, diagnostics_dict, context) + -- return "("..count..")" + -- end, + -- NOTE: this will be called a lot so don't do any heavy processing here + -- custom_filter = function(buf_number) + -- -- filter out filetypes you don't want to see + -- if vim.bo[buf_number].filetype ~= "" then + -- return true + -- end + -- -- filter out by buffer name + -- if vim.fn.bufname(buf_number) ~= "" then + -- return true + -- end + -- -- filter out based on arbitrary rules + -- -- e.g. filter out vim wiki buffer from tabline in your work repo + -- if vim.fn.getcwd() == "" and vim.bo[buf_number].filetype ~= "wiki" then + -- return true + -- end + -- end, + offsets = { { filetype = "NvimTree", text = "", padding = 1 } }, + show_buffer_icons = true, + show_buffer_close_icons = false, + show_close_icon = false, + show_tab_indicators = true, + persist_buffer_sort = true, -- whether or not custom sorted buffers should persist + -- can also be a table containing 2 custom separators + -- [focused and unfocused]. eg: { '|', '|' } + separator_style = "thin", -- | "thick" | "thin" | { 'any', 'any' }, + enforce_regular_tabs = true, + always_show_bufferline = true, + -- sort_by = 'id' | 'extension' | 'relative_directory' | 'directory' | 'tabs' | function(buffer_a, buffer_b) + -- -- add custom logic + -- return buffer_a.modified > buffer_b.modified + -- end + }, + highlights = { + fill = { + guifg = { attribute = "fg", highlight = "#ff0000" }, + guibg = { attribute = "bg", highlight = "TabLine" }, + }, + background = { + guifg = { attribute = "fg", highlight = "TabLine" }, + guibg = { attribute = "bg", highlight = "TabLine" }, + }, + + -- buffer_selected = { + -- guifg = {attribute='fg',highlight='#ff0000'}, + -- guibg = {attribute='bg',highlight='#0000ff'}, + -- gui = 'none' + -- }, + buffer_visible = { + guifg = { attribute = "fg", highlight = "TabLine" }, + guibg = { attribute = "bg", highlight = "TabLine" }, + }, + + close_button = { + guifg = { attribute = "fg", highlight = "TabLine" }, + guibg = { attribute = "bg", highlight = "TabLine" }, + }, + close_button_visible = { + guifg = { attribute = "fg", highlight = "TabLine" }, + guibg = { attribute = "bg", highlight = "TabLine" }, + }, + -- close_button_selected = { + -- guifg = {attribute='fg',highlight='TabLineSel'}, + -- guibg ={attribute='bg',highlight='TabLineSel'} + -- }, + + tab_selected = { + guifg = { attribute = "fg", highlight = "Normal" }, + guibg = { attribute = "bg", highlight = "Normal" }, + }, + tab = { + guifg = { attribute = "fg", highlight = "TabLine" }, + guibg = { attribute = "bg", highlight = "TabLine" }, + }, + tab_close = { + -- guifg = {attribute='fg',highlight='LspDiagnosticsDefaultError'}, + guifg = { attribute = "fg", highlight = "TabLineSel" }, + guibg = { attribute = "bg", highlight = "Normal" }, + }, + + duplicate_selected = { + guifg = { attribute = "fg", highlight = "TabLineSel" }, + guibg = { attribute = "bg", highlight = "TabLineSel" }, + gui = "italic", + }, + duplicate_visible = { + guifg = { attribute = "fg", highlight = "TabLine" }, + guibg = { attribute = "bg", highlight = "TabLine" }, + gui = "italic", + }, + duplicate = { + guifg = { attribute = "fg", highlight = "TabLine" }, + guibg = { attribute = "bg", highlight = "TabLine" }, + gui = "italic", + }, + + modified = { + guifg = { attribute = "fg", highlight = "TabLine" }, + guibg = { attribute = "bg", highlight = "TabLine" }, + }, + modified_selected = { + guifg = { attribute = "fg", highlight = "Normal" }, + guibg = { attribute = "bg", highlight = "Normal" }, + }, + modified_visible = { + guifg = { attribute = "fg", highlight = "TabLine" }, + guibg = { attribute = "bg", highlight = "TabLine" }, + }, + + separator = { + guifg = { attribute = "bg", highlight = "TabLine" }, + guibg = { attribute = "bg", highlight = "TabLine" }, + }, + separator_selected = { + guifg = { attribute = "bg", highlight = "Normal" }, + guibg = { attribute = "bg", highlight = "Normal" }, + }, + -- separator_visible = { + -- guifg = {attribute='bg',highlight='TabLine'}, + -- guibg = {attribute='bg',highlight='TabLine'} + -- }, + indicator_selected = { + guifg = { attribute = "fg", highlight = "LspDiagnosticsDefaultHint" }, + guibg = { attribute = "bg", highlight = "Normal" }, + }, + }, +}) diff --git a/lua/config/cmp.lua b/lua/config/cmp.lua new file mode 100644 index 0000000..27114ca --- /dev/null +++ b/lua/config/cmp.lua @@ -0,0 +1,132 @@ +-- Configuration for completion plugin. + +local cmp_status_ok, cmp = pcall(require, "cmp") +if not cmp_status_ok then + return +end + +local snip_status_ok, luasnip = pcall(require, "luasnip") +if not snip_status_ok then + return +end + +require("luasnip/loaders/from_vscode").lazy_load() + +local check_backspace = function() + local col = vim.fn.col(".") - 1 + return col == 0 or vim.fn.getline("."):sub(col, col):match("%s") +end + +local kind_icons = { + Text = "", + Method = "m", + 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) + luasnip.lsp_expand(args.body) -- For `luasnip` users. + end, + }, + mapping = { + [""] = cmp.mapping.select_prev_item(), + [""] = cmp.mapping.select_next_item(), + [""] = cmp.mapping(cmp.mapping.scroll_docs(-1), { "i", "c" }), + [""] = cmp.mapping(cmp.mapping.scroll_docs(1), { "i", "c" }), + [""] = cmp.mapping(cmp.mapping.complete(), { "i", "c" }), + [""] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `` mapping. + [""] = cmp.mapping({ + i = cmp.mapping.abort(), + c = cmp.mapping.close(), + }), + -- Accept currently selected item. If none selected, `select` first item. + -- Set `select` to `false` to only confirm explicitly selected items. + [""] = cmp.mapping.confirm({ select = true }), + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.expandable() then + luasnip.expand() + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + elseif check_backspace() then + fallback() + 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) + -- Kind icons + vim_item.kind = string.format("%s", kind_icons[vim_item.kind]) + -- vim_item.kind = string.format('%s %s', kind_icons[vim_item.kind], vim_item.kind) -- This concatonates the icons with the name of the item kind + vim_item.menu = ({ + nvim_lsp = "[LSP]", + nvim_lua = "[NVIM_LUA]", + luasnip = "[Snippet]", + buffer = "[Buffer]", + path = "[Path]", + })[entry.source.name] + return vim_item + end, + }, + -- TODO: check out more sources + sources = { + { name = "nvim_lsp" }, + { name = "nvim_lua" }, + { name = "luasnip" }, + { name = "buffer" }, + { name = "path" }, + }, + confirm_opts = { + behavior = cmp.ConfirmBehavior.Replace, + select = false, + }, + documentation = { + border = { "╭", "─", "╮", "│", "╯", "─", "╰", "│" }, + }, + experimental = { + ghost_text = false, + native_menu = false, + }, +}) diff --git a/lua/config/colorscheme.lua b/lua/config/colorscheme.lua new file mode 100644 index 0000000..5f0654d --- /dev/null +++ b/lua/config/colorscheme.lua @@ -0,0 +1,9 @@ +-- Neovim colorscheme. + +local colorscheme = "default" + +local status_ok, _ = pcall(vim.cmd, "colorscheme " .. colorscheme) +if not status_ok then + vim.notify("colorscheme " .. colorscheme .. " not found!") + return +end diff --git a/lua/config/comment.lua b/lua/config/comment.lua new file mode 100644 index 0000000..740697e --- /dev/null +++ b/lua/config/comment.lua @@ -0,0 +1,24 @@ +-- Language aware commenting. + +local status_ok, comment = pcall(require, "Comment") +if not status_ok then + return +end + +comment.setup({ + pre_hook = function(ctx) + local U = require("Comment.utils") + + local location = nil + if ctx.ctype == U.ctype.block then + location = require("ts_context_commentstring.utils").get_cursor_location() + elseif ctx.cmotion == U.cmotion.v or ctx.cmotion == U.cmotion.V then + location = require("ts_context_commentstring.utils").get_visual_start_location() + end + + return require("ts_context_commentstring.internal").calculate_commentstring({ + key = ctx.ctype == U.ctype.line and "__default" or "__multiline", + location = location, + }) + end, +}) diff --git a/lua/config/gitsigns.lua b/lua/config/gitsigns.lua new file mode 100644 index 0000000..05aa495 --- /dev/null +++ b/lua/config/gitsigns.lua @@ -0,0 +1,50 @@ +-- Add git signs to source files. + +local status_ok, gitsigns = pcall(require, "gitsigns") +if not status_ok then + return +end + +gitsigns.setup({ + signs = { + add = { hl = "GitSignsAdd", text = "▎", numhl = "GitSignsAddNr", linehl = "GitSignsAddLn" }, + change = { hl = "GitSignsChange", text = "▎", numhl = "GitSignsChangeNr", linehl = "GitSignsChangeLn" }, + delete = { hl = "GitSignsDelete", text = "契", numhl = "GitSignsDeleteNr", linehl = "GitSignsDeleteLn" }, + topdelete = { hl = "GitSignsDelete", text = "契", numhl = "GitSignsDeleteNr", linehl = "GitSignsDeleteLn" }, + changedelete = { hl = "GitSignsChange", text = "▎", numhl = "GitSignsChangeNr", linehl = "GitSignsChangeLn" }, + }, + signcolumn = true, -- Toggle with `:Gitsigns toggle_signs` + numhl = false, -- Toggle with `:Gitsigns toggle_numhl` + linehl = false, -- Toggle with `:Gitsigns toggle_linehl` + word_diff = false, -- Toggle with `:Gitsigns toggle_word_diff` + watch_gitdir = { + interval = 1000, + follow_files = true, + }, + attach_to_untracked = true, + current_line_blame = false, -- Toggle with `:Gitsigns toggle_current_line_blame` + current_line_blame_opts = { + virt_text = true, + virt_text_pos = "eol", -- 'eol' | 'overlay' | 'right_align' + delay = 1000, + ignore_whitespace = false, + }, + current_line_blame_formatter_opts = { + relative_time = false, + }, + sign_priority = 6, + update_debounce = 100, + status_formatter = nil, -- Use default + max_file_length = 40000, + preview_config = { + -- Options passed to nvim_open_win + border = "single", + style = "minimal", + relative = "cursor", + row = 0, + col = 1, + }, + yadm = { + enable = false, + }, +}) diff --git a/lua/config/init.lua b/lua/config/init.lua new file mode 100644 index 0000000..31a1aa9 --- /dev/null +++ b/lua/config/init.lua @@ -0,0 +1,12 @@ +-- Loads all plugin configs. + +require("config.colorscheme") +require("config.cmp") +require("config.lsp") +require("config.telescope") +require("config.treesitter") +require("config.autopairs") +require("config.comment") +require("config.gitsigns") +require("config.nvim-tree") +require("config.bufferline") diff --git a/lua/config/lsp/handlers.lua b/lua/config/lsp/handlers.lua new file mode 100644 index 0000000..3dcf0dc --- /dev/null +++ b/lua/config/lsp/handlers.lua @@ -0,0 +1,106 @@ +-- Handler for LSP servers. + +local M = {} + +-- TODO: backfill this to template +M.setup = function() + local signs = { + { name = "DiagnosticSignError", text = "" }, + { name = "DiagnosticSignWarn", text = "" }, + { name = "DiagnosticSignHint", text = "" }, + { name = "DiagnosticSignInfo", text = "" }, + } + + for _, sign in ipairs(signs) do + vim.fn.sign_define(sign.name, { texthl = sign.name, text = sign.text, numhl = "" }) + end + + local config = { + -- disable virtual text + virtual_text = false, + -- show signs + signs = { + active = signs, + }, + update_in_insert = true, + underline = true, + severity_sort = true, + float = { + focusable = false, + style = "minimal", + border = "rounded", + source = "always", + header = "", + prefix = "", + }, + } + + vim.diagnostic.config(config) + + vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { + border = "rounded", + }) + + vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, { + border = "rounded", + }) +end + +local function lsp_highlight_document(client) + -- Set autocommands conditional on server_capabilities + if client.resolved_capabilities.document_highlight then + vim.api.nvim_exec( + [[ + augroup lsp_document_highlight + autocmd! * + autocmd CursorHold lua vim.lsp.buf.document_highlight() + autocmd CursorMoved lua vim.lsp.buf.clear_references() + augroup END + ]], + false + ) + end +end + +local function lsp_keymaps(bufnr) + local opts = { noremap = true, silent = true } + vim.api.nvim_buf_set_keymap(bufnr, "n", "gD", "lua vim.lsp.buf.declaration()", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "gd", "lua vim.lsp.buf.definition()", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "K", "lua vim.lsp.buf.hover()", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "gi", "lua vim.lsp.buf.implementation()", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "", "lua vim.lsp.buf.signature_help()", opts) + -- vim.api.nvim_buf_set_keymap(bufnr, "n", "rn", "lua vim.lsp.buf.rename()", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "gr", "lua vim.lsp.buf.references()", opts) + -- vim.api.nvim_buf_set_keymap(bufnr, "n", "ca", "lua vim.lsp.buf.code_action()", opts) + -- vim.api.nvim_buf_set_keymap(bufnr, "n", "f", "lua vim.diagnostic.open_float()", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "[d", 'lua vim.diagnostic.goto_prev({ border = "rounded" })', opts) + vim.api.nvim_buf_set_keymap( + bufnr, + "n", + "gl", + 'lua vim.lsp.diagnostic.show_line_diagnostics({ border = "rounded" })', + opts + ) + vim.api.nvim_buf_set_keymap(bufnr, "n", "]d", 'lua vim.diagnostic.goto_next({ border = "rounded" })', opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "q", "lua vim.diagnostic.setloclist()", opts) + vim.cmd([[ command! Format execute 'lua vim.lsp.buf.formatting()' ]]) +end + +M.on_attach = function(client, bufnr) + if client.name == "tsserver" then + client.resolved_capabilities.document_formatting = false + end + lsp_keymaps(bufnr) + lsp_highlight_document(client) +end + +local capabilities = vim.lsp.protocol.make_client_capabilities() + +local status_ok, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp") +if not status_ok then + return +end + +M.capabilities = cmp_nvim_lsp.update_capabilities(capabilities) + +return M diff --git a/lua/config/lsp/init.lua b/lua/config/lsp/init.lua new file mode 100644 index 0000000..b231014 --- /dev/null +++ b/lua/config/lsp/init.lua @@ -0,0 +1,9 @@ +-- Loads the LSP module. + +local status_ok, _ = pcall(require, "lspconfig") +if not status_ok then + return +end + +require("config.lsp.lsp-installer") +require("config.lsp.handlers").setup() diff --git a/lua/config/lsp/lsp-installer.lua b/lua/config/lsp/lsp-installer.lua new file mode 100644 index 0000000..876adad --- /dev/null +++ b/lua/config/lsp/lsp-installer.lua @@ -0,0 +1,34 @@ +-- LSP installer. + +local status_ok, lsp_installer = pcall(require, "nvim-lsp-installer") +if not status_ok then + return +end + +-- Register a handler that will be called for all installed servers. +-- Alternatively, you may also register handlers on specific server instances instead (see example below). +lsp_installer.on_server_ready(function(server) + local opts = { + on_attach = require("plugins.lsp.handlers").on_attach, + capabilities = require("plugins.lsp.handlers").capabilities, + } + + if server.name == "jsonls" then + local jsonls_opts = require("plugins.lsp.settings.jsonls") + opts = vim.tbl_deep_extend("force", jsonls_opts, opts) + end + + if server.name == "sumneko_lua" then + local sumneko_opts = require("plugins.lsp.settings.sumneko_lua") + opts = vim.tbl_deep_extend("force", sumneko_opts, opts) + end + + if server.name == "pyright" then + local pyright_opts = require("plugins.lsp.settings.pyright") + opts = vim.tbl_deep_extend("force", pyright_opts, opts) + end + + -- This setup() function is exactly the same as lspconfig's setup function. + -- Refer to https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md + server:setup(opts) +end) diff --git a/lua/config/lsp/settings/jsonls.lua b/lua/config/lsp/settings/jsonls.lua new file mode 100644 index 0000000..bcc5f65 --- /dev/null +++ b/lua/config/lsp/settings/jsonls.lua @@ -0,0 +1,178 @@ +-- A Json language server config. +-- Find more schemas here: https://www.schemastore.org/json/ + +local schemas = { + { + description = "TypeScript compiler configuration file", + fileMatch = { + "tsconfig.json", + "tsconfig.*.json", + }, + url = "https://json.schemastore.org/tsconfig.json", + }, + { + description = "Lerna config", + fileMatch = { "lerna.json" }, + url = "https://json.schemastore.org/lerna.json", + }, + { + description = "Babel configuration", + fileMatch = { + ".babelrc.json", + ".babelrc", + "babel.config.json", + }, + url = "https://json.schemastore.org/babelrc.json", + }, + { + description = "ESLint config", + fileMatch = { + ".eslintrc.json", + ".eslintrc", + }, + url = "https://json.schemastore.org/eslintrc.json", + }, + { + description = "Bucklescript config", + fileMatch = { "bsconfig.json" }, + url = "https://raw.githubusercontent.com/rescript-lang/rescript-compiler/8.2.0/docs/docson/build-schema.json", + }, + { + description = "Prettier config", + fileMatch = { + ".prettierrc", + ".prettierrc.json", + "prettier.config.json", + }, + url = "https://json.schemastore.org/prettierrc", + }, + { + description = "Vercel Now config", + fileMatch = { "now.json" }, + url = "https://json.schemastore.org/now", + }, + { + description = "Stylelint config", + fileMatch = { + ".stylelintrc", + ".stylelintrc.json", + "stylelint.config.json", + }, + url = "https://json.schemastore.org/stylelintrc", + }, + { + description = "A JSON schema for the ASP.NET LaunchSettings.json files", + fileMatch = { "launchsettings.json" }, + url = "https://json.schemastore.org/launchsettings.json", + }, + { + description = "Schema for CMake Presets", + fileMatch = { + "CMakePresets.json", + "CMakeUserPresets.json", + }, + url = "https://raw.githubusercontent.com/Kitware/CMake/master/Help/manual/presets/schema.json", + }, + { + description = "Configuration file as an alternative for configuring your repository in the settings page.", + fileMatch = { + ".codeclimate.json", + }, + url = "https://json.schemastore.org/codeclimate.json", + }, + { + description = "LLVM compilation database", + fileMatch = { + "compile_commands.json", + }, + url = "https://json.schemastore.org/compile-commands.json", + }, + { + description = "Config file for Command Task Runner", + fileMatch = { + "commands.json", + }, + url = "https://json.schemastore.org/commands.json", + }, + { + description = "AWS CloudFormation provides a common language for you to describe and provision all the infrastructure resources in your cloud environment.", + fileMatch = { + "*.cf.json", + "cloudformation.json", + }, + url = "https://raw.githubusercontent.com/awslabs/goformation/v5.2.9/schema/cloudformation.schema.json", + }, + { + description = "The AWS Serverless Application Model (AWS SAM, previously known as Project Flourish) extends AWS CloudFormation to provide a simplified way of defining the Amazon API Gateway APIs, AWS Lambda functions, and Amazon DynamoDB tables needed by your serverless application.", + fileMatch = { + "serverless.template", + "*.sam.json", + "sam.json", + }, + url = "https://raw.githubusercontent.com/awslabs/goformation/v5.2.9/schema/sam.schema.json", + }, + { + description = "Json schema for properties json file for a GitHub Workflow template", + fileMatch = { + ".github/workflow-templates/**.properties.json", + }, + url = "https://json.schemastore.org/github-workflow-template-properties.json", + }, + { + description = "golangci-lint configuration file", + fileMatch = { + ".golangci.toml", + ".golangci.json", + }, + url = "https://json.schemastore.org/golangci-lint.json", + }, + { + description = "JSON schema for the JSON Feed format", + fileMatch = { + "feed.json", + }, + url = "https://json.schemastore.org/feed.json", + versions = { + ["1"] = "https://json.schemastore.org/feed-1.json", + ["1.1"] = "https://json.schemastore.org/feed.json", + }, + }, + { + description = "Packer template JSON configuration", + fileMatch = { + "packer.json", + }, + url = "https://json.schemastore.org/packer.json", + }, + { + description = "NPM configuration file", + fileMatch = { + "package.json", + }, + url = "https://json.schemastore.org/package.json", + }, + { + description = "Resume json", + fileMatch = { "resume.json" }, + url = "https://raw.githubusercontent.com/jsonresume/resume-schema/v1.0.0/schema.json", + }, +} + +local opts = { + settings = { + json = { + schemas = schemas, + }, + }, + setup = { + commands = { + Format = { + function() + vim.lsp.buf.range_formatting({}, { 0, 0 }, { vim.fn.line("$"), 0 }) + end, + }, + }, + }, +} + +return opts diff --git a/lua/config/lsp/settings/pyright.lua b/lua/config/lsp/settings/pyright.lua new file mode 100644 index 0000000..d07ae8c --- /dev/null +++ b/lua/config/lsp/settings/pyright.lua @@ -0,0 +1,12 @@ +-- Config for pyright language server. + +return { + settings = { + + python = { + analysis = { + typeCheckingMode = "off", + }, + }, + }, +} diff --git a/lua/config/lsp/settings/sumneko_lua.lua b/lua/config/lsp/settings/sumneko_lua.lua new file mode 100644 index 0000000..d7957c1 --- /dev/null +++ b/lua/config/lsp/settings/sumneko_lua.lua @@ -0,0 +1,18 @@ +-- Config for a Lua language server. + +return { + settings = { + + Lua = { + diagnostics = { + globals = { "vim" }, + }, + workspace = { + library = { + [vim.fn.expand("$VIMRUNTIME/lua")] = true, + [vim.fn.stdpath("config") .. "/lua"] = true, + }, + }, + }, + }, +} diff --git a/lua/config/nvim-tree.lua b/lua/config/nvim-tree.lua new file mode 100644 index 0000000..c48a8e4 --- /dev/null +++ b/lua/config/nvim-tree.lua @@ -0,0 +1,100 @@ +-- A file explorer. + +vim.g.nvim_tree_icons = { + default = "", + symlink = "", + git = { + unstaged = "", + staged = "S", + unmerged = "", + renamed = "➜", + deleted = "", + untracked = "U", + ignored = "◌", + }, + folder = { + default = "", + open = "", + empty = "", + empty_open = "", + symlink = "", + }, +} + +local status_ok, nvim_tree = pcall(require, "nvim-tree") +if not status_ok then + return +end + +local config_status_ok, nvim_tree_config = pcall(require, "nvim-tree.config") +if not config_status_ok then + return +end + +local tree_cb = nvim_tree_config.nvim_tree_callback + +nvim_tree.setup({ + disable_netrw = true, + hijack_netrw = true, + open_on_setup = false, + ignore_ft_on_setup = { + "startify", + "dashboard", + "alpha", + }, + auto_close = true, + open_on_tab = false, + hijack_cursor = false, + update_cwd = true, + update_to_buf_dir = { + enable = true, + auto_open = true, + }, + diagnostics = { + enable = true, + icons = { + hint = "", + info = "", + warning = "", + error = "", + }, + }, + update_focused_file = { + enable = true, + update_cwd = true, + ignore_list = {}, + }, + git = { + enable = true, + ignore = true, + timeout = 500, + }, + view = { + width = 30, + height = 30, + hide_root_folder = false, + side = "left", + auto_resize = true, + mappings = { + custom_only = false, + list = { + { key = { "l", "", "o" }, cb = tree_cb("edit") }, + { key = "h", cb = tree_cb("close_node") }, + { key = "v", cb = tree_cb("vsplit") }, + }, + }, + number = false, + relativenumber = false, + }, + quit_on_open = 0, + git_hl = 1, + disable_window_picker = 0, + root_folder_modifier = ":t", + show_icons = { + git = 1, + folders = 1, + files = 1, + folder_arrows = 1, + tree_width = 30, + }, +}) diff --git a/lua/config/telescope.lua b/lua/config/telescope.lua new file mode 100644 index 0000000..ff65505 --- /dev/null +++ b/lua/config/telescope.lua @@ -0,0 +1,100 @@ +-- Telescope a highly extendable fuzzy finder over lists. + +local status_ok, telescope = pcall(require, "telescope") +if not status_ok then + return +end + +telescope.load_extension("media_files") + +local actions = require("telescope.actions") + +telescope.setup({ + defaults = { + + prompt_prefix = " ", + selection_caret = " ", + path_display = { "smart" }, + + mappings = { + i = { + [""] = actions.cycle_history_next, + [""] = actions.cycle_history_prev, + + [""] = actions.move_selection_next, + [""] = actions.move_selection_previous, + + [""] = actions.close, + + [""] = actions.move_selection_next, + [""] = actions.move_selection_previous, + + [""] = actions.select_default, + [""] = actions.select_horizontal, + [""] = actions.select_vertical, + [""] = actions.select_tab, + + [""] = actions.preview_scrolling_up, + [""] = actions.preview_scrolling_down, + + [""] = actions.results_scrolling_up, + [""] = actions.results_scrolling_down, + + [""] = actions.toggle_selection + actions.move_selection_worse, + [""] = actions.toggle_selection + actions.move_selection_better, + [""] = actions.send_to_qflist + actions.open_qflist, + [""] = actions.send_selected_to_qflist + actions.open_qflist, + [""] = actions.complete_tag, + [""] = actions.which_key, -- keys from pressing + }, + + n = { + [""] = actions.close, + [""] = actions.select_default, + [""] = actions.select_horizontal, + [""] = actions.select_vertical, + [""] = actions.select_tab, + + [""] = actions.toggle_selection + actions.move_selection_worse, + [""] = actions.toggle_selection + actions.move_selection_better, + [""] = actions.send_to_qflist + actions.open_qflist, + [""] = actions.send_selected_to_qflist + actions.open_qflist, + + ["j"] = actions.move_selection_next, + ["k"] = actions.move_selection_previous, + ["H"] = actions.move_to_top, + ["M"] = actions.move_to_middle, + ["L"] = actions.move_to_bottom, + + [""] = actions.move_selection_next, + [""] = actions.move_selection_previous, + ["gg"] = actions.move_to_top, + ["G"] = actions.move_to_bottom, + + [""] = actions.preview_scrolling_up, + [""] = actions.preview_scrolling_down, + + [""] = actions.results_scrolling_up, + [""] = actions.results_scrolling_down, + + ["?"] = actions.which_key, + }, + }, + }, + pickers = { + -- Default configuration for builtin pickers goes here: + -- picker_name = { + -- picker_config_key = value, + -- ... + -- } + -- Now the picker_config_key will be applied every time you call this + -- builtin picker + }, + extensions = { + -- Your extension configuration goes here: + -- extension_name = { + -- extension_config_key = value, + -- } + -- please take a look at the readme of the extension you want to configure + }, +}) diff --git a/lua/config/treesitter.lua b/lua/config/treesitter.lua new file mode 100644 index 0000000..0e1fe07 --- /dev/null +++ b/lua/config/treesitter.lua @@ -0,0 +1,22 @@ +-- Treesitter is a tool for building syntax trees for source files. +-- In the neovim context it helps with better coloring. + +local status_ok, treesitter = pcall(require, "nvim-treesitter.configs") +if not status_ok then + return +end + +treesitter.setup({ + ensure_installed = "maintained", + sync_install = false, + ignore_install = { "" }, -- List of parsers to ignore installing + autopairs = { + enable = true, + }, + highlight = { + enable = true, -- false will disable the whole extension + disable = { "" }, -- list of language that will be disabled + additional_vim_regex_highlighting = true, + }, + indent = { enable = true, disable = { "yaml" } }, +}) diff --git a/lua/installer.lua b/lua/installer.lua new file mode 100644 index 0000000..6c3b14a --- /dev/null +++ b/lua/installer.lua @@ -0,0 +1,55 @@ +-- Neovim packer installer. + +local fn = vim.fn +local plugins = require("plugins.plugins") + +-- Automatically install packer +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, + }) + print("Installing packer close and reopen Neovim...") + vim.cmd([[packadd packer.nvim]]) +end + +-- Autocommand that reloads neovim whenever you save the plugins.lua file +vim.cmd([[ + augroup packer_user_config + autocmd! + autocmd BufWritePost plugins.lua source | PackerSync + augroup end +]]) + +-- Use a protected call so we don't error out on first use +local status_ok, packer = pcall(require, "packer") +if not status_ok then + return +end + +-- Have packer use a popup window +packer.init({ + display = { + open_fn = function() + return require("packer.util").float({ border = "rounded" }) + end, + }, +}) + +-- Install your plugins here +return packer.startup(function(use) + for _, plugin in ipairs(plugins) do + use(plugin) + end + + -- Automatically set up your configuration after cloning packer.nvim + -- Put this at the end after all plugins + if PACKER_BOOTSTRAP then + require("packer").sync() + end +end) diff --git a/lua/plugins.lua b/lua/plugins.lua new file mode 100644 index 0000000..8789397 --- /dev/null +++ b/lua/plugins.lua @@ -0,0 +1,53 @@ +-- Neovim plugins + +return { + -- Base -- + { "wbthomason/packer.nvim" }, -- Have packer manage itself + { "nvim-lua/popup.nvim" }, -- An implementation of the Popup API from vim in Neovim + { "nvim-lua/plenary.nvim" }, -- Useful lua functions used ny lots of plugins + + -- Colorschemes -- + { "aktersnurra/no-clown-fiesta.nvim" }, -- My colorscheme + + -- cmp plugins -- + { "hrsh7th/nvim-cmp" }, -- The completion plugin + { "hrsh7th/cmp-buffer" }, -- buffer completions + { "hrsh7th/cmp-path" }, -- path completions + { "hrsh7th/cmp-cmdline" }, -- cmdline completions + { "saadparwaiz1/cmp_luasnip" }, -- snippet completions + + -- Snippets -- + { "L3MON4D3/LuaSnip" }, --snippet engine + { "rafamadriz/friendly-snippets" }, -- a bunch of snippets to use + + -- LSP -- + { "neovim/nvim-lspconfig" }, -- enable LSP + { "williamboman/nvim-lsp-installer" }, -- simple to use language server installer + + -- Telescope -- + { "nvim-telescope/telescope.nvim" }, + + -- Treesitter -- + { + "nvim-treesitter/nvim-treesitter", + run = ":TSUpdate", + }, + + -- Autopairs -- + { "windwp/nvim-autopairs" }, -- Autopairs, integrates with both cmp and treesitter + + -- Comments -- + { "numToStr/Comment.nvim" }, -- Easily comment stuff + { "JoosepAlviste/nvim-ts-context-commentstring" }, + + -- Gitsigns -- + { "lewis6991/gitsigns.nvim" }, + + -- Nvim tree -- + { "kyazdani42/nvim-web-devicons" }, + { "kyazdani42/nvim-tree.lua" }, + + -- Buffer handler + { "akinsho/bufferline.nvim" }, + { "moll/vim-bbye" }, +} diff --git a/lua/plugins/config/cmp.lua b/lua/plugins/config/cmp.lua deleted file mode 100644 index 27114ca..0000000 --- a/lua/plugins/config/cmp.lua +++ /dev/null @@ -1,132 +0,0 @@ --- Configuration for completion plugin. - -local cmp_status_ok, cmp = pcall(require, "cmp") -if not cmp_status_ok then - return -end - -local snip_status_ok, luasnip = pcall(require, "luasnip") -if not snip_status_ok then - return -end - -require("luasnip/loaders/from_vscode").lazy_load() - -local check_backspace = function() - local col = vim.fn.col(".") - 1 - return col == 0 or vim.fn.getline("."):sub(col, col):match("%s") -end - -local kind_icons = { - Text = "", - Method = "m", - 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) - luasnip.lsp_expand(args.body) -- For `luasnip` users. - end, - }, - mapping = { - [""] = cmp.mapping.select_prev_item(), - [""] = cmp.mapping.select_next_item(), - [""] = cmp.mapping(cmp.mapping.scroll_docs(-1), { "i", "c" }), - [""] = cmp.mapping(cmp.mapping.scroll_docs(1), { "i", "c" }), - [""] = cmp.mapping(cmp.mapping.complete(), { "i", "c" }), - [""] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `` mapping. - [""] = cmp.mapping({ - i = cmp.mapping.abort(), - c = cmp.mapping.close(), - }), - -- Accept currently selected item. If none selected, `select` first item. - -- Set `select` to `false` to only confirm explicitly selected items. - [""] = cmp.mapping.confirm({ select = true }), - [""] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_next_item() - elseif luasnip.expandable() then - luasnip.expand() - elseif luasnip.expand_or_jumpable() then - luasnip.expand_or_jump() - elseif check_backspace() then - fallback() - 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) - -- Kind icons - vim_item.kind = string.format("%s", kind_icons[vim_item.kind]) - -- vim_item.kind = string.format('%s %s', kind_icons[vim_item.kind], vim_item.kind) -- This concatonates the icons with the name of the item kind - vim_item.menu = ({ - nvim_lsp = "[LSP]", - nvim_lua = "[NVIM_LUA]", - luasnip = "[Snippet]", - buffer = "[Buffer]", - path = "[Path]", - })[entry.source.name] - return vim_item - end, - }, - -- TODO: check out more sources - sources = { - { name = "nvim_lsp" }, - { name = "nvim_lua" }, - { name = "luasnip" }, - { name = "buffer" }, - { name = "path" }, - }, - confirm_opts = { - behavior = cmp.ConfirmBehavior.Replace, - select = false, - }, - documentation = { - border = { "╭", "─", "╮", "│", "╯", "─", "╰", "│" }, - }, - experimental = { - ghost_text = false, - native_menu = false, - }, -}) diff --git a/lua/plugins/config/colorscheme.lua b/lua/plugins/config/colorscheme.lua deleted file mode 100644 index 5f0654d..0000000 --- a/lua/plugins/config/colorscheme.lua +++ /dev/null @@ -1,9 +0,0 @@ --- Neovim colorscheme. - -local colorscheme = "default" - -local status_ok, _ = pcall(vim.cmd, "colorscheme " .. colorscheme) -if not status_ok then - vim.notify("colorscheme " .. colorscheme .. " not found!") - return -end diff --git a/lua/plugins/config/init.lua b/lua/plugins/config/init.lua deleted file mode 100644 index bfbf750..0000000 --- a/lua/plugins/config/init.lua +++ /dev/null @@ -1,6 +0,0 @@ --- Loads all plugin configs. - -require("plugins.config.colorscheme") -require("plugins.config.cmp") -require("plugins.config.telescope") -require("plugins.config.treesitter") diff --git a/lua/plugins/config/telescope.lua b/lua/plugins/config/telescope.lua deleted file mode 100644 index ff65505..0000000 --- a/lua/plugins/config/telescope.lua +++ /dev/null @@ -1,100 +0,0 @@ --- Telescope a highly extendable fuzzy finder over lists. - -local status_ok, telescope = pcall(require, "telescope") -if not status_ok then - return -end - -telescope.load_extension("media_files") - -local actions = require("telescope.actions") - -telescope.setup({ - defaults = { - - prompt_prefix = " ", - selection_caret = " ", - path_display = { "smart" }, - - mappings = { - i = { - [""] = actions.cycle_history_next, - [""] = actions.cycle_history_prev, - - [""] = actions.move_selection_next, - [""] = actions.move_selection_previous, - - [""] = actions.close, - - [""] = actions.move_selection_next, - [""] = actions.move_selection_previous, - - [""] = actions.select_default, - [""] = actions.select_horizontal, - [""] = actions.select_vertical, - [""] = actions.select_tab, - - [""] = actions.preview_scrolling_up, - [""] = actions.preview_scrolling_down, - - [""] = actions.results_scrolling_up, - [""] = actions.results_scrolling_down, - - [""] = actions.toggle_selection + actions.move_selection_worse, - [""] = actions.toggle_selection + actions.move_selection_better, - [""] = actions.send_to_qflist + actions.open_qflist, - [""] = actions.send_selected_to_qflist + actions.open_qflist, - [""] = actions.complete_tag, - [""] = actions.which_key, -- keys from pressing - }, - - n = { - [""] = actions.close, - [""] = actions.select_default, - [""] = actions.select_horizontal, - [""] = actions.select_vertical, - [""] = actions.select_tab, - - [""] = actions.toggle_selection + actions.move_selection_worse, - [""] = actions.toggle_selection + actions.move_selection_better, - [""] = actions.send_to_qflist + actions.open_qflist, - [""] = actions.send_selected_to_qflist + actions.open_qflist, - - ["j"] = actions.move_selection_next, - ["k"] = actions.move_selection_previous, - ["H"] = actions.move_to_top, - ["M"] = actions.move_to_middle, - ["L"] = actions.move_to_bottom, - - [""] = actions.move_selection_next, - [""] = actions.move_selection_previous, - ["gg"] = actions.move_to_top, - ["G"] = actions.move_to_bottom, - - [""] = actions.preview_scrolling_up, - [""] = actions.preview_scrolling_down, - - [""] = actions.results_scrolling_up, - [""] = actions.results_scrolling_down, - - ["?"] = actions.which_key, - }, - }, - }, - pickers = { - -- Default configuration for builtin pickers goes here: - -- picker_name = { - -- picker_config_key = value, - -- ... - -- } - -- Now the picker_config_key will be applied every time you call this - -- builtin picker - }, - extensions = { - -- Your extension configuration goes here: - -- extension_name = { - -- extension_config_key = value, - -- } - -- please take a look at the readme of the extension you want to configure - }, -}) diff --git a/lua/plugins/config/treesitter.lua b/lua/plugins/config/treesitter.lua deleted file mode 100644 index 8feffc9..0000000 --- a/lua/plugins/config/treesitter.lua +++ /dev/null @@ -1,19 +0,0 @@ --- Treesitter is a tool for building syntax trees for source files. --- In the neovim context it helps with better coloring. - -local status_ok, treesitter = pcall(require, "nvim-treesitter.configs") -if not status_ok then - return -end - -treesitter.setup({ - ensure_installed = "maintained", - sync_install = false, - ignore_install = { "" }, -- List of parsers to ignore installing - highlight = { - enable = true, -- false will disable the whole extension - disable = { "" }, -- list of language that will be disabled - additional_vim_regex_highlighting = true, - }, - indent = { enable = true, disable = { "yaml" } }, -}) diff --git a/lua/plugins/installer.lua b/lua/plugins/installer.lua deleted file mode 100644 index 6c3b14a..0000000 --- a/lua/plugins/installer.lua +++ /dev/null @@ -1,55 +0,0 @@ --- Neovim packer installer. - -local fn = vim.fn -local plugins = require("plugins.plugins") - --- Automatically install packer -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, - }) - print("Installing packer close and reopen Neovim...") - vim.cmd([[packadd packer.nvim]]) -end - --- Autocommand that reloads neovim whenever you save the plugins.lua file -vim.cmd([[ - augroup packer_user_config - autocmd! - autocmd BufWritePost plugins.lua source | PackerSync - augroup end -]]) - --- Use a protected call so we don't error out on first use -local status_ok, packer = pcall(require, "packer") -if not status_ok then - return -end - --- Have packer use a popup window -packer.init({ - display = { - open_fn = function() - return require("packer.util").float({ border = "rounded" }) - end, - }, -}) - --- Install your plugins here -return packer.startup(function(use) - for _, plugin in ipairs(plugins) do - use(plugin) - end - - -- Automatically set up your configuration after cloning packer.nvim - -- Put this at the end after all plugins - if PACKER_BOOTSTRAP then - require("packer").sync() - end -end) diff --git a/lua/plugins/lsp/handlers.lua b/lua/plugins/lsp/handlers.lua deleted file mode 100644 index 3dcf0dc..0000000 --- a/lua/plugins/lsp/handlers.lua +++ /dev/null @@ -1,106 +0,0 @@ --- Handler for LSP servers. - -local M = {} - --- TODO: backfill this to template -M.setup = function() - local signs = { - { name = "DiagnosticSignError", text = "" }, - { name = "DiagnosticSignWarn", text = "" }, - { name = "DiagnosticSignHint", text = "" }, - { name = "DiagnosticSignInfo", text = "" }, - } - - for _, sign in ipairs(signs) do - vim.fn.sign_define(sign.name, { texthl = sign.name, text = sign.text, numhl = "" }) - end - - local config = { - -- disable virtual text - virtual_text = false, - -- show signs - signs = { - active = signs, - }, - update_in_insert = true, - underline = true, - severity_sort = true, - float = { - focusable = false, - style = "minimal", - border = "rounded", - source = "always", - header = "", - prefix = "", - }, - } - - vim.diagnostic.config(config) - - vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { - border = "rounded", - }) - - vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, { - border = "rounded", - }) -end - -local function lsp_highlight_document(client) - -- Set autocommands conditional on server_capabilities - if client.resolved_capabilities.document_highlight then - vim.api.nvim_exec( - [[ - augroup lsp_document_highlight - autocmd! * - autocmd CursorHold lua vim.lsp.buf.document_highlight() - autocmd CursorMoved lua vim.lsp.buf.clear_references() - augroup END - ]], - false - ) - end -end - -local function lsp_keymaps(bufnr) - local opts = { noremap = true, silent = true } - vim.api.nvim_buf_set_keymap(bufnr, "n", "gD", "lua vim.lsp.buf.declaration()", opts) - vim.api.nvim_buf_set_keymap(bufnr, "n", "gd", "lua vim.lsp.buf.definition()", opts) - vim.api.nvim_buf_set_keymap(bufnr, "n", "K", "lua vim.lsp.buf.hover()", opts) - vim.api.nvim_buf_set_keymap(bufnr, "n", "gi", "lua vim.lsp.buf.implementation()", opts) - vim.api.nvim_buf_set_keymap(bufnr, "n", "", "lua vim.lsp.buf.signature_help()", opts) - -- vim.api.nvim_buf_set_keymap(bufnr, "n", "rn", "lua vim.lsp.buf.rename()", opts) - vim.api.nvim_buf_set_keymap(bufnr, "n", "gr", "lua vim.lsp.buf.references()", opts) - -- vim.api.nvim_buf_set_keymap(bufnr, "n", "ca", "lua vim.lsp.buf.code_action()", opts) - -- vim.api.nvim_buf_set_keymap(bufnr, "n", "f", "lua vim.diagnostic.open_float()", opts) - vim.api.nvim_buf_set_keymap(bufnr, "n", "[d", 'lua vim.diagnostic.goto_prev({ border = "rounded" })', opts) - vim.api.nvim_buf_set_keymap( - bufnr, - "n", - "gl", - 'lua vim.lsp.diagnostic.show_line_diagnostics({ border = "rounded" })', - opts - ) - vim.api.nvim_buf_set_keymap(bufnr, "n", "]d", 'lua vim.diagnostic.goto_next({ border = "rounded" })', opts) - vim.api.nvim_buf_set_keymap(bufnr, "n", "q", "lua vim.diagnostic.setloclist()", opts) - vim.cmd([[ command! Format execute 'lua vim.lsp.buf.formatting()' ]]) -end - -M.on_attach = function(client, bufnr) - if client.name == "tsserver" then - client.resolved_capabilities.document_formatting = false - end - lsp_keymaps(bufnr) - lsp_highlight_document(client) -end - -local capabilities = vim.lsp.protocol.make_client_capabilities() - -local status_ok, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp") -if not status_ok then - return -end - -M.capabilities = cmp_nvim_lsp.update_capabilities(capabilities) - -return M diff --git a/lua/plugins/lsp/init.lua b/lua/plugins/lsp/init.lua deleted file mode 100644 index 0b8db93..0000000 --- a/lua/plugins/lsp/init.lua +++ /dev/null @@ -1,9 +0,0 @@ --- Loads the LSP module. - -local status_ok, _ = pcall(require, "lspconfig") -if not status_ok then - return -end - -require("plugins.lsp.lsp-installer") -require("plugins.lsp.handlers").setup() diff --git a/lua/plugins/lsp/lsp-installer.lua b/lua/plugins/lsp/lsp-installer.lua deleted file mode 100644 index 876adad..0000000 --- a/lua/plugins/lsp/lsp-installer.lua +++ /dev/null @@ -1,34 +0,0 @@ --- LSP installer. - -local status_ok, lsp_installer = pcall(require, "nvim-lsp-installer") -if not status_ok then - return -end - --- Register a handler that will be called for all installed servers. --- Alternatively, you may also register handlers on specific server instances instead (see example below). -lsp_installer.on_server_ready(function(server) - local opts = { - on_attach = require("plugins.lsp.handlers").on_attach, - capabilities = require("plugins.lsp.handlers").capabilities, - } - - if server.name == "jsonls" then - local jsonls_opts = require("plugins.lsp.settings.jsonls") - opts = vim.tbl_deep_extend("force", jsonls_opts, opts) - end - - if server.name == "sumneko_lua" then - local sumneko_opts = require("plugins.lsp.settings.sumneko_lua") - opts = vim.tbl_deep_extend("force", sumneko_opts, opts) - end - - if server.name == "pyright" then - local pyright_opts = require("plugins.lsp.settings.pyright") - opts = vim.tbl_deep_extend("force", pyright_opts, opts) - end - - -- This setup() function is exactly the same as lspconfig's setup function. - -- Refer to https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md - server:setup(opts) -end) diff --git a/lua/plugins/lsp/settings/jsonls.lua b/lua/plugins/lsp/settings/jsonls.lua deleted file mode 100644 index bcc5f65..0000000 --- a/lua/plugins/lsp/settings/jsonls.lua +++ /dev/null @@ -1,178 +0,0 @@ --- A Json language server config. --- Find more schemas here: https://www.schemastore.org/json/ - -local schemas = { - { - description = "TypeScript compiler configuration file", - fileMatch = { - "tsconfig.json", - "tsconfig.*.json", - }, - url = "https://json.schemastore.org/tsconfig.json", - }, - { - description = "Lerna config", - fileMatch = { "lerna.json" }, - url = "https://json.schemastore.org/lerna.json", - }, - { - description = "Babel configuration", - fileMatch = { - ".babelrc.json", - ".babelrc", - "babel.config.json", - }, - url = "https://json.schemastore.org/babelrc.json", - }, - { - description = "ESLint config", - fileMatch = { - ".eslintrc.json", - ".eslintrc", - }, - url = "https://json.schemastore.org/eslintrc.json", - }, - { - description = "Bucklescript config", - fileMatch = { "bsconfig.json" }, - url = "https://raw.githubusercontent.com/rescript-lang/rescript-compiler/8.2.0/docs/docson/build-schema.json", - }, - { - description = "Prettier config", - fileMatch = { - ".prettierrc", - ".prettierrc.json", - "prettier.config.json", - }, - url = "https://json.schemastore.org/prettierrc", - }, - { - description = "Vercel Now config", - fileMatch = { "now.json" }, - url = "https://json.schemastore.org/now", - }, - { - description = "Stylelint config", - fileMatch = { - ".stylelintrc", - ".stylelintrc.json", - "stylelint.config.json", - }, - url = "https://json.schemastore.org/stylelintrc", - }, - { - description = "A JSON schema for the ASP.NET LaunchSettings.json files", - fileMatch = { "launchsettings.json" }, - url = "https://json.schemastore.org/launchsettings.json", - }, - { - description = "Schema for CMake Presets", - fileMatch = { - "CMakePresets.json", - "CMakeUserPresets.json", - }, - url = "https://raw.githubusercontent.com/Kitware/CMake/master/Help/manual/presets/schema.json", - }, - { - description = "Configuration file as an alternative for configuring your repository in the settings page.", - fileMatch = { - ".codeclimate.json", - }, - url = "https://json.schemastore.org/codeclimate.json", - }, - { - description = "LLVM compilation database", - fileMatch = { - "compile_commands.json", - }, - url = "https://json.schemastore.org/compile-commands.json", - }, - { - description = "Config file for Command Task Runner", - fileMatch = { - "commands.json", - }, - url = "https://json.schemastore.org/commands.json", - }, - { - description = "AWS CloudFormation provides a common language for you to describe and provision all the infrastructure resources in your cloud environment.", - fileMatch = { - "*.cf.json", - "cloudformation.json", - }, - url = "https://raw.githubusercontent.com/awslabs/goformation/v5.2.9/schema/cloudformation.schema.json", - }, - { - description = "The AWS Serverless Application Model (AWS SAM, previously known as Project Flourish) extends AWS CloudFormation to provide a simplified way of defining the Amazon API Gateway APIs, AWS Lambda functions, and Amazon DynamoDB tables needed by your serverless application.", - fileMatch = { - "serverless.template", - "*.sam.json", - "sam.json", - }, - url = "https://raw.githubusercontent.com/awslabs/goformation/v5.2.9/schema/sam.schema.json", - }, - { - description = "Json schema for properties json file for a GitHub Workflow template", - fileMatch = { - ".github/workflow-templates/**.properties.json", - }, - url = "https://json.schemastore.org/github-workflow-template-properties.json", - }, - { - description = "golangci-lint configuration file", - fileMatch = { - ".golangci.toml", - ".golangci.json", - }, - url = "https://json.schemastore.org/golangci-lint.json", - }, - { - description = "JSON schema for the JSON Feed format", - fileMatch = { - "feed.json", - }, - url = "https://json.schemastore.org/feed.json", - versions = { - ["1"] = "https://json.schemastore.org/feed-1.json", - ["1.1"] = "https://json.schemastore.org/feed.json", - }, - }, - { - description = "Packer template JSON configuration", - fileMatch = { - "packer.json", - }, - url = "https://json.schemastore.org/packer.json", - }, - { - description = "NPM configuration file", - fileMatch = { - "package.json", - }, - url = "https://json.schemastore.org/package.json", - }, - { - description = "Resume json", - fileMatch = { "resume.json" }, - url = "https://raw.githubusercontent.com/jsonresume/resume-schema/v1.0.0/schema.json", - }, -} - -local opts = { - settings = { - json = { - schemas = schemas, - }, - }, - setup = { - commands = { - Format = { - function() - vim.lsp.buf.range_formatting({}, { 0, 0 }, { vim.fn.line("$"), 0 }) - end, - }, - }, - }, -} - -return opts diff --git a/lua/plugins/lsp/settings/pyright.lua b/lua/plugins/lsp/settings/pyright.lua deleted file mode 100644 index d07ae8c..0000000 --- a/lua/plugins/lsp/settings/pyright.lua +++ /dev/null @@ -1,12 +0,0 @@ --- Config for pyright language server. - -return { - settings = { - - python = { - analysis = { - typeCheckingMode = "off", - }, - }, - }, -} diff --git a/lua/plugins/lsp/settings/sumneko_lua.lua b/lua/plugins/lsp/settings/sumneko_lua.lua deleted file mode 100644 index d7957c1..0000000 --- a/lua/plugins/lsp/settings/sumneko_lua.lua +++ /dev/null @@ -1,18 +0,0 @@ --- Config for a Lua language server. - -return { - settings = { - - Lua = { - diagnostics = { - globals = { "vim" }, - }, - workspace = { - library = { - [vim.fn.expand("$VIMRUNTIME/lua")] = true, - [vim.fn.stdpath("config") .. "/lua"] = true, - }, - }, - }, - }, -} diff --git a/lua/plugins/plugins.lua b/lua/plugins/plugins.lua deleted file mode 100644 index 2998fb9..0000000 --- a/lua/plugins/plugins.lua +++ /dev/null @@ -1,36 +0,0 @@ --- Neovim plugins - -return { - -- Base -- - { "wbthomason/packer.nvim" }, -- Have packer manage itself - { "nvim-lua/popup.nvim" }, -- An implementation of the Popup API from vim in Neovim - { "nvim-lua/plenary.nvim" }, -- Useful lua functions used ny lots of plugins - - -- Colorschemes -- - { "aktersnurra/no-clown-fiesta.nvim" }, -- My colorscheme - - -- cmp plugins -- - { "hrsh7th/nvim-cmp" }, -- The completion plugin - { "hrsh7th/cmp-buffer" }, -- buffer completions - { "hrsh7th/cmp-path" }, -- path completions - { "hrsh7th/cmp-cmdline" }, -- cmdline completions - { "saadparwaiz1/cmp_luasnip" }, -- snippet completions - - -- Snippets -- - { "L3MON4D3/LuaSnip" }, --snippet engine - { "rafamadriz/friendly-snippets" }, -- a bunch of snippets to use - - -- LSP -- - { "neovim/nvim-lspconfig" }, -- enable LSP - { "williamboman/nvim-lsp-installer" }, -- simple to use language server installer - - -- Telescope -- - { "nvim-telescope/telescope.nvim" }, - - -- Treesitter -- - { - "nvim-treesitter/nvim-treesitter", - run = ":TSUpdate", - }, - -} -- cgit v1.2.3-70-g09d2