From c795a01c103c6de6e00bbe7a950f65754aed9ef2 Mon Sep 17 00:00:00 2001 From: hollorol Date: Tue, 30 Jul 2024 20:11:20 +0200 Subject: [PATCH] Fully working python and R plugins --- init.lua | 1 + lua/config/plugins/init.lua | 1 - lua/config/plugins/iron.lua | 63 +++++++++++++ lua/config/plugins/mazon.lua | 150 ++++++++++++++++++++++++++++++ lua/config/plugins/nvimr.lua | 17 ---- lua/config/plugins/python.lua | 4 + lua/config/plugins/treesitter.lua | 9 ++ 7 files changed, 227 insertions(+), 18 deletions(-) create mode 100644 lua/config/plugins/iron.lua create mode 100644 lua/config/plugins/mazon.lua create mode 100644 lua/config/plugins/python.lua create mode 100644 lua/config/plugins/treesitter.lua diff --git a/init.lua b/init.lua index 51b75a7..b5d710b 100644 --- a/init.lua +++ b/init.lua @@ -2,3 +2,4 @@ require("config.options") require("config.keymaps") require("config.lazy") require("custom.functions") +-- require("custom.chatgpt") diff --git a/lua/config/plugins/init.lua b/lua/config/plugins/init.lua index 0f5e83b..cf76e88 100644 --- a/lua/config/plugins/init.lua +++ b/lua/config/plugins/init.lua @@ -1,7 +1,6 @@ return { {'tpope/vim-fugitive'}, {'gorkunov/smartpairs.vim'}, - {'SirVer/ultisnips'}, {'tpope/vim-surround'}, {'mattn/emmet-vim', ft = { 'html', 'css', 'javascript', 'typescript', 'vue' }, diff --git a/lua/config/plugins/iron.lua b/lua/config/plugins/iron.lua new file mode 100644 index 0000000..af19167 --- /dev/null +++ b/lua/config/plugins/iron.lua @@ -0,0 +1,63 @@ +return { + 'Vigemus/iron.nvim', + config = function () + + local iron = require("iron.core") + + iron.setup { + config = { + -- Whether a repl should be discarded or not + scratch_repl = true, + -- Your repl definitions come here + repl_definition = { + sh = { + -- Can be a table or a function that + -- returns a table (see below) + command = {"bash"} + }, + python = { + command = { "ipython3", "--no-autoindent" }, -- or { "ipython", "--no-autoindent" } + format = require("iron.fts.common").bracketed_paste_python + } + }, + -- How the repl window will be displayed + -- See below for more information + repl_open_cmd = require('iron.view').split.below(80), + }, + -- Iron doesn't set keymaps by default anymore. + -- You can set them here or manually add keymaps to the functions in iron.core + keymaps = { + send_motion = "sc", + visual_send = "sc", + send_file = "sf", + send_line = "sl", + send_paragraph = "sp", + send_until_cursor = "su", + send_mark = "sm", + mark_motion = "mc", + mark_visual = "mc", + remove_mark = "md", + cr = "s", + interrupt = "s", + exit = "sq", + clear = "cl", + }, + -- If the highlight is on, you can change how it looks + -- For the available options, check nvim_set_hl + highlight = { + italic = true + }, + ignore_blank_lines = true, -- ignore blank lines when sending visual select lines + } + + -- iron also has a list of commands, see :h iron-commands for all available commands + vim.keymap.set('n', 'rs', 'IronRepl') + vim.keymap.set('n', 'rr', 'IronRestart') + vim.keymap.set('n', 'rf', 'IronFocus') + vim.keymap.set('n', 'rh', 'IronHide') + + + + + end +} diff --git a/lua/config/plugins/mazon.lua b/lua/config/plugins/mazon.lua new file mode 100644 index 0000000..d7e12fe --- /dev/null +++ b/lua/config/plugins/mazon.lua @@ -0,0 +1,150 @@ +return { + -- Mason for managing external tools (LSP servers, linters, etc.) + { + "williamboman/mason.nvim", + config = function() + require("mason").setup() + end + }, + -- Mason LSP config to bridge Mason and nvim-lspconfig + { + "williamboman/mason-lspconfig.nvim", + config = function() + require("mason-lspconfig").setup { + ensure_installed = {"pyright"} + } + end + }, + -- nvim-lspconfig for configuring LSP servers + { + "neovim/nvim-lspconfig", + config = function() + local lspconfig = require("lspconfig") + local capabilities = require('cmp_nvim_lsp').default_capabilities() + + -- Setup LSP server (Pyright for Python) + lspconfig.pyright.setup { + capabilities = capabilities, + on_attach = function(client, bufnr) + local buf_set_keymap = vim.api.nvim_buf_set_keymap + local buf_set_option = vim.api.nvim_buf_set_option + + buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') + + -- Key mappings for LSP + local opts = { noremap = true, silent = true } + buf_set_keymap(bufnr, 'n', 'gD', 'lua vim.lsp.buf.declaration()', opts) + buf_set_keymap(bufnr, 'n', 'gd', 'lua vim.lsp.buf.definition()', opts) + buf_set_keymap(bufnr, 'n', 'K', 'lua vim.lsp.buf.hover()', opts) + buf_set_keymap(bufnr, 'n', 'gi', 'lua vim.lsp.buf.implementation()', opts) + buf_set_keymap(bufnr, 'n', '', 'lua vim.lsp.buf.signature_help()', opts) + buf_set_keymap(bufnr, 'n', 'wa', 'lua vim.lsp.buf.add_workspace_folder()', opts) + buf_set_keymap(bufnr, 'n', 'wr', 'lua vim.lsp.buf.remove_workspace_folder()', opts) + buf_set_keymap(bufnr, 'n', 'wl', 'lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))', opts) + buf_set_keymap(bufnr, 'n', 'D', 'lua vim.lsp.buf.type_definition()', opts) + buf_set_keymap(bufnr, 'n', 'rn', 'lua vim.lsp.buf.rename()', opts) + buf_set_keymap(bufnr, 'n', 'gr', 'lua vim.lsp.buf.references()', opts) + buf_set_keymap(bufnr, 'n', 'e', 'lua vim.lsp.diagnostic.show_line_diagnostics()', opts) + buf_set_keymap(bufnr, 'n', '[d', 'lua vim.lsp.diagnostic.goto_prev()', opts) + buf_set_keymap(bufnr, 'n', ']d', 'lua vim.lsp.diagnostic.goto_next()', opts) + buf_set_keymap(bufnr, 'n', 'q', 'lua vim.lsp.diagnostic.set_loclist()', opts) + buf_set_keymap(bufnr, 'n', 'so', [[lua require('telescope.builtin').lsp_document_symbols()]], opts) + vim.cmd [[ command! Format execute 'lua vim.lsp.buf.formatting()' ]] + + -- Scroll hover documentation + buf_set_keymap(bufnr, 'n', '', 'lua vim.lsp.util.scroll_popup(1)', opts) + buf_set_keymap(bufnr, 'n', '', 'lua vim.lsp.util.scroll_popup(-1)', opts) + end, + } + end + }, + -- nvim-cmp for autocompletion + { + "hrsh7th/nvim-cmp", + dependencies = { + "SirVer/ultisnips", + "hrsh7th/cmp-nvim-lsp", + "hrsh7th/cmp-buffer", + "hrsh7th/cmp-path", + "hrsh7th/cmp-cmdline", + "quangnguyen30192/cmp-nvim-ultisnips", + -- "nvim-treesitter/nvim-treesitter", -- Ensure this for better syntax highlighting + "onsails/lspkind-nvim", + "hrsh7th/cmp-nvim-lsp-signature-help", + "R-nvim/cmp-r" + }, + config = function() + local cmp = require'cmp' + local lspkind = require('lspkind') + + cmp.setup({ + snippet = { + expand = function(args) + vim.fn["UltiSnips#Anon"](args.body) + end, + }, + mapping = { + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.abort(), + [''] = cmp.mapping.confirm({ select = true }), + [''] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif vim.fn["UltiSnips#CanExpandSnippet"]() == 1 then + vim.fn.feedkeys(vim.api.nvim_replace_termcodes("=UltiSnips#ExpandSnippet()", true, true, true), "") + elseif vim.fn["UltiSnips#CanJumpForwards"]() == 1 then + vim.fn.feedkeys(vim.api.nvim_replace_termcodes("=UltiSnips#JumpForwards()", true, true, true), "") + else + fallback() + end + end, { "i", "s" }), + [''] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + elseif vim.fn["UltiSnips#CanJumpBackwards"]() == 1 then + vim.fn.feedkeys(vim.api.nvim_replace_termcodes("=UltiSnips#JumpBackwards()", true, true, true), "") + else + fallback() + end + end, { "i", "s" }), + }, + sources = cmp.config.sources({ + { name = 'nvim_lsp' }, + { name = 'nvim_lsp_signature_help' }, + { name = 'ultisnips' }, + { name = "cmp_r" } + }, { + { name = 'buffer' }, + }), + formatting = { + format = lspkind.cmp_format({ with_text = true, maxwidth = 50 }) + } + }) + + -- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore). + cmp.setup.cmdline('/', { + sources = { + { name = 'buffer' } + } + }) + + cmp.setup.cmdline('?', { + sources = { + { name = 'buffer' } + } + }) + + -- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore). + cmp.setup.cmdline(':', { + sources = cmp.config.sources({ + { name = 'path' } + }, { + { name = 'cmdline' } + }) + }) + require("cmp_r").setup({ }) + end + } +} diff --git a/lua/config/plugins/nvimr.lua b/lua/config/plugins/nvimr.lua index eef99ff..94b031e 100644 --- a/lua/config/plugins/nvimr.lua +++ b/lua/config/plugins/nvimr.lua @@ -2,22 +2,5 @@ return { { "R-nvim/R.nvim", lazy = false - }, - { - "nvim-treesitter/nvim-treesitter", - run = ":TSUpdate", - config = function () - require("nvim-treesitter.configs").setup({ - ensure_installed = { "markdown", "markdown_inline", "r", "rnoweb", "yaml" }, - }) - end - }, - "R-nvim/cmp-r", - { - "hrsh7th/nvim-cmp", - config = function() - require("cmp").setup({ sources = {{ name = "cmp_r" }}}) - require("cmp_r").setup({ }) - end, } } diff --git a/lua/config/plugins/python.lua b/lua/config/plugins/python.lua new file mode 100644 index 0000000..8cedf48 --- /dev/null +++ b/lua/config/plugins/python.lua @@ -0,0 +1,4 @@ +return { + + +} diff --git a/lua/config/plugins/treesitter.lua b/lua/config/plugins/treesitter.lua new file mode 100644 index 0000000..940020a --- /dev/null +++ b/lua/config/plugins/treesitter.lua @@ -0,0 +1,9 @@ +return{ + "nvim-treesitter/nvim-treesitter", + run = ":TSUpdate", + config = function () + require("nvim-treesitter.configs").setup({ + ensure_installed = { "markdown", "markdown_inline", "r", "rnoweb", "yaml", "python"}, + }) + end +}