From 36093bc8416107ecb93d67073f531e69bd7acca2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Dudr?= Date: Fri, 23 Sep 2022 20:22:22 +0200 Subject: [PATCH] nvim: refactor --- dot_config/nvim/init.lua | 509 +-------------------- dot_config/nvim/lua/configs/lsp.lua | 74 +++ dot_config/nvim/lua/configs/lualine.lua | 33 ++ dot_config/nvim/lua/configs/neotree.lua | 222 +++++++++ dot_config/nvim/lua/configs/null-ls.lua | 58 +++ dot_config/nvim/lua/configs/nvim-cmp.lua | 36 ++ dot_config/nvim/lua/configs/nvimtree.lua | 33 ++ dot_config/nvim/lua/configs/options.lua | 44 ++ dot_config/nvim/lua/configs/packages.lua | 131 ++++++ dot_config/nvim/lua/configs/telescope.lua | 51 +++ dot_config/nvim/lua/configs/treesitter.lua | 43 ++ 11 files changed, 728 insertions(+), 506 deletions(-) create mode 100644 dot_config/nvim/lua/configs/lsp.lua create mode 100644 dot_config/nvim/lua/configs/lualine.lua create mode 100644 dot_config/nvim/lua/configs/neotree.lua create mode 100644 dot_config/nvim/lua/configs/null-ls.lua create mode 100644 dot_config/nvim/lua/configs/nvim-cmp.lua create mode 100644 dot_config/nvim/lua/configs/nvimtree.lua create mode 100644 dot_config/nvim/lua/configs/options.lua create mode 100644 dot_config/nvim/lua/configs/packages.lua create mode 100644 dot_config/nvim/lua/configs/telescope.lua create mode 100644 dot_config/nvim/lua/configs/treesitter.lua diff --git a/dot_config/nvim/init.lua b/dot_config/nvim/init.lua index e1d3106..7271352 100644 --- a/dot_config/nvim/init.lua +++ b/dot_config/nvim/init.lua @@ -1,259 +1,5 @@ ---- PACKAGES {{{ -local fn = vim.fn -local install_path = fn.stdpath('data') .. '/site/pack/packer/start/packer.nvim' -if fn.empty(fn.glob(install_path)) > 0 then - local 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 'neovim/nvim-lspconfig' - use { 'hrsh7th/nvim-cmp', requires = { 'neovim/nvim-lspconfig' } } - use { 'hrsh7th/cmp-nvim-lsp', requires = { 'hrsh7th/nvim-cmp' } } - use { 'hrsh7th/cmp-buffer', requires = { 'hrsh7th/nvim-cmp' } } - use { 'hrsh7th/cmp-path', requires = { 'hrsh7th/nvim-cmp' } } - use { 'hrsh7th/cmp-nvim-lua', requires = { 'hrsh7th/nvim-cmp' } } - use 'hrsh7th/vim-vsnip' - use 'hrsh7th/cmp-nvim-lsp-signature-help' - - use { 'hrsh7th/cmp-vsnip', requires = { 'hrsh7th/nvim-cmp', 'hrsh7th/vim-vsnip' } } - use { 'onsails/lspkind.nvim' } - use 'ray-x/lsp_signature.nvim' - use { 'RishabhRD/nvim-lsputils', requires = { 'RishabhRD/popfix' } } - -- use { 'weilbith/nvim-code-action-menu', cmd = 'CodeActionMenu' } - -- use { 'simrat39/symbols-outline.nvim', cmd = 'SymbolsOutline' } - - use { 'stevearc/dressing.nvim' } - - use { 'jose-elias-alvarez/null-ls.nvim', requires = { "nvim-lua/plenary.nvim" } } - - use { 'nvim-treesitter/nvim-treesitter', run = ':TSUpdate' } - use 'nvim-treesitter/playground' - use 'David-Kunz/treesitter-unit' - use({ "yioneko/nvim-yati", requires = "nvim-treesitter/nvim-treesitter" }) - - use { 'nvim-telescope/telescope.nvim', requires = { 'nvim-lua/popup.nvim', 'nvim-lua/plenary.nvim' } } - use { 'nvim-telescope/telescope-fzf-native.nvim', - run = 'cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=Release && cmake --build build --config Release && cmake --install build --prefix build' - } - - -- use {"ellisonleao/gruvbox.nvim"} - use { 'morhetz/gruvbox' } - -- use 'lifepillar/vim-solarized8' - - use { 'chrisbra/Colorizer', cmd = 'ColorToggle', keys = { 'n', 'c ColorToggle' } } - - -- #aaaaaa - - use { 'kdheepak/lazygit.nvim', keys = { 'n', 'g LazyGit' }, cmd = 'LazyGit' } - use { 'lewis6991/gitsigns.nvim', requires = { 'nvim-lua/plenary.nvim' } } - - use { 'hoob3rt/lualine.nvim', requires = { 'kyazdani42/nvim-web-devicons', opt = true } } - - use { 'AndrewRadev/linediff.vim', cmd = 'LineDiffAdd' } - - use 'lukas-reineke/indent-blankline.nvim' - - use 'b3nj5m1n/kommentary' - use 'airblade/vim-rooter' - - use { 'vlada-dudr/vim-php-cs-fixer', ft = 'php' } - - use 'editorconfig/editorconfig-vim' - - use { 'kyazdani42/nvim-tree.lua' } - - use { 'vim-vdebug/vdebug' } - - use { 'dyng/ctrlsf.vim', cmd = 'CtrlSF' } - - use { 'folke/lua-dev.nvim' } - - use { 'AndrewRadev/tagalong.vim' } - use { 'andymass/vim-matchup' } - - use { 'fpob/nette.vim', ft = 'nette' } - - use { - 'folke/trouble.nvim', - requires = "kyazdani42/nvim-web-devicons", - cmd = 'TroubleToggle', - keys = { 'n', 't TroubleToggle' }, - config = function() require('trouble').setup() end - } - - use { 'ziglang/zig.vim', ft = 'zig' } - - if packer_bootstrap then - require('packer').sync() - end -end) - ---- PACKAGES }}} - ---- OPTIONS {{{ -vim.o.ruler = true -vim.o.mouse = '' -vim.o.showcmd = true -vim.o.scrolloff = 3 -vim.o.ignorecase = true -vim.o.smartcase = true -vim.o.incsearch = true -vim.o.inccommand = 'split' -vim.o.hidden = true -vim.o.autoread = true -vim.o.completeopt = 'menuone,noinsert,noselect' -vim.o.tabstop = 4 -vim.o.softtabstop = 4 -vim.o.swapfile = true -vim.o.undofile = true -vim.o.expandtab = true -vim.o.shiftwidth = 4 -vim.o.number = true ---vim.o.colorcolumn=0 ---vim.o.foldmethod='marker' -vim.o.foldcolumn = 'auto:1' -vim.o.signcolumn = 'yes' -vim.o.list = false -vim.o.relativenumber = false -vim.o.foldenable = true -vim.o.cursorline = true -vim.o.autoindent = true -vim.o.smartindent = true -vim.o.fileencodings = 'ucs-bom,utf-8,default,cp852,latin1' -vim.o.path = '**' ---vim.o.clipboard = "unnamedplus" - --- Buffer -vim.cmd([[ - augroup forceRecheck - au FocusGained,BufEnter * :silent! ! - augroup END -]]) - --- vim.env.EDITOR = 'nvr' - ---- OPTIONS }}} - ---- LSP {{{ ---[[ vim.api.nvim_create_autocmd('LspAttach', { - callback = function(args) - local client = vim.lsp.get_client_by_id(args.data.client_id) - if client.server_capabilities.hoverProvider then - vim.keymap.set('n', 'K', vim.lsp.buf.hover, { buffer = args.buf }) - end - end, -}) - ]] -local nvim_lsp = require('lspconfig') -local on_attach = function(client, bufnr) - local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end - - local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end - - require "lsp_signature".on_attach() - -- require'completion'.on_attach() - - -- Mappings. - local opts = { noremap = true, silent = true } - buf_set_keymap('n', 'gD', 'lua vim.lsp.buf.declaration()', opts) - buf_set_keymap('n', 'gd', 'lua vim.lsp.buf.definition()', opts) - buf_set_keymap('n', 'K', 'lua vim.lsp.buf.hover()', opts) - buf_set_keymap('n', 'gi', 'lua vim.lsp.buf.implementation()', opts) - buf_set_keymap('n', '', 'lua vim.lsp.buf.signature_help()', opts) - buf_set_keymap('i', '', 'lua vim.lsp.buf.signature_help()', opts) - buf_set_keymap('n', 'wa', 'lua vim.lsp.buf.add_workspace_folder()', opts) - buf_set_keymap('n', 'wr', 'lua vim.lsp.buf.remove_workspace_folder()', opts) - buf_set_keymap('n', 'wl', 'lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))', opts) - buf_set_keymap('n', 'D', 'lua vim.lsp.buf.type_definition()', opts) - buf_set_keymap('n', 'rn', 'lua vim.lsp.buf.rename()', opts) - buf_set_keymap('n', 'ca', 'lua vim.lsp.buf.code_action()', opts) - buf_set_keymap('v', 'ca', 'lua vim.lsp.buf.range_code_action()', opts) - buf_set_keymap('n', 'gr', 'lua vim.lsp.buf.references()', opts) - buf_set_keymap('n', '[d', 'lua vim.diagnostic.goto_prev()', opts) - buf_set_keymap('n', ']d', 'lua vim.diagnostic.goto_next()', opts) - buf_set_keymap('n', 'q', 'lua vim.diagnostic.setloclist()', opts) - buf_set_keymap('n', 'F', 'lua vim.lsp.buf.formatting()', opts) - buf_set_keymap('v', 'F', 'lua vim.lsp.buf.range_formatting()', opts) -end - --- Use a loop to conveniently both setup defined servers --- and map buffer local keybindings when the language server attaches -local servers = { 'phpactor', 'gopls', 'clangd', 'zls', 'hls', 'tsserver', 'sumneko_lua', 'perlls' } -for _, lsp in ipairs(servers) do - nvim_lsp[lsp].setup { - on_attach = on_attach, - capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities()), - } -end - -require 'lspconfig'.phpactor.setup { - on_attach = on_attach, - capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities()), - - root_dir = function(startpath) - local u = require('lspconfig.util') - return u.search_ancestors(startpath, function(path) - return not string.find(path, '/vendor/') and ( - u.path.exists(u.path.join(path, 'composer.json')) - or u.path.exists(u.path.join(path, '.git')) - ) - end) - end -} - -require 'lspconfig'.omnisharp.setup { - cmd = { '/usr/bin/omnisharp', '--languageserver', '--hostPID', tostring(pid) }, - on_attach = on_attach, - capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities()) -} - -require 'lspconfig'.powershell_es.setup { - bundle_path = '/home/vladimir/devel/PowerShellEditorServices/module', - capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities()) -} - ---vim.lsp.set_log_level("debug") - ---- LSP }}} - ---- CMP {{{ -local cmp = require 'cmp' - -cmp.setup({ - -- documentation = true, - sources = { - { name = 'nvim_lsp' }, - { name = 'nvim_lua' }, - { name = 'buffer' }, - { name = 'path' }, - -- { name = 'nvim_lsp_signature_help' }, - }, - formatting = { - format = require 'lspkind'.cmp_format({ - -- mode = 'symbol', - }), - }, - window = { - -- completion = cmp.config.window.bordered(), - -- documentation = cmp.config.window.bordered(), - }, - mapping = cmp.mapping.preset.insert({ - [''] = cmp.mapping.confirm({ select = false }) - }), - snippet = { - expand = function(args) - -- For `vsnip` user. - vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` user. - end - } -}) - ---- CMP }}} +require("configs.packages").setup() +require("configs.options").setup() -- vsnip {{{ vim.cmd 'imap vsnip#jumpable(1) ? \'(vsnip-jump-next)\' : \'\'' @@ -262,123 +8,6 @@ vim.cmd 'imap vsnip#jumpable(-1) ? \'(vsnip-jump-prev)\' vim.cmd 'smap vsnip#jumpable(-1) ? \'(vsnip-jump-prev)\' : \'\'' -- vsnip }}} ---- gitsigns {{{ -require 'gitsigns'.setup {} ---- gitsigns }}} - --- lualine {{{ -require 'lualine'.setup { - options = { - icons_enabled = true, - theme = vim.env.TERM ~= 'linux' and 'gruvbox' or nil, - component_separators = { '', '' }, - section_separators = { '', '' }, - disabled_filetypes = {} - }, - sections = { - lualine_a = { 'mode' }, - lualine_b = { 'branch' }, - lualine_c = { { 'filename', path = 1 } }, - lualine_x = { 'encoding', 'fileformat', 'filetype' }, - lualine_y = { 'progress' }, - lualine_z = { 'location' } - }, - inactive_sections = { - lualine_a = {}, - lualine_b = {}, - lualine_c = { { 'filename' } }, - lualine_x = { 'location' }, - lualine_y = {}, - lualine_z = {} - }, - tabline = {}, - extensions = { 'nerdtree' } -} --- lualine }}} - --- NvimTree {{{ -require('nvim-tree').setup({ - sync_root_with_cwd = true, - renderer = { - add_trailing = true, - special_files = {}, - highlight_git = true, - indent_markers = { - enable = true, - }, - icons = { - show = { - file = false, - folder = false, - folder_arrow = false, - git = false - } - }, - }, - git = { - ignore = true - }, - filters = { - custom = { '_null-ls.*' }, - }, -}) - -vim.api.nvim_set_keymap('n', '', [[NvimTreeToggle]], {}) -vim.api.nvim_set_keymap('n', '', [[NvimTreeFindFile]], {}) --- }}} NvimTree - --- Telescope {{{ -vim.api.nvim_set_keymap('n', 'b', [[Telescope buffers]], { noremap = true, silent = true }) -vim.api.nvim_set_keymap('n', 'f', [[Telescope fd]], { noremap = true, silent = true }) -vim.api.nvim_set_keymap('n', 'T', [[Telescope]], { noremap = true, silent = true }) - -require("telescope").setup { - defaults = { - preview = { - hide_on_startup = true - }, - --[[ mappings = { -i = { -[""] = actions.toggle_preview, -}, -n = { -[""] = actions.toggle_preview, -}, -}, ]] - }, - pickers = { - buffers = { - show_all_buffers = true, - sort_lastused = false, - sort_mru = true, - -- theme = "dropdown", - mappings = { - i = { - [""] = "delete_buffer", - }, - n = { - [""] = "delete_buffer", - } - } - } - } -} - -require('telescope').load_extension('fzf') - ---[[ local telescope_ag = vim.api.nvim_create_augroup('Telescope') -nvim.nvim_create_autocmd('FileType', { pattern='TelescopePrompt', command = nvim.nvim_buf_set_keymap('n', '' ]] -vim.cmd 'augroup Telescope' -vim.cmd 'autocmd FileType TelescopePrompt inoremap Telescope buffers initial_mode=insert' -vim.cmd 'autocmd FileType TelescopePrompt inoremap Telescope fd initial_mode=insert' -vim.cmd 'autocmd FileType TelescopePrompt nnoremap Telescope buffers initial_mode=insert' -vim.cmd 'autocmd FileType TelescopePrompt nnoremap Telescope fd initial_mode=insert' -vim.cmd 'autocmd FileType TelescopePrompt inoremap Telescope builtin initial_mode=insert' -vim.cmd 'autocmd FileType TelescopePrompt nnoremap Telescope builtin initial_mode=insert' -vim.cmd 'augroup END' - --- Telescope }}} - -- dressing.nvim {{{ require('dressing').setup({ input = { @@ -388,80 +17,13 @@ require('dressing').setup({ -- }}} --- Tree sitter {{{ -require 'nvim-treesitter.configs'.setup { - ensure_installed = 'all', -- one of "all", "maintained" (parsers with maintainers), or a list of languages - highlight = { enable = true, }, - playground = { enable = true, }, - yati = { enable = true, }, - incremental_selection = { - enable = true, - keymaps = { - init_selection = "gnn", - node_incremental = "+", - scope_incremental = "grc", - node_decremental = "-", - }, - }, - indent = { - -- disable = { "php" },-- php indent SUCKS A LOT - enable = false, - }, -} - -local ts_parsers = require 'nvim-treesitter.parsers'.get_parser_configs() -ts_parsers.xml = { - install_info = { - url = "https://github.com/dorgnarg/tree-sitter-xml", -- local path or git repo - files = { "src/parser.c" }, - -- optional entries: - branch = "main", -- default branch in case of git repo if different from master - generate_requires_npm = false, -- if stand-alone parser without npm dependencies - requires_generate_from_grammar = true, -- if folder contains pre-generated src/parser.c - }, - filetype = "xml", -- if filetype does not match the parser name -} - -vim.api.nvim_set_keymap('x', 'iu', ':lua require"treesitter-unit".select()', { noremap = true }) -vim.api.nvim_set_keymap('x', 'au', ':lua require"treesitter-unit".select(true)', { noremap = true }) -vim.api.nvim_set_keymap('o', 'iu', ':lua require"treesitter-unit".select()', { noremap = true }) -vim.api.nvim_set_keymap('o', 'au', ':lua require"treesitter-unit".select(true)', { noremap = true }) - ---[[ vim.o.foldmethod = 'expr' -vim.o.foldexpr = 'nvim_treesitter#foldexpr()' ]] ---- Tree sitter }}} - -- Indent lines {{{ vim.g.indent_blankline_filetype_exclude = { 'help', 'NvimTree', 'TelescopePrompt', 'lspinfo' } vim.g.indent_blankline_buftype_exclude = { 'terminal', 'nofile', 'prompt' } -- indent lines }}} --- PHP CS FIXER {{{ -vim.g.php_cs_fixer_rules = [[ -{ -"@Symfony":true, -"array_syntax":{"syntax":"short"}, -"binary_operator_spaces":{"default":"align_single_space_minimal"}, -"fully_qualified_strict_types":false -} -]] - ---vim.g.php_cs_fixer_php_path = 'php7' -- Path to PHP -vim.g.php_cs_fixer_path = '/usr/bin/php-cs-fixer' -- Path to PHP -vim.g.php_cs_fixer_enable_default_mapping = 1 -- Enable the mapping by default (pcd) -vim.g.php_cs_fixer_dry_run = 0 -- Call command with dry-run option -vim.g.php_cs_fixer_verbose = 0 -vim.g.php_cs_fixer_version = 3 - --- }}} - --- kommentary {{{ -kommentary_config = require('kommentary.config') -kommentary_config.configure_language("php", { prefer_single_line_comments = true, }) --- kommentary }}} - -- NEORAY {{{ -vim.o.guifont="Noto Sans Mono:14h" +vim.o.guifont = "Noto Sans Mono:14h" vim.cmd [[ if exists('g:neoray') NeoraySet CursorAnimTime 0 @@ -477,71 +39,6 @@ vim.cmd [[ -- }}} --- rooter {{{ -vim.g.rooter_manual_only = 1 --- }}} - --- null-ls {{{ -local nls = require "null-ls" - -nls.setup({ - on_attach = on_attach, - debug = true, - sources = { - nls.builtins.formatting.xmllint, - nls.builtins.formatting.jq, - nls.builtins.diagnostics.sqlfluff, - nls.builtins.diagnostics.phpstan.with({ - cwd = function(params) - -- falls back to root if return value is nil - return params.root:match("jopixel") and not params.root:match("repo") and "www"; - end - }), - nls.builtins.formatting.phpcsfixer.with({ - extra_args = { "--rules", [[ { - "@Symfony":true, - "nullable_type_declaration_for_default_null_value":true, - "array_syntax":{"syntax":"short"}, - "binary_operator_spaces":{ - "default":"single_space", - "operators": { - "=>":"align_single_space_minimal", - "=":"align_single_space_minimal", - "??=":"align_single_space_minimal", - "^=":"align_single_space_minimal", - "|=":"align_single_space_minimal", - "+=":"align_single_space_minimal", - "%=":"align_single_space_minimal", - "&=":"align_single_space_minimal", - "**=":"align_single_space_minimal", - "*=":"align_single_space_minimal", - "-=":"align_single_space_minimal", - ".=":"align_single_space_minimal", - "/=":"align_single_space_minimal", - "<<=":"align_single_space_minimal", - "<=":"align_single_space_minimal", - ">=":"align_single_space_minimal", - ">>=":"align_single_space_minimal" - } - }, - "fully_qualified_strict_types":false - } ]] } - }), - nls.builtins.diagnostics.shellcheck, - nls.builtins.formatting.eslint, - -- nls.builtins.diagnostics.eslint, - nls.builtins.code_actions.eslint, - nls.builtins.diagnostics.yamllint, - } -}) - - --- }}} - --- Trouble {{{ --- vim.api.nvim_set_keymap('n', 't', 'TroubleToggle', {}) --- }}} TROUBLE - -- color handling {{{ local term = vim.env.TERM if (term ~= 'linux' or vim.g.neoray) diff --git a/dot_config/nvim/lua/configs/lsp.lua b/dot_config/nvim/lua/configs/lsp.lua new file mode 100644 index 0000000..ae1555d --- /dev/null +++ b/dot_config/nvim/lua/configs/lsp.lua @@ -0,0 +1,74 @@ +local M = { + on_attach = function(client, bufnr) + local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end + + require "lsp_signature".on_attach() + -- require'completion'.on_attach() + + -- Mappings. + local opts = { noremap = true, silent = true } + buf_set_keymap('n', 'gD', 'lua vim.lsp.buf.declaration()', opts) + buf_set_keymap('n', 'gd', 'lua vim.lsp.buf.definition()', opts) + buf_set_keymap('n', 'K', 'lua vim.lsp.buf.hover()', opts) + buf_set_keymap('n', 'gi', 'lua vim.lsp.buf.implementation()', opts) + buf_set_keymap('n', '', 'lua vim.lsp.buf.signature_help()', opts) + buf_set_keymap('i', '', 'lua vim.lsp.buf.signature_help()', opts) + buf_set_keymap('n', 'wa', 'lua vim.lsp.buf.add_workspace_folder()', opts) + buf_set_keymap('n', 'wr', 'lua vim.lsp.buf.remove_workspace_folder()', opts) + buf_set_keymap('n', 'wl', 'lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))', opts) + buf_set_keymap('n', 'D', 'lua vim.lsp.buf.type_definition()', opts) + buf_set_keymap('n', 'rn', 'lua vim.lsp.buf.rename()', opts) + buf_set_keymap('n', 'ca', 'lua vim.lsp.buf.code_action()', opts) + buf_set_keymap('v', 'ca', 'lua vim.lsp.buf.range_code_action()', opts) + buf_set_keymap('n', 'gr', 'lua vim.lsp.buf.references()', opts) + buf_set_keymap('n', '[d', 'lua vim.diagnostic.goto_prev()', opts) + buf_set_keymap('n', ']d', 'lua vim.diagnostic.goto_next()', opts) + buf_set_keymap('n', 'q', 'lua vim.diagnostic.setloclist()', opts) + buf_set_keymap('n', 'F', 'lua vim.lsp.buf.formatting()', opts) + buf_set_keymap('v', 'F', 'lua vim.lsp.buf.range_formatting()', opts) + end +} + +function M.setup() + require("lua-dev").setup({}) + + local nvim_lsp = require('lspconfig') + + -- Use a loop to conveniently both setup defined servers + -- and map buffer local keybindings when the language server attaches + local servers = { 'phpactor', 'gopls', 'clangd', 'zls', 'hls', 'tsserver', 'sumneko_lua', 'perlls' } + for _, lsp in ipairs(servers) do + nvim_lsp[lsp].setup { + on_attach = M.on_attach, + capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities()), + } + end + + require 'lspconfig'.phpactor.setup { + on_attach = M.on_attach, + capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities()), + + root_dir = function(startpath) + local u = require('lspconfig.util') + return u.search_ancestors(startpath, function(path) + return not string.find(path, '/vendor/') and ( + u.path.exists(u.path.join(path, 'composer.json')) + or u.path.exists(u.path.join(path, '.git')) + ) + end) + end + } + + require 'lspconfig'.omnisharp.setup { + cmd = { '/usr/bin/omnisharp', '--languageserver', '--hostPID', tostring(pid) }, + on_attach = M.on_attach, + capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities()) + } + + require 'lspconfig'.powershell_es.setup { + bundle_path = '/home/vladimir/devel/PowerShellEditorServices/module', + capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities()) + } +end + +return M diff --git a/dot_config/nvim/lua/configs/lualine.lua b/dot_config/nvim/lua/configs/lualine.lua new file mode 100644 index 0000000..a7978f1 --- /dev/null +++ b/dot_config/nvim/lua/configs/lualine.lua @@ -0,0 +1,33 @@ +local M = {} + +function M.setup() + require 'lualine'.setup { + options = { + icons_enabled = true, + theme = vim.env.TERM ~= 'linux' and 'gruvbox' or nil, + component_separators = { '', '' }, + section_separators = { '', '' }, + disabled_filetypes = {} + }, + sections = { + lualine_a = { 'mode' }, + lualine_b = { 'branch' }, + lualine_c = { { 'filename', path = 1 } }, + lualine_x = { 'encoding', 'fileformat', 'filetype' }, + lualine_y = { 'progress' }, + lualine_z = { 'location' } + }, + inactive_sections = { + lualine_a = {}, + lualine_b = {}, + lualine_c = { { 'filename' } }, + lualine_x = { 'location' }, + lualine_y = {}, + lualine_z = {} + }, + tabline = {}, + extensions = { 'nerdtree' } + } +end + +return M diff --git a/dot_config/nvim/lua/configs/neotree.lua b/dot_config/nvim/lua/configs/neotree.lua new file mode 100644 index 0000000..95ef829 --- /dev/null +++ b/dot_config/nvim/lua/configs/neotree.lua @@ -0,0 +1,222 @@ +local M = {} +function M.setup() + vim.cmd([[ let g:neo_tree_remove_legacy_commands = 1 ]]) + + -- If you want icons for diagnostic errors, you'll need to define them somewhere: + vim.fn.sign_define("DiagnosticSignError", + { text = " ", texthl = "DiagnosticSignError" }) + vim.fn.sign_define("DiagnosticSignWarn", + { text = " ", texthl = "DiagnosticSignWarn" }) + vim.fn.sign_define("DiagnosticSignInfo", + { text = " ", texthl = "DiagnosticSignInfo" }) + vim.fn.sign_define("DiagnosticSignHint", + { text = "", texthl = "DiagnosticSignHint" }) + -- NOTE: this is changed from v1.x, which used the old style of highlight groups + -- in the form "LspDiagnosticsSignWarning" + + require("neo-tree").setup({ + close_if_last_window = false, -- Close Neo-tree if it is the last window left in the tab + popup_border_style = "rounded", + enable_git_status = true, + enable_diagnostics = true, + sort_case_insensitive = false, -- used when sorting files and directories in the tree + sort_function = nil, -- use a custom function for sorting files and directories in the tree + -- sort_function = function (a,b) + -- if a.type == b.type then + -- return a.path > b.path + -- else + -- return a.type > b.type + -- end + -- end , -- this sorts files and directories descendantly + default_component_configs = { + container = { + enable_character_fade = true + }, + indent = { + indent_size = 2, + padding = 1, -- extra padding on left hand side + -- indent guides + with_markers = true, + indent_marker = "│", + last_indent_marker = "└", + highlight = "NeoTreeIndentMarker", + -- expander config, needed for nesting files + with_expanders = nil, -- if nil and file nesting is enabled, will enable expanders + expander_collapsed = "", + expander_expanded = "", + expander_highlight = "NeoTreeExpander", + }, + icon = { + folder_closed = "", + folder_open = "", + folder_empty = "ﰊ", + -- The next two settings are only a fallback, if you use nvim-web-devicons and configure default icons there + -- then these will never be used. + default = "*", + highlight = "NeoTreeFileIcon" + }, + modified = { + symbol = "[+]", + highlight = "NeoTreeModified", + }, + name = { + trailing_slash = false, + use_git_status_colors = true, + highlight = "NeoTreeFileName", + }, + git_status = { + symbols = { + -- Change type + added = "", -- or "✚", but this is redundant info if you use git_status_colors on the name + modified = "", -- or "", but this is redundant info if you use git_status_colors on the name + deleted = "✖", -- this can only be used in the git_status source + renamed = "", -- this can only be used in the git_status source + -- Status type + untracked = "", + ignored = "", + unstaged = "", + staged = "", + conflict = "", + } + }, + }, + window = { + position = "left", + width = 40, + mapping_options = { + noremap = true, + nowait = true, + }, + mappings = { + [""] = { + "toggle_node", + nowait = false, -- disable `nowait` if you have existing combos starting with this char that you want to use + }, + ["<2-LeftMouse>"] = "open", + [""] = "open", + [""] = "revert_preview", + ["P"] = { "toggle_preview", config = { use_float = true } }, + ["S"] = "open_split", + ["s"] = "open_vsplit", + -- ["S"] = "split_with_window_picker", + -- ["s"] = "vsplit_with_window_picker", + ["t"] = "open_tabnew", + -- [""] = "open_drop", + -- ["t"] = "open_tab_drop", + ["w"] = "open_with_window_picker", + --["P"] = "toggle_preview", -- enter preview mode, which shows the current node without focusing + ["C"] = "close_node", + ["z"] = "close_all_nodes", + --["Z"] = "expand_all_nodes", + ["a"] = { + "add", + -- some commands may take optional config options, see `:h neo-tree-mappings` for details + config = { + show_path = "none" -- "none", "relative", "absolute" + } + }, + ["A"] = "add_directory", -- also accepts the optional config.show_path option like "add". + ["d"] = "delete", + ["r"] = "rename", + ["y"] = "copy_to_clipboard", + ["x"] = "cut_to_clipboard", + ["p"] = "paste_from_clipboard", + ["c"] = "copy", -- takes text input for destination, also accepts the optional config.show_path option like "add": + -- ["c"] = { + -- "copy", + -- config = { + -- show_path = "none" -- "none", "relative", "absolute" + -- } + --} + ["m"] = "move", -- takes text input for destination, also accepts the optional config.show_path option like "add". + ["q"] = "close_window", + ["R"] = "refresh", + ["?"] = "show_help", + ["<"] = "prev_source", + [">"] = "next_source", + } + }, + nesting_rules = {}, + filesystem = { + filtered_items = { + visible = false, -- when true, they will just be displayed differently than normal items + hide_dotfiles = true, + hide_gitignored = true, + hide_hidden = true, -- only works on Windows for hidden files/directories + hide_by_name = { + --"node_modules" + }, + hide_by_pattern = { -- uses glob style patterns + --"*.meta", + --"*/src/*/tsconfig.json", + }, + always_show = { -- remains visible even if other settings would normally hide it + --".gitignored", + }, + never_show = { -- remains hidden even if visible is toggled to true, this overrides always_show + --".DS_Store", + --"thumbs.db" + }, + never_show_by_pattern = { -- uses glob style patterns + --".null-ls_*", + }, + }, + follow_current_file = false, -- This will find and focus the file in the active buffer every + -- time the current file is changed while the tree is open. + group_empty_dirs = false, -- when true, empty folders will be grouped together + hijack_netrw_behavior = "open_default", -- netrw disabled, opening a directory opens neo-tree + -- in whatever position is specified in window.position + -- "open_current", -- netrw disabled, opening a directory opens within the + -- window like netrw would, regardless of window.position + -- "disabled", -- netrw left alone, neo-tree does not handle opening dirs + use_libuv_file_watcher = false, -- This will use the OS level file watchers to detect changes + -- instead of relying on nvim autocmd events. + window = { + mappings = { + [""] = "navigate_up", + ["."] = "set_root", + ["H"] = "toggle_hidden", + ["/"] = "fuzzy_finder", + ["D"] = "fuzzy_finder_directory", + ["f"] = "filter_on_submit", + [""] = "clear_filter", + ["[g"] = "prev_git_modified", + ["]g"] = "next_git_modified", + } + } + }, + buffers = { + follow_current_file = true, -- This will find and focus the file in the active buffer every + -- time the current file is changed while the tree is open. + group_empty_dirs = true, -- when true, empty folders will be grouped together + show_unloaded = true, + window = { + mappings = { + ["bd"] = "buffer_delete", + [""] = "navigate_up", + ["."] = "set_root", + } + }, + }, + git_status = { + window = { + position = "float", + mappings = { + ["A"] = "git_add_all", + ["gu"] = "git_unstage_file", + ["ga"] = "git_add_file", + ["gr"] = "git_revert_file", + ["gc"] = "git_commit", + ["gp"] = "git_push", + ["gg"] = "git_commit_and_push", + } + } + } + }) + + vim.api.nvim_set_keymap('n', '', [[Neotree toggle]], {}) + vim.api.nvim_set_keymap('n', '', [[Neotree reveal]], {}) + vim.api.nvim_set_keymap('n', 'G', [[Neotree git_status]], {}) +end + +return M diff --git a/dot_config/nvim/lua/configs/null-ls.lua b/dot_config/nvim/lua/configs/null-ls.lua new file mode 100644 index 0000000..2534e53 --- /dev/null +++ b/dot_config/nvim/lua/configs/null-ls.lua @@ -0,0 +1,58 @@ +local M = {} + +function M.setup() +local nls = require "null-ls" + +nls.setup({ + on_attach = require('configs.lsp').on_attach, + debug = true, + sources = { + nls.builtins.formatting.xmllint, + nls.builtins.formatting.jq, + nls.builtins.diagnostics.sqlfluff, + nls.builtins.diagnostics.phpstan.with({ + cwd = function(params) + -- falls back to root if return value is nil + return params.root:match("jopixel") and not params.root:match("repo") and "www"; + end + }), + nls.builtins.formatting.phpcsfixer.with({ + extra_args = { "--rules", [[ { + "@Symfony":true, + "nullable_type_declaration_for_default_null_value":true, + "array_syntax":{"syntax":"short"}, + "binary_operator_spaces":{ + "default":"single_space", + "operators": { + "=>":"align_single_space_minimal", + "=":"align_single_space_minimal", + "??=":"align_single_space_minimal", + "^=":"align_single_space_minimal", + "|=":"align_single_space_minimal", + "+=":"align_single_space_minimal", + "%=":"align_single_space_minimal", + "&=":"align_single_space_minimal", + "**=":"align_single_space_minimal", + "*=":"align_single_space_minimal", + "-=":"align_single_space_minimal", + ".=":"align_single_space_minimal", + "/=":"align_single_space_minimal", + "<<=":"align_single_space_minimal", + "<=":"align_single_space_minimal", + ">=":"align_single_space_minimal", + ">>=":"align_single_space_minimal" + } + }, + "fully_qualified_strict_types":false + } ]] } + }), + nls.builtins.diagnostics.shellcheck, + nls.builtins.formatting.eslint, + -- nls.builtins.diagnostics.eslint, + nls.builtins.code_actions.eslint, + nls.builtins.diagnostics.yamllint, + } +}) +end + +return M diff --git a/dot_config/nvim/lua/configs/nvim-cmp.lua b/dot_config/nvim/lua/configs/nvim-cmp.lua new file mode 100644 index 0000000..1817a2b --- /dev/null +++ b/dot_config/nvim/lua/configs/nvim-cmp.lua @@ -0,0 +1,36 @@ +local M = {} + +function M.setup() + local cmp = require 'cmp' + + cmp.setup({ + -- documentation = true, + sources = { + { name = 'nvim_lsp' }, + { name = 'nvim_lua' }, + { name = 'buffer' }, + { name = 'path' }, + -- { name = 'nvim_lsp_signature_help' }, + }, + formatting = { + format = require 'lspkind'.cmp_format({ + -- mode = 'symbol', + }), + }, + window = { + -- completion = cmp.config.window.bordered(), + -- documentation = cmp.config.window.bordered(), + }, + mapping = cmp.mapping.preset.insert({ + [''] = cmp.mapping.confirm({ select = false }) + }), + snippet = { + expand = function(args) + -- For `vsnip` user. + vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` user. + end + } + }) +end + +return M diff --git a/dot_config/nvim/lua/configs/nvimtree.lua b/dot_config/nvim/lua/configs/nvimtree.lua new file mode 100644 index 0000000..0635744 --- /dev/null +++ b/dot_config/nvim/lua/configs/nvimtree.lua @@ -0,0 +1,33 @@ +local M = {} +function M.setup() + require('nvim-tree').setup({ + sync_root_with_cwd = true, + renderer = { + add_trailing = true, + special_files = {}, + highlight_git = true, + indent_markers = { + enable = true, + }, + icons = { + show = { + file = false, + folder = false, + folder_arrow = false, + git = false + } + }, + }, + git = { + ignore = true + }, + filters = { + dotfiles = true, + }, + }) + + vim.api.nvim_set_keymap('n', '', [[NvimTreeToggle]], {}) + vim.api.nvim_set_keymap('n', '', [[NvimTreeFindFile]], {}) +end + +return M diff --git a/dot_config/nvim/lua/configs/options.lua b/dot_config/nvim/lua/configs/options.lua new file mode 100644 index 0000000..ffb0ecd --- /dev/null +++ b/dot_config/nvim/lua/configs/options.lua @@ -0,0 +1,44 @@ +local M = {} + +function M.setup() + vim.o.ruler = true + vim.o.mouse = '' + vim.o.showcmd = true + vim.o.scrolloff = 3 + vim.o.ignorecase = true + vim.o.smartcase = true + vim.o.incsearch = true + vim.o.inccommand = 'split' + vim.o.hidden = true + vim.o.autoread = true + vim.o.completeopt = 'menuone,noinsert,noselect' + vim.o.tabstop = 4 + vim.o.softtabstop = 4 + vim.o.swapfile = true + vim.o.undofile = true + vim.o.expandtab = true + vim.o.shiftwidth = 4 + vim.o.number = true + --vim.o.colorcolumn=0 + --vim.o.foldmethod='marker' + vim.o.foldcolumn = 'auto:1' + vim.o.signcolumn = 'yes' + vim.o.list = false + vim.o.relativenumber = false + vim.o.foldenable = true + vim.o.cursorline = true + vim.o.autoindent = true + vim.o.smartindent = true + vim.o.fileencodings = 'ucs-bom,utf-8,default,windows-1250,cp852' + vim.o.path = '**' + --vim.o.clipboard = "unnamedplus" + + -- Buffer + vim.cmd([[ + augroup forceRecheck + au FocusGained,BufEnter * :silent! ! + augroup END + ]]) +end + +return M diff --git a/dot_config/nvim/lua/configs/packages.lua b/dot_config/nvim/lua/configs/packages.lua new file mode 100644 index 0000000..7f505ed --- /dev/null +++ b/dot_config/nvim/lua/configs/packages.lua @@ -0,0 +1,131 @@ +local M = {} + +function M.setup() + local ensure_packer = function() + local fn = vim.fn + local install_path = fn.stdpath('data') .. '/site/pack/packer/start/packer.nvim' + if fn.empty(fn.glob(install_path)) > 0 then + fn.system({ 'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path }) + vim.cmd [[packadd packer.nvim]] + return true + end + return false + end + + local packer_bootstrap = ensure_packer() + + + require('packer').startup(function(use, use_rocks) + use 'wbthomason/packer.nvim' + + use { 'neovim/nvim-lspconfig', config = function() require("configs.lsp").setup() end } + use { 'hrsh7th/nvim-cmp', requires = { 'neovim/nvim-lspconfig' }, config = require("configs.nvim-cmp").setup } + use { 'hrsh7th/cmp-nvim-lsp', requires = { 'hrsh7th/nvim-cmp' } } + use { 'hrsh7th/cmp-buffer', requires = { 'hrsh7th/nvim-cmp' } } + use { 'hrsh7th/cmp-path', requires = { 'hrsh7th/nvim-cmp' } } + use { 'hrsh7th/cmp-nvim-lua', requires = { 'hrsh7th/nvim-cmp' } } + use 'hrsh7th/vim-vsnip' + use 'hrsh7th/cmp-nvim-lsp-signature-help' + + use { 'hrsh7th/cmp-vsnip', requires = { 'hrsh7th/nvim-cmp', 'hrsh7th/vim-vsnip' } } + use { 'onsails/lspkind.nvim' } + use 'ray-x/lsp_signature.nvim' + use { 'RishabhRD/nvim-lsputils', requires = { 'RishabhRD/popfix' } } + -- use { 'weilbith/nvim-code-action-menu', cmd = 'CodeActionMenu' } + -- use { 'simrat39/symbols-outline.nvim', cmd = 'SymbolsOutline' } + + use { 'stevearc/dressing.nvim' } + + use { 'jose-elias-alvarez/null-ls.nvim', requires = { "nvim-lua/plenary.nvim" } } + + use { 'nvim-treesitter/nvim-treesitter', + run = ':TSUpdate', + config = require("configs.treesitter").setup, + } + use 'nvim-treesitter/playground' + use 'David-Kunz/treesitter-unit' + use({ "yioneko/nvim-yati", requires = "nvim-treesitter/nvim-treesitter" }) + + use { 'nvim-telescope/telescope.nvim', + requires = { 'nvim-lua/popup.nvim', 'nvim-lua/plenary.nvim' }, + config = require("configs.telescope").setup, + } + use { 'nvim-telescope/telescope-fzf-native.nvim', + run = 'cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=Release && cmake --build build --config Release && cmake --install build --prefix build' + } + + use { 'morhetz/gruvbox' } + + use { 'chrisbra/Colorizer', cmd = 'ColorToggle', keys = { 'n', 'c ColorToggle' } } + + use { 'kdheepak/lazygit.nvim', keys = { 'n', 'g LazyGit' }, cmd = 'LazyGit' } + use { 'lewis6991/gitsigns.nvim', + requires = { 'nvim-lua/plenary.nvim' }, + config = function() require 'gitsigns'.setup({}) end } + + use { 'hoob3rt/lualine.nvim', + requires = { 'kyazdani42/nvim-web-devicons', opt = true }, + config = require("configs.lualine").setup + } + + use { 'AndrewRadev/linediff.vim', cmd = 'LineDiffAdd' } + + use 'lukas-reineke/indent-blankline.nvim' + + use { + 'b3nj5m1n/kommentary', + config = function() require('kommentary.config').configure_language("php", + { prefer_single_line_comments = true, }) + end + } + + use 'editorconfig/editorconfig-vim' + + use { + 'kyazdani42/nvim-tree.lua', + config = require("configs.nvimtree"), + disable = true, + } + + use { + "nvim-neo-tree/neo-tree.nvim", + branch = "v2.x", + requires = { + "nvim-lua/plenary.nvim", + "kyazdani42/nvim-web-devicons", -- not strictly required, but recommended + "MunifTanjim/nui.nvim", + }, + config = require("configs.neotree").setup, + } + + use { 'vim-vdebug/vdebug' } + + use { 'dyng/ctrlsf.vim', cmd = 'CtrlSF' } + + use { 'folke/lua-dev.nvim' } + use { 'rafcamlet/nvim-luapad' } + + use { 'AndrewRadev/tagalong.vim' } + use { 'andymass/vim-matchup' } + + use { 'fpob/nette.vim', ft = 'nette' } + + use { + 'folke/trouble.nvim', + requires = "kyazdani42/nvim-web-devicons", + cmd = 'TroubleToggle', + keys = { 'n', 't TroubleToggle' }, + config = function() require('trouble').setup() end + } + + use { 'ziglang/zig.vim', ft = 'zig' } + + use_rocks { 'inspect' } + + if packer_bootstrap then + require('packer').sync() + end + end) +end + +return M diff --git a/dot_config/nvim/lua/configs/telescope.lua b/dot_config/nvim/lua/configs/telescope.lua new file mode 100644 index 0000000..a7b79c5 --- /dev/null +++ b/dot_config/nvim/lua/configs/telescope.lua @@ -0,0 +1,51 @@ +local M = {} + +function M.setup() + vim.api.nvim_set_keymap('n', 'b', [[Telescope buffers]], { noremap = true, silent = true }) + vim.api.nvim_set_keymap('n', 'f', [[Telescope fd]], { noremap = true, silent = true }) + vim.api.nvim_set_keymap('n', 'T', [[Telescope]], { noremap = true, silent = true }) + + require("telescope").setup { + defaults = { + preview = { + hide_on_startup = true + }, + --[[ mappings = { +i = { +[""] = actions.toggle_preview, +}, +n = { +[""] = actions.toggle_preview, +}, +}, ]] + }, + pickers = { + buffers = { + show_all_buffers = true, + sort_lastused = false, + sort_mru = true, + -- theme = "dropdown", + mappings = { + i = { [""] = "delete_buffer", }, + n = { [""] = "delete_buffer", } + } + } + } + } + + require('telescope').load_extension('fzf') + + --[[ local telescope_ag = vim.api.nvim_create_augroup('Telescope') +nvim.nvim_create_autocmd('FileType', { pattern='TelescopePrompt', command = nvim.nvim_buf_set_keymap('n', '' ]] + vim.cmd 'augroup Telescope' + vim.cmd 'autocmd FileType TelescopePrompt inoremap Telescope buffers initial_mode=insert' + vim.cmd 'autocmd FileType TelescopePrompt inoremap Telescope fd initial_mode=insert' + vim.cmd 'autocmd FileType TelescopePrompt nnoremap Telescope buffers initial_mode=insert' + vim.cmd 'autocmd FileType TelescopePrompt nnoremap Telescope fd initial_mode=insert' + vim.cmd 'autocmd FileType TelescopePrompt inoremap Telescope builtin initial_mode=insert' + vim.cmd 'autocmd FileType TelescopePrompt nnoremap Telescope builtin initial_mode=insert' + vim.cmd 'augroup END' + +end + +return M diff --git a/dot_config/nvim/lua/configs/treesitter.lua b/dot_config/nvim/lua/configs/treesitter.lua new file mode 100644 index 0000000..08725ca --- /dev/null +++ b/dot_config/nvim/lua/configs/treesitter.lua @@ -0,0 +1,43 @@ +local M = {} + +function M.setup() + require 'nvim-treesitter.configs'.setup { + ensure_installed = 'all', -- one of "all", "maintained" (parsers with maintainers), or a list of languages + highlight = { enable = true, }, + playground = { enable = true, }, + yati = { enable = true, }, + incremental_selection = { + enable = true, + keymaps = { + init_selection = "gnn", + node_incremental = "+", + scope_incremental = "grc", + node_decremental = "-", + }, + }, + indent = { + -- disable = { "php" },-- php indent SUCKS A LOT + enable = false, + }, + } + + local ts_parsers = require 'nvim-treesitter.parsers'.get_parser_configs() + ts_parsers.xml = { + install_info = { + url = "https://github.com/dorgnarg/tree-sitter-xml", -- local path or git repo + files = { "src/parser.c" }, + -- optional entries: + branch = "main", -- default branch in case of git repo if different from master + generate_requires_npm = false, -- if stand-alone parser without npm dependencies + requires_generate_from_grammar = true, -- if folder contains pre-generated src/parser.c + }, + filetype = "xml", -- if filetype does not match the parser name + } + + vim.api.nvim_set_keymap('x', 'iu', ':lua require"treesitter-unit".select()', { noremap = true }) + vim.api.nvim_set_keymap('x', 'au', ':lua require"treesitter-unit".select(true)', { noremap = true }) + vim.api.nvim_set_keymap('o', 'iu', ':lua require"treesitter-unit".select()', { noremap = true }) + vim.api.nvim_set_keymap('o', 'au', ':lua require"treesitter-unit".select(true)', { noremap = true }) +end + +return M