From 7cc46f0771352a1ac486df9bdeb5826712d11d33 Mon Sep 17 00:00:00 2001 From: LMBishop <13875753+LMBishop@users.noreply.github.com> Date: Sat, 15 Jul 2023 17:03:48 +0100 Subject: Add new colour scheme --- vim/nvim/lua/config/autocomplete.lua | 85 ++++++++++++++++++++++++++++++++++++ vim/nvim/lua/config/diagnostic.lua | 29 ++++++++++++ vim/nvim/lua/config/init.lua | 4 ++ vim/nvim/lua/config/lsp.lua | 37 ++++++++++++++++ vim/nvim/lua/config/treesitter.lua | 6 +++ 5 files changed, 161 insertions(+) create mode 100644 vim/nvim/lua/config/autocomplete.lua create mode 100644 vim/nvim/lua/config/diagnostic.lua create mode 100644 vim/nvim/lua/config/init.lua create mode 100644 vim/nvim/lua/config/lsp.lua create mode 100644 vim/nvim/lua/config/treesitter.lua (limited to 'vim/nvim/lua/config') diff --git a/vim/nvim/lua/config/autocomplete.lua b/vim/nvim/lua/config/autocomplete.lua new file mode 100644 index 0000000..b981bdb --- /dev/null +++ b/vim/nvim/lua/config/autocomplete.lua @@ -0,0 +1,85 @@ +local luasnip = require 'luasnip' +local lspkind = require('lspkind') +local cmp = require 'cmp' +cmp.setup { + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) + end, + }, + mapping = cmp.mapping.preset.insert({ + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.confirm { + behavior = cmp.ConfirmBehavior.Replace, + select = false, + }, + [''] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + 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' }), + }), + sources = { + { name = 'nvim_lsp' }, + { name = 'luasnip' }, + }, + formatting = { + format = lspkind.cmp_format({ + mode = 'symbol_text', + maxwidth = 50, + ellipsis_char = '...', + }) + }, + window = { + documentation = cmp.config.window.bordered(), + completion = cmp.config.window.bordered(), + }, +} + +local api = require('cmp.utils.api') +local types = require('cmp.types') +local highlight = require('cmp.utils.highlight') +local autocmd = require('cmp.utils.autocmd') + +vim.api.nvim_set_hl(0, 'CmpItemAbbr', { link = 'CmpItemAbbrDefault', default = true }) +vim.api.nvim_set_hl(0, 'CmpItemAbbrDeprecated', { link = 'CmpItemAbbrDeprecatedDefault', default = true }) +vim.api.nvim_set_hl(0, 'CmpItemAbbrMatch', { link = 'CmpItemAbbrMatchDefault', default = true }) +vim.api.nvim_set_hl(0, 'CmpItemAbbrMatchFuzzy', { link = 'CmpItemAbbrMatchFuzzyDefault', default = true }) +vim.api.nvim_set_hl(0, 'CmpItemKind', { link = 'CmpItemKindDefault', default = true }) +vim.api.nvim_set_hl(0, 'CmpItemMenu', { link = 'CmpItemMenuDefault', default = true }) +for kind in pairs(types.lsp.CompletionItemKind) do + if type(kind) == 'string' then + local name = ('CmpItemKind%s'):format(kind) + vim.api.nvim_set_hl(0, name, { link = ('%sDefault'):format(name), default = true }) + end +end + +autocmd.subscribe('ColorScheme', function() + highlight.inherit('CmpItemAbbrDefault', 'Pmenu', { bg = 'NONE', default = false }) + highlight.inherit('CmpItemAbbrDeprecatedDefault', 'Comment', { bg = 'NONE', default = false }) + highlight.inherit('CmpItemAbbrMatchDefault', 'Pmenu', { bg = 'NONE', default = false }) + highlight.inherit('CmpItemAbbrMatchFuzzyDefault', 'Pmenu', { bg = 'NONE', default = false }) + highlight.inherit('CmpItemKindDefault', 'Special', { bg = 'NONE', default = false }) + highlight.inherit('CmpItemMenuDefault', 'Pmenu', { bg = 'NONE', default = false }) + for name in pairs(types.lsp.CompletionItemKind) do + if type(name) == 'string' then + vim.api.nvim_set_hl(0, ('CmpItemKind%sDefault'):format(name), { link = 'CmpItemKind', default = false }) + end + end +end) +autocmd.emit('ColorScheme') diff --git a/vim/nvim/lua/config/diagnostic.lua b/vim/nvim/lua/config/diagnostic.lua new file mode 100644 index 0000000..afa9c87 --- /dev/null +++ b/vim/nvim/lua/config/diagnostic.lua @@ -0,0 +1,29 @@ +vim.diagnostic.config({ + underline = true, + signs = true, + virtual_text = false, + float = { + show_header = true, + source = 'if_many', + focusable = false, + transparent = true, + }, + update_in_insert = true, -- default to false + severity_sort = false, -- default to false +}) + +vim.api.nvim_exec([[ autocmd InsertEnter * :lua vim.diagnostic.config({virtual_text = true}) ]], false) +vim.api.nvim_exec([[ autocmd InsertLeave * :lua vim.diagnostic.config({virtual_text = false}) ]], false) +vim.api.nvim_exec([[ autocmd CursorMoved * :lua vim.diagnostic.open_float({ silent=true }) ]], false) + +vim.lsp.handlers['textDocument/publishDiagnostics'] = vim.lsp.with( + vim.lsp.diagnostic.on_publish_diagnostics, { + update_in_insert = true, + } +) + +local signs = { Error = " ", Warn = " ", Hint = " ", Info = " " } +for type, icon in pairs(signs) do + local hl = "DiagnosticSign" .. type + vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = "" }) +end diff --git a/vim/nvim/lua/config/init.lua b/vim/nvim/lua/config/init.lua new file mode 100644 index 0000000..94d770c --- /dev/null +++ b/vim/nvim/lua/config/init.lua @@ -0,0 +1,4 @@ +require('config.autocomplete') +require('config.diagnostic') +require('config.lsp') +require('config.treesitter') diff --git a/vim/nvim/lua/config/lsp.lua b/vim/nvim/lua/config/lsp.lua new file mode 100644 index 0000000..08213fe --- /dev/null +++ b/vim/nvim/lua/config/lsp.lua @@ -0,0 +1,37 @@ +local capabilities = require("cmp_nvim_lsp").default_capabilities() + +local lsp_flags = { + debounce_text_changes = 150, +} +require('lspconfig')['hls'].setup{ + on_attach = on_attach, + flags = lsp_flags, + capabilities = capabilities, +} +require('lspconfig')['tsserver'].setup{ + on_attach = on_attach, + flags = lsp_flags, + capabilities = capabilities, +} +require('lspconfig')['quick_lint_js'].setup{ + on_attach = on_attach, + flags = lsp_flags, + capabilities = capabilities, +} +require('clangd_extensions').setup() +require('lspconfig')['pylsp'].setup{ + on_attach = on_attach, + flags = lsp_flags, + capabilities = capabilities, +} + +require('lspconfig')['yamlls'].setup{ + on_attach = on_attach, + flags = lsp_flags, + capabilities = capabilities, +} +require('lspconfig')['bashls'].setup{ + on_attach = on_attach, + flags = lsp_flags, + capabilities = capabilities, +} diff --git a/vim/nvim/lua/config/treesitter.lua b/vim/nvim/lua/config/treesitter.lua new file mode 100644 index 0000000..4e90be1 --- /dev/null +++ b/vim/nvim/lua/config/treesitter.lua @@ -0,0 +1,6 @@ +require'nvim-treesitter.configs'.setup { + highlight = { + enable = true, + additional_vim_regex_highlighting = { "haskell" }, + }, +} -- cgit v1.2.3-70-g09d2