diff options
Diffstat (limited to 'nvim')
-rwxr-xr-x | nvim/init.vim | 51 | ||||
-rw-r--r-- | nvim/lua/init.lua | 1 | ||||
-rw-r--r-- | nvim/lua/user/cmp.lua | 129 | ||||
-rw-r--r-- | nvim/lua/user/lsp/handlers.lua | 104 | ||||
-rw-r--r-- | nvim/lua/user/lsp/init.lua | 7 | ||||
-rw-r--r-- | nvim/lua/user/lsp/mason.lua | 47 | ||||
-rw-r--r-- | nvim/lua/user/lsp/null-ls.lua | 19 |
7 files changed, 343 insertions, 15 deletions
diff --git a/nvim/init.vim b/nvim/init.vim index 26fe0ad..699fcb4 100755 --- a/nvim/init.vim +++ b/nvim/init.vim @@ -12,23 +12,37 @@ Plug 'ap/vim-css-color' Plug 'junegunn/goyo.vim' Plug 'vimwiki/vimwiki' Plug 'tpope/vim-commentary' +Plug 'hrsh7th/nvim-cmp' " The completion plugin +Plug 'hrsh7th/cmp-buffer' " buffer completions +Plug 'hrsh7th/cmp-path' " path completions +Plug 'hrsh7th/cmp-cmdline' " cmdline completions +Plug 'hrsh7th/cmp-nvim-lsp' +Plug 'saadparwaiz1/cmp_luasnip' " snippet completions +Plug 'L3MON4D3/LuaSnip' " snippet engine +Plug 'rafamadriz/friendly-snippets' " a bunch of snippets to use +Plug 'neovim/nvim-lspconfig' " enable LSP +Plug 'williamboman/mason.nvim' " simple to use language server installer +Plug 'williamboman/mason-lspconfig.nvim' " simple to use language server installer call plug#end() +" lua require('user.cmp') +" lua require('user.lsp') + "" Basic options -set autochdir " Always change directory to current file -set autoindent " Keeps indentation on new lines -set hlsearch " Highlight search hits -set ignorecase " Case-insensitive search... -set linebreak " Word wrap -set list " Show whitespace characters defined in listchars -set listchars=tab:▏\ \,space:· " Highlight tabs and spaces -set mouse=a " Because sometimes it's just easier to use the mouse -set number relativenumber " Enable relative line numbers -set smartcase " ...Unless the search term is capital -set splitbelow splitright " Open splits on bottom/right instead of top/left -set termguicolors " Enable GUI colors for the terminal to get truecolor -set wildmode=longest,list,full " Enable file auto-complete -syntax on " Enable syntax highlighting +set autochdir " Always change directory to current file +set autoindent " Keeps indentation on new lines +set hlsearch " Highlight search hits +set ignorecase " Case-insensitive search... +set linebreak " Word wrap +set list " Show whitespace characters defined in listchars +set listchars=tab:▏\ \,space:· " Highlight tabs and spaces +set mouse=a " Because sometimes it's just easier to use the mouse +set number relativenumber " Enable relative line numbers +set smartcase " ...Unless the search term is capital +set splitbelow splitright " Open splits on bottom/right instead of top/left +set termguicolors " Enable GUI colors for the terminal to get truecolor +set wildmode=longest,list,full " Enable file auto-complete +syntax on " Enable syntax highlighting " Get rid of the pointless .viminfo files that clutter the home directory let skip_defaults_vim=1 @@ -37,6 +51,13 @@ set viminfo="" " Disables automatic commenting on newline: autocmd FileType * setlocal formatoptions-=c formatoptions-=r formatoptions-=o +" Tabbing +let tabwidth = 4 +set tabstop=4 " Set width of tabs to 4 instead of default 8 +set shiftwidth=4 " Tab key will only insert 1 tab +" Use tabs instead of spaces +autocmd FileType sass setlocal noet ci pi sts=0 sw=4 ts=4 + "" Plugin options " Closetag let g:closetag_filenames = '*.html,*.xhtml,*.phtml' @@ -160,4 +181,4 @@ augroup END "" Auto compile " Sass -autocmd BufWritePost [^_]*.sass,[^_]*.scss silent !sass %:p %:p:r.css +"autocmd BufWritePost [^_]*.sass,[^_]*.scss silent !sass %:p %:p:r.css diff --git a/nvim/lua/init.lua b/nvim/lua/init.lua new file mode 100644 index 0000000..7a62678 --- /dev/null +++ b/nvim/lua/init.lua @@ -0,0 +1 @@ +require "user.cmp" diff --git a/nvim/lua/user/cmp.lua b/nvim/lua/user/cmp.lua new file mode 100644 index 0000000..c83ddce --- /dev/null +++ b/nvim/lua/user/cmp.lua @@ -0,0 +1,129 @@ +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 + +-- פּ ﯟ some other good icons +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 = "", +} +-- find more here: https://www.nerdfonts.com/cheat-sheet + +cmp.setup { + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) -- For `luasnip` users. + end, + }, + mapping = { + ["<C-k>"] = cmp.mapping.select_prev_item(), + ["<C-j>"] = cmp.mapping.select_next_item(), + ["<C-b>"] = cmp.mapping(cmp.mapping.scroll_docs(-1), { "i", "c" }), + ["<C-f>"] = cmp.mapping(cmp.mapping.scroll_docs(1), { "i", "c" }), + ["<C-Space>"] = cmp.mapping(cmp.mapping.complete(), { "i", "c" }), + ["<C-y>"] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `<C-y>` mapping. + ["<C-e>"] = 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. + ["<CR>"] = cmp.mapping.confirm { select = true }, + ["<Tab>"] = 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", + }), + ["<S-Tab>"] = 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 = ({ + luasnip = "[Snippet]", + buffer = "[Buffer]", + path = "[Path]", + })[entry.source.name] + return vim_item + end, + }, + sources = { + { name = "nvim_lsp" }, + { name = "nvim_lua" }, + { name = "luasnip" }, + { name = "buffer" }, + { name = "path" }, + }, + confirm_opts = { + behavior = cmp.ConfirmBehavior.Replace, + select = false, + }, + window = { + documentation = cmp.config.window.bordered(), + }, + experimental = { + ghost_text = false, + native_menu = false, + }, +} diff --git a/nvim/lua/user/lsp/handlers.lua b/nvim/lua/user/lsp/handlers.lua new file mode 100644 index 0000000..8de0abd --- /dev/null +++ b/nvim/lua/user/lsp/handlers.lua @@ -0,0 +1,104 @@ +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.server_capabilities.documentHighlight then + vim.api.nvim_exec( + [[ + augroup lsp_document_highlight + autocmd! * <buffer> + autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight() + autocmd CursorMoved <buffer> 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", "<cmd>lua vim.lsp.buf.declaration()<CR>", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "gd", "<cmd>lua vim.lsp.buf.definition()<CR>", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "K", "<cmd>lua vim.lsp.buf.hover()<CR>", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "gi", "<cmd>lua vim.lsp.buf.implementation()<CR>", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "<C-k>", "<cmd>lua vim.lsp.buf.signature_help()<CR>", opts) + -- vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>rn", "<cmd>lua vim.lsp.buf.rename()<CR>", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "gr", "<cmd>lua vim.lsp.buf.references()<CR>", opts) + -- vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>ca", "<cmd>lua vim.lsp.buf.code_action()<CR>", opts) + -- vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>f", "<cmd>lua vim.diagnostic.open_float()<CR>", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "[d", '<cmd>lua vim.diagnostic.goto_prev({ border = "rounded" })<CR>', opts) + vim.api.nvim_buf_set_keymap( + bufnr, + "n", + "gl", + '<cmd>lua vim.diagnostic.open_float()<CR>', + opts + ) + vim.api.nvim_buf_set_keymap(bufnr, "n", "]d", '<cmd>lua vim.diagnostic.goto_next({ border = "rounded" })<CR>', opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>q", "<cmd>lua vim.diagnostic.setloclist()<CR>", opts) + vim.cmd [[ command! Format execute 'lua vim.lsp.buf.formatting()' ]] +end + +M.on_attach = function(client, bufnr) + if client.name == "tsserver" then + client.server_capabilities.documentFormattingProvider = 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.default_capabilities(capabilities) + +return M diff --git a/nvim/lua/user/lsp/init.lua b/nvim/lua/user/lsp/init.lua new file mode 100644 index 0000000..8a84467 --- /dev/null +++ b/nvim/lua/user/lsp/init.lua @@ -0,0 +1,7 @@ +local status_ok, _ = pcall(require, "lspconfig") +if not status_ok then + return +end + +require "user.lsp.mason" +require("user.lsp.handlers").setup() diff --git a/nvim/lua/user/lsp/mason.lua b/nvim/lua/user/lsp/mason.lua new file mode 100644 index 0000000..a2e5384 --- /dev/null +++ b/nvim/lua/user/lsp/mason.lua @@ -0,0 +1,47 @@ +local servers = { + "lua_ls", + "pyright", + "jsonls", +} + +local settings = { + ui = { + border = "none", + icons = { + package_installed = "◍", + package_pending = "◍", + package_uninstalled = "◍", + }, + }, + log_level = vim.log.levels.INFO, + max_concurrent_installers = 4, +} + +require("mason").setup(settings) +require("mason-lspconfig").setup({ + ensure_installed = servers, + automatic_installation = true, +}) + +local lspconfig_status_ok, lspconfig = pcall(require, "lspconfig") +if not lspconfig_status_ok then + return +end + +local opts = {} + +for _, server in pairs(servers) do + opts = { + on_attach = require("user.lsp.handlers").on_attach, + capabilities = require("user.lsp.handlers").capabilities, + } + + server = vim.split(server, "@")[1] + + local require_ok, conf_opts = pcall(require, "user.lsp.settings." .. server) + if require_ok then + opts = vim.tbl_deep_extend("force", conf_opts, opts) + end + + lspconfig[server].setup(opts) +end diff --git a/nvim/lua/user/lsp/null-ls.lua b/nvim/lua/user/lsp/null-ls.lua new file mode 100644 index 0000000..874e19c --- /dev/null +++ b/nvim/lua/user/lsp/null-ls.lua @@ -0,0 +1,19 @@ +local null_ls_status_ok, null_ls = pcall(require, "null-ls") +if not null_ls_status_ok then + return +end + +-- https://github.com/jose-elias-alvarez/null-ls.nvim/tree/main/lua/null-ls/builtins/formatting +local formatting = null_ls.builtins.formatting +-- https://github.com/jose-elias-alvarez/null-ls.nvim/tree/main/lua/null-ls/builtins/diagnostics +local diagnostics = null_ls.builtins.diagnostics + +null_ls.setup({ + debug = false, + sources = { + formatting.prettier.with({ extra_args = { "--no-semi", "--single-quote", "--jsx-single-quote" } }), + formatting.black.with({ extra_args = { "--fast" } }), + formatting.stylua, + -- diagnostics.flake8 + }, +}) |