add config

This commit is contained in:
nik
2025-10-05 16:58:08 +03:00
parent 61fc1ec1ba
commit 6b1626bb41
19 changed files with 1022 additions and 0 deletions

29
lua/configs/conform.lua Normal file
View File

@@ -0,0 +1,29 @@
local conform = require("conform")
local options = {
formatters_by_ft = {
lua = { "stylua" },
css = { "prettier" },
html = { "prettier" },
javascript = { "prettier" },
javascriptreact = { "prettier" },
typescript = { "prettier" },
typescriptreact = { "prettier" },
json = { "prettier" },
-- Add C++ formatters
cpp = { "clang-format" },
c = { "clang-format" },
python = { "black", "isort" },
cs = { "csharpier" },
},
format_on_save = {
-- These options will be passed to conform.format()
timeout_ms = 500,
lsp_fallback = true,
},
}
return options

19
lua/configs/cpp.lua Normal file
View File

@@ -0,0 +1,19 @@
local M = {}
M.setup = function()
-- Any specific C++ settings can go here
vim.opt.tabstop = 2
vim.opt.shiftwidth = 2
vim.opt.expandtab = true
-- For C++ projects, you might want to set up a compile command
vim.api.nvim_create_user_command("CppBuild", function()
vim.cmd("!g++ -std=c++17 % -o %:r")
end, {})
vim.api.nvim_create_user_command("CppRun", function()
vim.cmd("!g++ -std=c++17 % -o %:r && ./%:r")
end, {})
end
return M

23
lua/configs/csharp.lua Normal file
View File

@@ -0,0 +1,23 @@
local M = {}
M.setup = function()
local dap = require("dap")
dap.adapters.coreclr = {
type = "executable",
command = "netcoredbg",
args = { "--interpreter=vscode" },
}
dap.configurations = dap.configurations or {}
dap.configurations.cs = {
{
type = "coreclr",
name = "launch",
request = "launch",
program = function()
return vim.fn.input("Path to dll: ", vim.fn.getcwd() .. "/bin/Debug/net8.0/", "file")
end,
},
}
end
return M

130
lua/configs/java.lua Normal file
View File

@@ -0,0 +1,130 @@
local M = {}
M.setup = function()
-- Java-specific settings
vim.opt_local.tabstop = 4
vim.opt_local.shiftwidth = 4
vim.opt_local.expandtab = true
-- Quick commands for Java
vim.api.nvim_create_user_command("JavaRun", function()
vim.cmd "!javac % && java %:r"
end, {})
vim.api.nvim_create_user_command("JavaCompile", function()
vim.cmd "!javac %"
end, {})
end
-- Setup jdtls when a Java file is opened
M.setup_jdtls = function()
local status, jdtls = pcall(require, "jdtls")
if not status then
print "Failed to load JDTLS plugin"
return
end
-- Find root of project
local root_markers = { ".git", "mvnw", "gradlew", "pom.xml", "build.gradle" }
local root_dir = require("jdtls.setup").find_root(root_markers)
if not root_dir then
root_dir = vim.fn.getcwd()
end
-- Determine OS-specific config
local os_config
if vim.fn.has "mac" == 1 then
os_config = "config_mac"
elseif vim.fn.has "unix" == 1 then
os_config = "config_linux"
elseif vim.fn.has "win32" == 1 then
os_config = "config_win"
else
os_config = "config_linux"
end
-- Get mason paths
local mason_path = vim.fn.stdpath "data" .. "/mason"
local jdtls_path = mason_path .. "/packages/jdtls"
-- Check if launcher jar exists
local launcher_jar = vim.fn.glob(jdtls_path .. "/plugins/org.eclipse.equinox.launcher_*.jar")
if launcher_jar == "" then
print "JDTLS launcher jar not found"
return
end
-- Create workspace directory
local project_name = vim.fn.fnamemodify(root_dir, ":p:h:t")
local workspace_dir = vim.fn.expand "~/.cache/jdtls/workspace/" .. project_name
vim.fn.mkdir(workspace_dir, "p")
-- Get system Java
local java_cmd = "java"
local config = {
cmd = {
java_cmd,
"-Declipse.application=org.eclipse.jdt.ls.core.id1",
"-Dosgi.bundles.defaultStartLevel=4",
"-Declipse.product=org.eclipse.jdt.ls.core.product",
"-Dlog.protocol=true",
"-Dlog.level=ALL",
"-Xms1g",
"--add-modules=ALL-SYSTEM",
"--add-opens",
"java.base/java.util=ALL-UNNAMED",
"--add-opens",
"java.base/java.lang=ALL-UNNAMED",
"-jar",
launcher_jar,
"-configuration",
jdtls_path .. "/" .. os_config,
"-data",
workspace_dir,
},
root_dir = root_dir,
settings = {
java = {
signatureHelp = { enabled = true },
contentProvider = { preferred = "fernflower" },
completion = {
favoriteStaticMembers = {
"org.junit.jupiter.api.Assertions.*",
"java.util.Objects.requireNonNull",
"java.util.Objects.requireNonNullElse",
},
},
sources = {
organizeImports = {
starThreshold = 9999,
staticStarThreshold = 9999,
},
},
codeGeneration = {
toString = {
template = "${object.className}{${member.name()}=${member.value}, ${otherMembers}}",
},
useBlocks = true,
},
configuration = {
updateBuildConfiguration = "interactive",
},
},
},
capabilities = require("nvchad.configs.lspconfig").capabilities,
on_attach = require("nvchad.configs.lspconfig").on_attach,
init_options = {
bundles = {},
},
}
-- Print the commands being used (for debugging)
print("JDTLS launcher: " .. launcher_jar)
print("JDTLS config dir: " .. jdtls_path .. "/" .. os_config)
-- Start jdtls
jdtls.start_or_attach(config)
end
return M

47
lua/configs/lazy.lua Normal file
View File

@@ -0,0 +1,47 @@
return {
defaults = { lazy = true },
install = { colorscheme = { "nvchad" } },
ui = {
icons = {
ft = "",
lazy = "󰂠 ",
loaded = "",
not_loaded = "",
},
},
performance = {
rtp = {
disabled_plugins = {
"2html_plugin",
"tohtml",
"getscript",
"getscriptPlugin",
"gzip",
"logipat",
"netrw",
"netrwPlugin",
"netrwSettings",
"netrwFileHandlers",
"matchit",
"tar",
"tarPlugin",
"rrhelper",
"spellfile_plugin",
"vimball",
"vimballPlugin",
"zip",
"zipPlugin",
"tutor",
"rplugin",
"syntax",
"synmenu",
"optwin",
"compiler",
"bugreport",
"ftplugin",
},
},
},
}

226
lua/configs/lspconfig.lua Normal file
View File

@@ -0,0 +1,226 @@
local on_attach = require("nvchad.configs.lspconfig").on_attach
local capabilities = require("nvchad.configs.lspconfig").capabilities
local lspconfig = require("lspconfig")
-- List of servers to install and configure
local servers = {
"lua_ls",
"clangd",
"pyright",
"ts_ls", -- TypeScript/JavaScript
"html",
"cssls",
"emmet_ls",
"eslint",
}
-- Loop through servers and set them up
for _, lsp in ipairs(servers) do
lspconfig[lsp].setup({
on_attach = on_attach,
capabilities = capabilities,
})
end
-- C++ specific configuration
lspconfig.clangd.setup({
on_attach = on_attach,
capabilities = capabilities,
cmd = {
"clangd",
"--background-index",
"--suggest-missing-includes",
"--clang-tidy",
"--header-insertion=iwyu",
},
filetypes = { "c", "cpp", "objc", "objcpp" },
})
-- Python specific configuration
lspconfig.pyright.setup({
on_attach = on_attach,
capabilities = capabilities,
settings = {
pyright = {
autoImportCompletions = true,
typeCheckingMode = "basic", -- or "strict"
},
python = {
analysis = {
diagnosticSeverityOverrides = {
-- Customize diagnostic severity if needed
},
},
},
},
})
lspconfig.ts_ls.setup({
on_attach = on_attach,
capabilities = capabilities,
init_options = {
preferences = {
disableSuggestions = false,
},
},
settings = {
typescript = {
inlayHints = {
includeInlayParameterNameHints = "all",
includeInlayParameterNameHintsWhenArgumentMatchesName = false,
includeInlayFunctionParameterTypeHints = true,
includeInlayVariableTypeHints = true,
includeInlayPropertyDeclarationTypeHints = true,
includeInlayFunctionLikeReturnTypeHints = true,
includeInlayEnumMemberValueHints = true,
},
},
javascript = {
inlayHints = {
includeInlayParameterNameHints = "all",
includeInlayParameterNameHintsWhenArgumentMatchesName = false,
includeInlayFunctionParameterTypeHints = true,
includeInlayVariableTypeHints = true,
includeInlayPropertyDeclarationTypeHints = true,
includeInlayFunctionLikeReturnTypeHints = true,
includeInlayEnumMemberValueHints = true,
},
},
},
})
-- HTML configuration
lspconfig.html.setup({
on_attach = on_attach,
capabilities = capabilities,
filetypes = { "html", "htmldjango" },
})
-- CSS configuration
lspconfig.cssls.setup({
on_attach = on_attach,
capabilities = capabilities,
settings = {
css = {
validate = true,
lint = {
unknownAtRules = "ignore",
},
},
scss = {
validate = true,
lint = {
unknownAtRules = "ignore",
},
},
less = {
validate = true,
lint = {
unknownAtRules = "ignore",
},
},
},
})
-- Emmet configuration for HTML/CSS
lspconfig.emmet_ls.setup({
on_attach = on_attach,
capabilities = capabilities,
filetypes = { "html", "css", "scss", "javascript", "javascriptreact", "typescript", "typescriptreact" },
init_options = {
html = {
options = {
["bem.enabled"] = true,
},
},
},
})
-- ESLint configuration
lspconfig.eslint.setup({
on_attach = function(client, bufnr)
on_attach(client, bufnr)
-- Auto fix on save
vim.api.nvim_create_autocmd("BufWritePre", {
buffer = bufnr,
command = "EslintFixAll",
})
end,
capabilities = capabilities,
settings = {
codeAction = {
disableRuleComment = {
enable = true,
location = "separateLine",
},
showDocumentation = {
enable = true,
},
},
codeActionOnSave = {
enable = false,
mode = "all",
},
format = true,
nodePath = "",
onIgnoredFiles = "off",
packageManager = "npm",
quiet = false,
rulesCustomizations = {},
run = "onType",
useESLintClass = false,
validate = "on",
workingDirectory = {
mode = "location",
},
},
})
-- Configure tinymist (Typst LSP)
lspconfig.tinymist.setup({
cmd = { vim.fn.stdpath("data") .. "/mason/bin/tinymist" },
on_attach = on_attach,
capabilities = capabilities,
filetypes = { "typ", "typst" },
})
-- C# OmniSharp configuration - SINGLE CONFIGURATION
lspconfig.omnisharp.setup({
on_attach = function(client, bufnr)
on_attach(client, bufnr)
-- Set up C# specific keymaps
local opts = { noremap = true, silent = true, buffer = bufnr }
vim.keymap.set("n", "gd", require("omnisharp_extended").lsp_definitions, opts)
vim.keymap.set("n", "gr", require("omnisharp_extended").lsp_references, opts)
vim.keymap.set("n", "gi", require("omnisharp_extended").lsp_implementation, opts)
end,
capabilities = capabilities,
handlers = {
["textDocument/definition"] = require("omnisharp_extended").handler,
},
cmd = { "omnisharp", "--languageserver", "--hostPID", tostring(vim.fn.getpid()) },
root_dir = function(fname)
return require("lspconfig.util").root_pattern("*.sln", "*.csproj", "omnisharp.json", "function.json")(fname)
or require("lspconfig.util").find_git_ancestor(fname)
or vim.fn.getcwd()
end,
settings = {
FormattingOptions = {
EnableEditorConfigSupport = true,
OrganizeImports = true,
},
MsBuild = {
LoadProjectsOnDemand = false,
},
RoslynExtensionsOptions = {
EnableAnalyzersSupport = true,
EnableImportCompletion = true,
AnalyzeOpenDocumentsOnly = false,
},
Sdk = {
IncludePrereleases = true,
},
},
})

34
lua/configs/python.lua Normal file
View File

@@ -0,0 +1,34 @@
local M = {}
M.setup = function()
-- Python-specific settings
vim.opt.tabstop = 4
vim.opt.shiftwidth = 4
vim.opt.expandtab = true
-- Quick run and lint commands
vim.api.nvim_create_user_command("PythonRun", function()
vim.cmd("!python3 %")
end, {})
vim.api.nvim_create_user_command("PythonLint", function()
vim.cmd("!flake8 %")
end, {})
-- Optional: Virtual environment detection
local function activate_venv()
local venv_path = vim.fn.getcwd() .. "/venv/bin/activate"
if vim.fn.filereadable(venv_path) == 1 then
vim.env.VIRTUAL_ENV = venv_path
vim.cmd("source " .. venv_path)
end
end
-- Try to activate virtual environment when opening Python file
vim.api.nvim_create_autocmd("FileType", {
pattern = "python",
callback = activate_venv
})
end
return M

21
lua/configs/tinymist.lua Normal file
View File

@@ -0,0 +1,21 @@
local M = {}
M.setup = function()
local lspconfig = require("lspconfig")
lspconfig.tinymist.setup {
cmd = { vim.fn.stdpath("data") .. "/mason/bin/tinymist" },
on_attach = require("nvchad.configs.lspconfig").on_attach,
capabilities = require("nvchad.configs.lspconfig").capabilities,
filetypes = { "typ", "typst" },
settings = {
export = {
pdf = "onSave", -- or "onType", "never"
png = "never",
},
-- Other tinymist specific settings
},
}
end
return M

103
lua/configs/webdev.lua Normal file
View File

@@ -0,0 +1,103 @@
-- Create: lua/configs/webdev.lua
local M = {}
M.setup = function()
-- Web development settings
vim.api.nvim_create_autocmd("FileType", {
pattern = { "html", "css", "javascript", "typescript", "json" },
callback = function()
vim.opt_local.tabstop = 2
vim.opt_local.shiftwidth = 2
vim.opt_local.expandtab = true
vim.opt_local.softtabstop = 2
end,
})
-- Quick commands for web development
vim.api.nvim_create_user_command("NodeRun", function()
vim.cmd("!node %")
end, { desc = "Run current JavaScript file with Node.js" })
vim.api.nvim_create_user_command("LiveServer", function()
-- This assumes you have live-server installed globally
-- npm install -g live-server
vim.cmd("!live-server .")
end, { desc = "Start live server in current directory" })
-- HTML5 template insertion
vim.api.nvim_create_user_command("HTMLTemplate", function()
local template = {
"<!DOCTYPE html>",
"<html lang=\"en\">",
"<head>",
" <meta charset=\"UTF-8\">",
" <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">",
" <title>Document</title>",
"</head>",
"<body>",
" ",
"</body>",
"</html>"
}
vim.api.nvim_put(template, "l", true, true)
end, { desc = "Insert HTML5 template" })
-- React component template
vim.api.nvim_create_user_command("ReactComponent", function()
local filename = vim.fn.expand("%:t:r")
local component_name = filename:gsub("^%l", string.upper)
local template = {
"import React from 'react';",
"",
"const " .. component_name .. " = () => {",
" return (",
" <div>",
" <h1>" .. component_name .. "</h1>",
" </div>",
" );",
"};",
"",
"export default " .. component_name .. ";"
}
vim.api.nvim_put(template, "l", true, true)
end, { desc = "Insert React component template" })
-- Package.json quick commands
vim.api.nvim_create_user_command("NpmInit", function()
vim.cmd("!npm init -y")
end, { desc = "Initialize package.json" })
vim.api.nvim_create_user_command("NpmInstall", function()
vim.cmd("!npm install")
end, { desc = "Install npm dependencies" })
vim.api.nvim_create_user_command("NpmDev", function()
vim.cmd("!npm run dev")
end, { desc = "Run npm dev script" })
vim.api.nvim_create_user_command("NpmBuild", function()
vim.cmd("!npm run build")
end, { desc = "Run npm build script" })
-- Set up some useful keymaps for web development
vim.api.nvim_create_autocmd("FileType", {
pattern = { "html", "css", "javascript", "typescript", "javascriptreact", "typescriptreact" },
callback = function()
local opts = { noremap = true, silent = true, buffer = true }
-- Console.log snippet for JS/TS files
if vim.bo.filetype == "javascript" or vim.bo.filetype == "typescript" then
vim.keymap.set("n", "<leader>cl", "oconsole.log();<Esc>hi", opts)
vim.keymap.set("i", "clog", "console.log();<Esc>hi", opts)
end
-- Quick tag closing for HTML
if vim.bo.filetype == "html" then
vim.keymap.set("i", ">>", "></<C-x><C-o>", opts)
end
end,
})
end
return M