--- s file can be loaded by calling `lua require('plugins')` from your init.vim
-- Only required if you have packer configured as `opt`
--
vim.cmd [[packadd packer.nvim]]

return require('packer').startup(function(use)
    -- basic packer
	use('wbthomason/packer.nvim')
    -- theme
	use({
		"neanias/everforest-nvim",
		config = function()
			vim.cmd("colorscheme everforest")
		end,

	})
    --- Telescope - fuzzy finder
    use({
        'nvim-telescope/telescope.nvim', tag = '0.1.8',
        requires = { {'nvim-lua/plenary.nvim'} }
    })

    -- Look
    use({ 'nvim-tree/nvim-web-devicons' })
    use({"nvim-lualine/lualine.nvim",
        config = function()
            require('lualine').setup {
                options= {theme = 'everforest'}
            }
        end
    })
    --- File Tree
    use({'nvim-tree/nvim-tree.lua'})

    --- Syntax & Higlights
    use('nvim-treesitter/nvim-treesitter', {run = ':TSUpdate'})

    -- Others / To filter
    -- use('mbbil/undotree')
    use("nvim-lua/plenary.nvim")
    use({
        "ThePrimeagen/harpoon",
        branch = "harpoon2",
        requires = { {"nvim-lua/plenary.nvim"} }
    })

    -- Prog only
    -- Auto pair
    use {
        "windwp/nvim-autopairs",
        event = "InsertEnter",
        config = function()
            require("nvim-autopairs").setup {}
        end
    }
    -- Git
    use({
        'lewis6991/gitsigns.nvim',
        requires = { 'nvim-lua/plenary.nvim' },
        config = function()
            require('gitsigns').setup()
        end
    })
    use ('tpope/vim-fugitive')
    --------------------- Default LSP / Completion / Formatters -----------------------
-- LSP Setup
use({
  'williamboman/mason.nvim',
  config = function()
    require("mason").setup()
  end,
})

-- Bridge Mason-installed servers to nvim-lspconfig
use {
  'williamboman/mason-lspconfig.nvim',
  requires = {
    'williamboman/mason.nvim',
    'neovim/nvim-lspconfig',
  },
  after = { 'mason.nvim', 'nvim-lspconfig' },
config = function()
  local mason_lspconfig = require("mason-lspconfig")
  local lspconfig = require("lspconfig")

  mason_lspconfig.setup({
    ensure_installed = { "rust_analyzer", "pyright", "lua_ls" },
    automatic_installation = true,
  })
end,
}
-- use({
--   'williamboman/mason-lspconfig.nvim',
--   after = 'mason.nvim',
--   config = function()
-- local lspconfig = require("lspconfig")
--
-- -- Override default `rust_analyzer` config BEFORE handlers run
-- lspconfig.rust_analyzer = {
--   default_config = {
--     cmd = { "rust-analyzer" },
--     filetypes = { "rust" },
--     root_dir = lspconfig.util.root_pattern("Cargo.toml", "rust-project.json", ".git"),
--     settings = {}, -- clean default settings
--   }
-- }
--     local mason_lspconfig = require("mason-lspconfig")
--     mason_lspconfig.setup({
--       ensure_installed = {
--         "rust_analyzer",
--         "pyright",
--         "lua_ls",
--       },
--       automatic_installation = true,
--     })
--
--     local lspconfig = require("lspconfig")
--         lspconfig.rust_analyzer = {
--       default_config = {
--         cmd = { "rust-analyzer" },
--         filetypes = { "rust" },
--         root_dir = lspconfig.util.root_pattern("Cargo.toml", "rust-project.json", ".git"),
--         settings = {},
--       }
--     }
--     lspconfig.rust_analyzer = nil
--     package.loaded["lspconfig.server_configurations.rust_analyzer"] = nil
--     for _, server in ipairs(mason_lspconfig.get_installed_servers()) do
--       local opts = {}
--
--       if server == "rust_analyzer" then
--         opts.settings = {
--           ["rust_analyzer"] = {
--             checkOnSave = {
--               command = "clippy",
--               extraArgs = { "--no-deps" }
--             },
--             inlayHints = {
--               enable = true,
--               typeHints = { enable = true },
--               parameterHints = { enable = true },
--             },
--           },
--         }
--       elseif server == "pyright" then
--         opts.settings = {
--           python = {
--             analysis = {
--               autoSearchPaths = true,
--               diagnosticMode = "openFilesOnly",
--               useLibraryCodeForTypes = true,
--             }
--           }
--         }
--       end
--
--       lspconfig[server].setup(opts)
--     end
--   end,
-- })
	use('hrsh7th/nvim-cmp')                     -- Core completion plugin :contentReference[oaicite:6]{index=6}
	use('hrsh7th/cmp-nvim-lsp')                 -- LSP source for nvim-cmp
	use('L3MON4D3/LuaSnip')                     -- Snippet engine (optional)
    -- use("simrat39/rust-tools.nvim")
	use('saadparwaiz1/cmp_luasnip')     -- Snippet completions
	use('jose-elias-alvarez/null-ls.nvim')
	use('jay-babu/mason-null-ls.nvim')

    -- Rust IDE part
    use {
        'mfussenegger/nvim-dap',
        config = function()
            require('ntaun.lsp.rust.nvim-dap')
        end,
    }
    use {
        'rcarriga/nvim-dap-ui',
        requires = { 'mfussenegger/nvim-dap', 'nvim-neotest/nvim-nio' },
        config = function()
            require("dapui").setup()
        end,
    }
    use {
        'rust-lang/rust.vim',
        ft = 'rust',
        config = function()
            require("ntaun.lsp.rust.rust-vim")
        end,
    }
-- use {
--   'mrcjkb/rustaceanvim',
--   ft = { 'rust' },
--   init = function()
--     -- disable rustaceanvim's LSP client,
--     -- but leave any DAP or other bits intact (or remove them if unused)
--     vim.g.rustaceanvim = {
--       mason = { enable = false },  -- no auto-mason for LSP
--       lsp    = { enable = false }, -- no auto-setup of rust-analyzer
--       -- dap = { /* your existing dap config, if you still want it */ },
--     }
--   end,
--   config = function()
--     require('ntaun.lsp.rust.rustaceanvim')
--   end,
-- }
    use {
        'saecki/crates.nvim',
        ft = { 'toml' },
        config = function()
            require('ntaun.lsp.rust.crates')
        end,
    }

     -- Python LSP / DAP
     use{'linux-cultist/venv-selector.nvim',
     requires = {
         'neovim/nvim-lspconfig',
         'nvim-telescope/telescope.nvim',
         'mfussenegger/nvim-dap-python',
     },
     config = function ()
         require('ntaun.venv-selector')
     end,
     cmd = {'VenvSelect','VenvSelectCached'},
     keys = {'<leader>vs', '<leader>vc' },
 }
end)



