Configure NVIM config folder dynamically

This commit is contained in:
2023-09-15 14:41:31 +03:00
parent 75488a16c4
commit d08155e0e9
25 changed files with 56 additions and 460 deletions

View File

@@ -61,26 +61,26 @@
withPython3 = false; withPython3 = false;
withRuby = false; withRuby = false;
extraPython3Packages = false; extraPython3Packages = false;
extraMakeWrapperArgs = ''--prefix PATH : "${pkgs.lib.makeBinPath dependencies}"''; extraMakeWrapperArgs = ''--prefix PATH : "${pkgs.lib.makeBinPath dependencies}" --set XDG_CONFIG_HOME "${self}"'';
# make sure impatient is loaded before everything else to speed things up # make sure impatient is loaded before everything else to speed things up
configure = { # configure = {
customRC = # customRC =
'' # ''
lua << EOF # lua << EOF
package.path = "${self}/lua/?.lua;" .. package.path # package.path = "${self}/lua/?.lua;" .. package.path
'' # ''
+ pkgs.lib.readFile ./init.lua # + pkgs.lib.readFile ./init.lua
+ '' # + ''
EOF # EOF
''; # '';
# packages.myPlugins = with pkgs.vimPlugins; { # # packages.myPlugins = with pkgs.vimPlugins; {
# start = with pkgs.vimPlugins; []; # # start = with pkgs.vimPlugins; [];
# opt = with pkgs.vimPlugins; []; # # opt = with pkgs.vimPlugins; [];
# }; # # };
}; # };
}; };
apps.pwnvim = flake-utils.lib.mkApp { apps.pwnvim = flake-utils.lib.mkApp {
drv = packages.pwnvim; drv = self.packages.${system}.pwnvim;
name = "pwnvim"; name = "pwnvim";
exePath = "/bin/nvim"; exePath = "/bin/nvim";
}; };

View File

@@ -1,16 +0,0 @@
return {
"williamboman/mason.nvim",
opts = function(_, opts)
opts.ensure_installed = opts.ensure_installed or {}
vim.list_extend(opts.ensure_installed, {
"prettierd",
"gomodifytags",
"impl",
"gofumpt",
"goimports-reviser",
"delve",
"java-test",
"java-debug-adapter",
})
end,
}

View File

@@ -1,3 +0,0 @@
return {
"nvim-neotest/neotest-go",
}

View File

@@ -1,3 +0,0 @@
return {
"nvim-neotest/neotest-python",
}

View File

@@ -1,20 +0,0 @@
return {
"nvim-neotest/neotest",
optional = true,
dependencies = {
"nvim-neotest/neotest-go",
},
opts = {
adapters = {
["neotest-python"] = {
-- Here you can specify the settings for the adapter, i.e.
-- runner = "pytest",
-- python = ".venv/bin/python",
},
["neotest-go"] = {
-- Here we can set options for neotest-go, e.g.
-- args = { "-tags=integration" }
},
},
},
}

View File

@@ -1,18 +0,0 @@
return {
"jose-elias-alvarez/null-ls.nvim",
opts = function(_, opts)
if type(opts.sources) == "table" then
local null_ls = require("null-ls")
vim.list_extend(opts.sources, {
null_ls.builtins.diagnostics.hadolint,
null_ls.builtins.formatting.prettierd,
null_ls.builtins.formatting.terraform_fmt,
null_ls.builtins.diagnostics.terraform_validate,
null_ls.builtins.code_actions.gomodifytags,
null_ls.builtins.code_actions.impl,
null_ls.builtins.formatting.gofumpt,
null_ls.builtins.formatting.goimports_reviser,
})
end
end,
}

View File

@@ -1,4 +0,0 @@
return {
"leoluz/nvim-dap-go",
config = true,
}

View File

@@ -1,12 +0,0 @@
return {
"mfussenegger/nvim-dap-python",
-- stylua: ignore
keys = {
{ "<leader>dPt", function() require('dap-python').test_method() end, desc = "Debug Method" },
{ "<leader>dPc", function() require('dap-python').test_class() end, desc = "Debug Class" },
},
config = function()
local path = require("mason-registry").get_package("debugpy"):get_install_path()
require("dap-python").setup(path .. "/venv/bin/python")
end,
}

View File

@@ -1,4 +0,0 @@
return {
"mfussenegger/nvim-dap",
optional = true,
}

View File

@@ -1,163 +0,0 @@
return {
"mfussenegger/nvim-jdtls",
ft = java_filetypes,
opts = function()
return {
-- How to find the root dir for a given filename. The default comes from
-- lspconfig which provides a function specifically for java projects.
root_dir = require("lspconfig.server_configurations.jdtls").default_config.root_dir,
-- How to find the project name for a given root dir.
project_name = function(root_dir)
return root_dir and vim.fs.basename(root_dir)
end,
-- Where are the config and workspace dirs for a project?
jdtls_config_dir = function(project_name)
return vim.fn.stdpath("cache") .. "/jdtls/" .. project_name .. "/config"
end,
jdtls_workspace_dir = function(project_name)
return vim.fn.stdpath("cache") .. "/jdtls/" .. project_name .. "/workspace"
end,
-- How to run jdtls. This can be overridden to a full java command-line
-- if the Python wrapper script doesn't suffice.
cmd = { "jdtls" },
full_cmd = function(opts)
local fname = vim.api.nvim_buf_get_name(0)
local root_dir = opts.root_dir(fname)
local project_name = opts.project_name(root_dir)
local cmd = vim.deepcopy(opts.cmd)
if project_name then
vim.list_extend(cmd, {
"-configuration",
opts.jdtls_config_dir(project_name),
"-data",
opts.jdtls_workspace_dir(project_name),
})
end
return cmd
end,
-- These depend on nvim-dap, but can additionally be disabled by setting false here.
dap = { hotcodereplace = "auto", config_overrides = {} },
test = true,
}
end,
config = function()
local opts = Util.opts("nvim-jdtls") or {}
-- Find the extra bundles that should be passed on the jdtls command-line
-- if nvim-dap is enabled with java debug/test.
local mason_registry = require("mason-registry")
local bundles = {} ---@type string[]
if opts.dap and Util.has("nvim-dap") and mason_registry.is_installed("java-debug-adapter") then
local java_dbg_pkg = mason_registry.get_package("java-debug-adapter")
local java_dbg_path = java_dbg_pkg:get_install_path()
local jar_patterns = {
java_dbg_path .. "/extension/server/com.microsoft.java.debug.plugin-*.jar",
}
-- java-test also depends on java-debug-adapter.
if opts.test and mason_registry.is_installed("java-test") then
local java_test_pkg = mason_registry.get_package("java-test")
local java_test_path = java_test_pkg:get_install_path()
vim.list_extend(jar_patterns, {
java_test_path .. "/extension/server/*.jar",
})
end
for _, jar_pattern in ipairs(jar_patterns) do
for _, bundle in ipairs(vim.split(vim.fn.glob(jar_pattern), "\n")) do
table.insert(bundles, bundle)
end
end
end
local function attach_jdtls()
local fname = vim.api.nvim_buf_get_name(0)
-- Configuration can be augmented and overridden by opts.jdtls
local config = extend_or_override({
cmd = opts.full_cmd(opts),
root_dir = opts.root_dir(fname),
init_options = {
bundles = bundles,
},
-- enable CMP capabilities
capabilities = require("cmp_nvim_lsp").default_capabilities(),
}, opts.jdtls)
-- Existing server will be reused if the root_dir matches.
require("jdtls").start_or_attach(config)
-- not need to require("jdtls.setup").add_commands(), start automatically adds commands
end
-- Attach the jdtls for each java buffer. HOWEVER, this plugin loads
-- depending on filetype, so this autocmd doesn't run for the first file.
-- For that, we call directly below.
vim.api.nvim_create_autocmd("FileType", {
pattern = java_filetypes,
callback = attach_jdtls,
})
-- Setup keymap and dap after the lsp is fully attached.
-- https://github.com/mfussenegger/nvim-jdtls#nvim-dap-configuration
-- https://neovim.io/doc/user/lsp.html#LspAttach
vim.api.nvim_create_autocmd("LspAttach", {
callback = function(args)
local client = vim.lsp.get_client_by_id(args.data.client_id)
if client and client.name == "jdtls" then
local wk = require("which-key")
wk.register({
["<leader>cx"] = { name = "+extract" },
["<leader>cxv"] = { require("jdtls").extract_variable_all, "Extract Variable" },
["<leader>cxc"] = { require("jdtls").extract_constant, "Extract Constant" },
["gs"] = { require("jdtls").super_implementation, "Goto Super" },
["gS"] = { require("jdtls.tests").goto_subjects, "Goto Subjects" },
["<leader>co"] = { require("jdtls").organize_imports, "Organize Imports" },
}, { mode = "n", buffer = args.buf })
wk.register({
["<leader>c"] = { name = "+code" },
["<leader>cx"] = { name = "+extract" },
["<leader>cxm"] = {
[[<ESC><CMD>lua require('jdtls').extract_method(true)<CR>]],
"Extract Method",
},
["<leader>cxv"] = {
[[<ESC><CMD>lua require('jdtls').extract_variable_all(true)<CR>]],
"Extract Variable",
},
["<leader>cxc"] = {
[[<ESC><CMD>lua require('jdtls').extract_constant(true)<CR>]],
"Extract Constant",
},
}, { mode = "v", buffer = args.buf })
if opts.dap and Util.has("nvim-dap") and mason_registry.is_installed("java-debug-adapter") then
-- custom init for Java debugger
require("jdtls").setup_dap(opts.dap)
require("jdtls.dap").setup_dap_main_class_configs()
-- Java Test require Java debugger to work
if opts.test and mason_registry.is_installed("java-test") then
-- custom keymaps for Java test runner (not yet compatible with neotest)
wk.register({
["<leader>t"] = { name = "+test" },
["<leader>tt"] = { require("jdtls.dap").test_class, "Run All Test" },
["<leader>tr"] = { require("jdtls.dap").test_nearest_method, "Run Nearest Test" },
["<leader>tT"] = { require("jdtls.dap").pick_test, "Run Test" },
}, { mode = "n", buffer = args.buf })
end
end
-- User can set additional keymaps in opts.on_attach
if opts.on_attach then
opts.on_attach(args)
end
end
end,
})
-- Avoid race condition by calling attach the first time, since the autocmd won't fire.
attach_jdtls()
end,
}

View File

@@ -1,136 +0,0 @@
return {
"neovim/nvim-lspconfig",
opts = {
servers = {
jdtls = {},
dockerls = {},
docker_compose_language_service = {},
terraformls = {},
pyright = {},
ruff_lsp = {},
yamlls = {
-- Have to add this for yamlls to understand that we support line folding
capabilities = {
textDocument = {
foldingRange = {
dynamicRegistration = false,
lineFoldingOnly = true,
},
},
},
-- lazy-load schemastore when needed
on_new_config = function(new_config)
new_config.settings.yaml.schemas = new_config.settings.yaml.schemas or {}
vim.list_extend(new_config.settings.yaml.schemas, require("schemastore").yaml.schemas())
end,
settings = {
redhat = { telemetry = { enabled = false } },
yaml = {
keyOrdering = false,
format = {
enable = true,
},
validate = true,
schemaStore = {
-- Must disable built-in schemaStore support to use
-- schemas from SchemaStore.nvim plugin
enable = false,
-- Avoid TypeError: Cannot read properties of undefined (reading 'length')
url = "",
},
},
},
},
jsonls = {
-- lazy-load schemastore when needed
on_new_config = function(new_config)
new_config.settings.json.schemas = new_config.settings.json.schemas or {}
vim.list_extend(new_config.settings.json.schemas, require("schemastore").json.schemas())
end,
settings = {
json = {
format = {
enable = true,
},
validate = { enable = true },
},
},
},
gopls = {
keys = {
-- Workaround for the lack of a DAP strategy in neotest-go: https://github.com/nvim-neotest/neotest-go/issues/12
{ "<leader>td", "<cmd>lua require('dap-go').debug_test()<CR>", desc = "Debug Nearest (Go)" },
},
settings = {
gopls = {
gofumpt = true,
codelenses = {
gc_details = false,
generate = true,
regenerate_cgo = true,
run_govulncheck = true,
test = true,
tidy = true,
upgrade_dependency = true,
vendor = true,
},
hints = {
assignVariableTypes = true,
compositeLiteralFields = true,
compositeLiteralTypes = true,
constantValues = true,
functionTypeParameters = true,
parameterNames = true,
rangeVariableTypes = true,
},
analyses = {
fieldalignment = true,
nilness = true,
unusedparams = true,
unusedwrite = true,
useany = true,
},
usePlaceholders = true,
completeUnimported = true,
staticcheck = true,
directoryFilters = { "-.git", "-.vscode", "-.idea", "-.vscode-test", "-node_modules" },
semanticTokens = true,
},
},
},
},
setup = {
gopls = function(_, opts)
-- workaround for gopls not supporting semanticTokensProvider
-- https://github.com/golang/go/issues/54531#issuecomment-1464982242
require("lazyvim.util").on_attach(function(client, _)
if client.name == "gopls" then
if not client.server_capabilities.semanticTokensProvider then
local semantic = client.config.capabilities.textDocument.semanticTokens
client.server_capabilities.semanticTokensProvider = {
full = true,
legend = {
tokenTypes = semantic.tokenTypes,
tokenModifiers = semantic.tokenModifiers,
},
range = true,
}
end
end
end)
-- end workaround
end,
jdtls = function()
return true -- avoid duplicate servers
end,
ruff_lsp = function()
require("lazyvim.util").on_attach(function(client, _)
if client.name == "ruff_lsp" then
-- Disable hover in favor of Pyright
client.server_capabilities.hoverProvider = false
end
end)
end,
},
},
}

View File

@@ -1,25 +0,0 @@
return {
"nvim-treesitter/nvim-treesitter",
opts = function(_, opts)
if type(opts.ensure_installed) == "table" then
vim.list_extend(opts.ensure_installed, {
"java",
"go",
"gomod",
"gowork",
"gosum",
"dockerfile",
"terraform",
"hcl",
"json",
"json5",
"jsonc",
"ninja",
"python",
"rst",
"toml",
"yaml",
})
end
end,
}

View File

@@ -1,4 +0,0 @@
return {
"b0o/SchemaStore.nvim",
version = false, -- last release is way too old
}

View File

@@ -1,10 +0,0 @@
return {
"telescope.nvim",
dependencies = {
"nvim-telescope/telescope-fzf-native.nvim",
build = "make",
config = function()
require("telescope").load_extension("fzf")
end,
},
}

View File

@@ -1,13 +0,0 @@
return {
"linux-cultist/venv-selector.nvim",
cmd = "VenvSelect",
opts = {
name = {
"venv",
".venv",
"env",
".env",
},
},
keys = { { "<leader>cv", "<cmd>:VenvSelect<cr>", desc = "Select VirtualEnv" } },
}

View File

@@ -1 +0,0 @@
return { "folke/which-key.nvim" }

15
nvim/.neoconf.json Normal file
View File

@@ -0,0 +1,15 @@
{
"neodev": {
"library": {
"enabled": true,
"plugins": true
}
},
"neoconf": {
"plugins": {
"lua_ls": {
"enabled": true
}
}
}
}

View File

@@ -11,16 +11,6 @@ require("lazy").setup({
spec = { spec = {
-- add LazyVim and import its plugins -- add LazyVim and import its plugins
{ "LazyVim/LazyVim", import = "lazyvim.plugins" }, { "LazyVim/LazyVim", import = "lazyvim.plugins" },
{
"folke/tokyonight.nvim",
opts = {
transparent = true,
styles = {
sidebars = "transparent",
floats = "transparent",
},
},
},
{ import = "lazyvim.plugins.extras.ui.mini-animate" }, { import = "lazyvim.plugins.extras.ui.mini-animate" },
{ import = "lazyvim.plugins.extras.lang.python" }, { import = "lazyvim.plugins.extras.lang.python" },
{ import = "lazyvim.plugins.extras.lang.json" }, { import = "lazyvim.plugins.extras.lang.json" },
@@ -30,7 +20,7 @@ require("lazy").setup({
{ import = "lazyvim.plugins.extras.lang.json" }, { import = "lazyvim.plugins.extras.lang.json" },
{ import = "lazyvim.plugins.extras.lang.terraform" }, { import = "lazyvim.plugins.extras.lang.terraform" },
{ import = "lazyvim.plugins.extras.lang.yaml" }, { import = "lazyvim.plugins.extras.lang.yaml" },
{ import = "plugins" }, { import = "plugins.tokyonight" },
}, },
defaults = { defaults = {
-- By default, only LazyVim plugins will be lazy-loaded. Your custom plugins will load during startup. -- By default, only LazyVim plugins will be lazy-loaded. Your custom plugins will load during startup.

View File

@@ -0,0 +1,10 @@
return {
"telescope.nvim",
dependencies = {
"nvim-telescope/telescope-fzf-native.nvim",
build = "make",
config = function()
require("telescope").load_extension("fzf")
end,
},
}

View File

@@ -0,0 +1,10 @@
return {
"folke/tokyonight.nvim",
opts = {
transparent = true,
styles = {
sidebars = "transparent",
floats = "transparent",
},
},
}

3
nvim/stylua.toml Normal file
View File

@@ -0,0 +1,3 @@
indent_type = "Spaces"
indent_width = 2
column_width = 120