summaryrefslogtreecommitdiff
path: root/ar/.config/NvChad/lua/custom/configs
diff options
context:
space:
mode:
authorTheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com>2025-01-24 20:35:27 +0900
committerTheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com>2025-01-24 20:35:27 +0900
commitc80a54e42b52ce297f0f2f71af23c562832025c7 (patch)
treedcce8bb977a770f473325d48f6f70b21d9818a40 /ar/.config/NvChad/lua/custom/configs
init
Diffstat (limited to 'ar/.config/NvChad/lua/custom/configs')
-rw-r--r--ar/.config/NvChad/lua/custom/configs/cell_marker.lua159
-rw-r--r--ar/.config/NvChad/lua/custom/configs/dadbod.lua29
-rw-r--r--ar/.config/NvChad/lua/custom/configs/lspconfig.lua71
-rw-r--r--ar/.config/NvChad/lua/custom/configs/null-ls.lua45
-rw-r--r--ar/.config/NvChad/lua/custom/configs/overrides.lua247
5 files changed, 551 insertions, 0 deletions
diff --git a/ar/.config/NvChad/lua/custom/configs/cell_marker.lua b/ar/.config/NvChad/lua/custom/configs/cell_marker.lua
new file mode 100644
index 0000000..1d71dfb
--- /dev/null
+++ b/ar/.config/NvChad/lua/custom/configs/cell_marker.lua
@@ -0,0 +1,159 @@
+local M = {}
+
+M.get_commenter = function()
+ local commenter = { python = "# ", lua = "-- ", julia = "# ", fennel = ";; ", scala = "// ", r = "# " }
+ local bufnr = vim.api.nvim_get_current_buf()
+ local ft = vim.api.nvim_buf_get_option(bufnr, "filetype")
+ if ft == nil or ft == "" then
+ return commenter["python"]
+ elseif commenter[ft] == nil then
+ return commenter["python"]
+ end
+
+ return commenter[ft]
+end
+
+local CELL_MARKER = M.get_commenter() .. "%%"
+vim.api.nvim_set_hl(0, "CellMarkerHl", { default = true, bg = "#c5c5c5", fg = "#111111" })
+
+M.miniai_spec = function(mode)
+ local start_line = vim.fn.search("^" .. CELL_MARKER, "bcnW")
+
+ if start_line == 0 then
+ start_line = 1
+ else
+ if mode == "i" then
+ start_line = start_line + 1
+ end
+ end
+
+ local end_line = vim.fn.search("^" .. CELL_MARKER, "nW") - 1
+ if end_line == -1 then
+ end_line = vim.fn.line "$"
+ end
+
+ local last_col = math.max(vim.fn.getline(end_line):len(), 1)
+
+ local from = { line = start_line, col = 1 }
+ local to = { line = end_line, col = last_col }
+
+ return { from = from, to = to }
+end
+
+M.show_cell_markers = function()
+ require("mini.hipatterns").enable(0, {
+ highlighters = {
+ marker = { pattern = "^" .. M.get_commenter() .. "%%%%", group = "CellMarkerHl" },
+ },
+ })
+end
+
+M.select_cell = function()
+ local bufnr = vim.api.nvim_get_current_buf()
+ local current_row = vim.api.nvim_win_get_cursor(0)[1]
+ local current_col = vim.api.nvim_win_get_cursor(0)[2]
+
+ local start_line = nil
+ local end_line = nil
+
+ for line = current_row, 1, -1 do
+ local line_content = vim.api.nvim_buf_get_lines(bufnr, line - 1, line, false)[1]
+ if line_content:find("^" .. CELL_MARKER) then
+ start_line = line
+ break
+ end
+ end
+ local line_count = vim.api.nvim_buf_line_count(bufnr)
+ for line = current_row + 1, line_count do
+ local line_content = vim.api.nvim_buf_get_lines(bufnr, line - 1, line, false)[1]
+ if line_content:find("^" .. CELL_MARKER) then
+ end_line = line
+ break
+ end
+ end
+
+ if not start_line then
+ start_line = 1
+ end
+ if not end_line then
+ end_line = line_count
+ end
+ return current_row, current_col, start_line, end_line
+end
+
+M.execute_cell = function()
+ local current_row, current_col, start_line, end_line = M.select_cell()
+ if start_line and end_line then
+ vim.fn.setpos("'<", { 0, start_line + 1, 0, 0 })
+ vim.fn.setpos("'>", { 0, end_line - 1, 0, 0 })
+ require("iron.core").visual_send()
+ vim.api.nvim_win_set_cursor(0, { current_row, current_col })
+ end
+end
+
+M.delete_cell = function()
+ local _, _, start_line, end_line = M.select_cell()
+ if start_line and end_line then
+ local rows_to_select = end_line - start_line - 1
+ vim.api.nvim_win_set_cursor(0, { start_line, 0 })
+ vim.cmd("normal!V " .. rows_to_select .. "j")
+ vim.cmd "normal!d"
+ vim.cmd "normal!k"
+ end
+end
+
+M.navigate_cell = function(up)
+ local is_up = up or false
+ local _, _, start_line, end_line = M.select_cell()
+ if is_up and start_line ~= 1 then
+ vim.api.nvim_win_set_cursor(0, { start_line - 1, 0 })
+ elseif end_line then
+ local bufnr = vim.api.nvim_get_current_buf()
+ local line_count = vim.api.nvim_buf_line_count(bufnr)
+ if end_line ~= line_count then
+ vim.api.nvim_win_set_cursor(0, { end_line + 1, 0 })
+ _, _, start_line, end_line = M.select_cell()
+ vim.api.nvim_win_set_cursor(0, { end_line - 1, 0 })
+ end
+ end
+end
+
+M.move_cell = function(dir)
+ local search_res
+ local result
+ if dir == "d" then
+ search_res = vim.fn.search("^" .. CELL_MARKER, "W")
+ if search_res == 0 then
+ result = "last"
+ end
+ else
+ search_res = vim.fn.search("^" .. CELL_MARKER, "bW")
+ if search_res == 0 then
+ result = "first"
+ vim.api.nvim_win_set_cursor(0, { 1, 0 })
+ end
+ end
+
+ return result
+end
+
+M.insert_cell_before = function(content)
+ content = content or CELL_MARKER
+ local cell_object = M.miniai_spec "a"
+ vim.api.nvim_buf_set_lines(0, cell_object.from.line - 1, cell_object.from.line - 1, false, { content, "" })
+ M.move_cell "u"
+end
+
+M.insert_cell_after = function(content)
+ content = content or CELL_MARKER
+ vim.print(content)
+ local cell_object = M.miniai_spec "a"
+ vim.api.nvim_buf_set_lines(0, cell_object.to.line, cell_object.to.line, false, { content, "" })
+ M.move_cell "d"
+end
+
+M.insert_markdown_cell = function()
+ M.insert_cell_after(CELL_MARKER .. " [markdown]")
+end
+
+return M
diff --git a/ar/.config/NvChad/lua/custom/configs/dadbod.lua b/ar/.config/NvChad/lua/custom/configs/dadbod.lua
new file mode 100644
index 0000000..90c13fb
--- /dev/null
+++ b/ar/.config/NvChad/lua/custom/configs/dadbod.lua
@@ -0,0 +1,29 @@
+local M = {}
+
+local function db_completion()
+ require("cmp").setup.buffer { sources = { { name = "vim-dadbod-completion" } } }
+end
+
+function M.setup()
+ vim.g.db_ui_save_location = vim.fn.stdpath "config" .. require("plenary.path").path.sep .. "db_ui"
+
+ vim.api.nvim_create_autocmd("FileType", {
+ pattern = {
+ "sql",
+ },
+ command = [[setlocal omnifunc=vim_dadbod_completion#omni]],
+ })
+
+ vim.api.nvim_create_autocmd("FileType", {
+ pattern = {
+ "sql",
+ "mysql",
+ "plsql",
+ },
+ callback = function()
+ vim.schedule(db_completion)
+ end,
+ })
+end
+
+return M
diff --git a/ar/.config/NvChad/lua/custom/configs/lspconfig.lua b/ar/.config/NvChad/lua/custom/configs/lspconfig.lua
new file mode 100644
index 0000000..c4fd1db
--- /dev/null
+++ b/ar/.config/NvChad/lua/custom/configs/lspconfig.lua
@@ -0,0 +1,71 @@
+local on_attach = require("plugins.configs.lspconfig").on_attach
+local capabilities = require("plugins.configs.lspconfig").capabilities
+
+local lspconfig = require "lspconfig"
+
+-- if you just want default config for the servers then put them in a table
+local servers = { "clangd", "cssls", "emmet_language_server", "html", "julials", "sqlls", "tsserver" }
+
+for _, lsp in ipairs(servers) do
+ lspconfig[lsp].setup {
+ on_attach = on_attach,
+ capabilities = capabilities,
+ }
+end
+
+--
+-- lspconfig.pyright.setup { blabla}
+local on_attach_qmd = 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
+
+ buf_set_option("omnifunc", "v:lua.vim.lsp.omnifunc")
+ local opts = { noremap = true, silent = true }
+end
+
+local lsp_flags = {
+ allow_incremental_sync = true,
+ debounce_text_changes = 150,
+}
+
+local cmp_nvim_lsp = require "cmp_nvim_lsp"
+local util = require "lspconfig.util"
+
+lspconfig.marksman.setup {
+ on_attach = on_attach_qmd,
+ capabilities = capabilities,
+ filetypes = { "markdown", "quarto" },
+ root_dir = util.root_pattern(".git", ".marksman.toml", "_quarto.yml"),
+}
+
+-- lspconfig.r_language_server.setup {
+-- on_attach = on_attach,
+-- capabilities = capabilities,
+-- flags = lsp_flags,
+-- settings = {
+-- r = {
+-- lsp = {
+-- rich_documentation = false,
+-- },
+-- },
+-- },
+-- }
+
+lspconfig.yamlls.setup {
+ on_attach = on_attach,
+ capabilities = capabilities,
+ flags = lsp_flags,
+ settings = {
+ yaml = {
+ schemas = {
+ -- add custom schemas here
+ -- e.g.
+ ["https://raw.githubusercontent.com/hits-mbm-dev/kimmdy/main/src/kimmdy/kimmdy-yaml-schema.json"] = "kimmdy.yml",
+ },
+ },
+ },
+}
diff --git a/ar/.config/NvChad/lua/custom/configs/null-ls.lua b/ar/.config/NvChad/lua/custom/configs/null-ls.lua
new file mode 100644
index 0000000..d703736
--- /dev/null
+++ b/ar/.config/NvChad/lua/custom/configs/null-ls.lua
@@ -0,0 +1,45 @@
+local null_ls = require "null-ls"
+local augroup = vim.api.nvim_create_augroup("LspFormatting", {})
+
+local b = null_ls.builtins
+
+local sources = {
+ -- cpp
+ b.formatting.clang_format,
+
+ -- Lua
+ b.formatting.stylua,
+
+ -- python
+ b.code_actions.refactoring,
+ b.diagnostics.mypy,
+ b.diagnostics.ruff,
+ b.diagnostics.vulture,
+ b.formatting.black,
+ -- b.formatting.pyflyby,
+ -- b.formatting.reorder_python_imports,
+
+ -- webdev stuff
+ b.formatting.deno_fmt, -- choosed deno for ts/js files cuz its very fast!
+ b.formatting.prettier.with { filetypes = { "html", "markdown", "css" } }, -- so prettier works only on these filetypes
+}
+
+null_ls.setup {
+ debug = true,
+ sources = sources,
+ on_attach = function(client, bufnr)
+ if client.supports_method "textDocument/formatting" then
+ vim.api.nvim_clear_autocmds {
+ group = augroup,
+ buffer = bufnr,
+ }
+ vim.api.nvim_create_autocmd("BufWritePre", {
+ group = augroup,
+ buffer = bufnr,
+ callback = function()
+ vim.lsp.buf.format { bufnr = bufnr }
+ end,
+ })
+ end
+ end,
+}
diff --git a/ar/.config/NvChad/lua/custom/configs/overrides.lua b/ar/.config/NvChad/lua/custom/configs/overrides.lua
new file mode 100644
index 0000000..13a0aa1
--- /dev/null
+++ b/ar/.config/NvChad/lua/custom/configs/overrides.lua
@@ -0,0 +1,247 @@
+local M = {}
+
+M.blankline = {
+ -- show_trailing_blankline_indent = true,
+ -- show_first_indent_level = true,
+ context_patterns = {
+ "block",
+ "else_clause",
+ "catch_clause",
+ "class",
+ "function",
+ "import_statement",
+ "jsx_element",
+ "jsx_self_closing_element",
+ "method",
+ "return",
+ "try_statement",
+ "^for",
+ "^if",
+ "^object",
+ "^table",
+ "^while",
+ },
+}
+
+M.treesitter = {
+ dependencies = {
+ "nvim-treesitter/nvim-treesitter-textobjects",
+ "nvim-treesitter/nvim-treesitter-context",
+ },
+
+ ensure_installed = {
+ "bash",
+ "c",
+ "css",
+ "html",
+ "javascript",
+ "julia",
+ "latex",
+ "lua",
+ "markdown",
+ "markdown_inline",
+ "python",
+ "query",
+ -- "r",
+ "scala",
+ "tsx",
+ "typescript",
+ "vim",
+ "vimdoc",
+ "yaml",
+ },
+
+ highlight = { enable = true },
+
+ indent = {
+ enable = true,
+ -- disable = {
+ -- "python"
+ -- },
+ },
+}
+
+M.mason = {
+ ensure_installed = {
+ -- c/cpp stuff
+ "clangd",
+ "clang-format",
+
+ -- julia
+ "julia-lsp",
+
+ -- lua stuff
+ "lua-language-server",
+ "stylua",
+
+ -- markdown
+ "markdownlint",
+ "markdown-toc",
+ "marksman",
+
+ -- -- python
+ "black",
+ "debugpy",
+ "mypy",
+ "ruff",
+ "pyright",
+ "vulture",
+
+ -- R
+ -- "r-languageserver",
+
+ -- -- solidity
+ -- "solidity",
+
+ -- SQL
+ "sqlls",
+ "sqlfluff",
+ "sql-formatter",
+
+ -- web dev stuff
+ "css-lsp",
+ "html-lsp",
+ "typescript-language-server",
+ "deno",
+ "prettier",
+ },
+}
+
+-- git support in nvimtree
+M.nvimtree = {
+ git = {
+ enable = true,
+ },
+
+ renderer = {
+ highlight_git = true,
+ icons = {
+ show = {
+ git = true,
+ },
+ },
+ },
+}
+
+M.cmp = {
+ branch = "main",
+ dependencies = {
+ "hrsh7th/cmp-nvim-lsp-signature-help",
+ "hrsh7th/cmp-calc",
+ "hrsh7th/cmp-emoji",
+ "f3fora/cmp-spell",
+ "ray-x/cmp-treesitter",
+ "kdheepak/cmp-latex-symbols",
+ "jmbuhr/cmp-pandoc-references",
+ "rafamadriz/friendly-snippets",
+ "onsails/lspkind-nvim",
+ },
+ config = function()
+ local cmp = require "cmp"
+ local luasnip = require "luasnip"
+ local lspkind = require "lspkind"
+ lspkind.init()
+
+ local has_words_before = function()
+ local line, col = unpack(vim.api.nvim_win_get_cursor(0))
+ return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match "%s" == nil
+ end
+
+ cmp.setup {
+ snippet = {
+ expand = function(args)
+ luasnip.lsp_expand(args.body)
+ end,
+ },
+ mapping = {
+ ["<C-f>"] = cmp.mapping.scroll_docs(-4),
+ ["<C-b>"] = cmp.mapping.scroll_docs(4),
+ ["<C-m>"] = cmp.mapping(function(fallback)
+ if luasnip.expand_or_jumpable() then
+ luasnip.expand_or_jump()
+ fallback()
+ end
+ end, { "i", "s" }),
+ ["<C-p>"] = cmp.mapping(function(fallback)
+ if luasnip.jumpable(-1) then
+ luasnip.jump(-1)
+ else
+ fallback()
+ end
+ end, { "i", "s" }),
+ ["<C-e>"] = cmp.mapping.abort(),
+ ["<CR>"] = cmp.mapping.confirm {
+ select = true,
+ },
+ ["<Tab><Tab>"] = cmp.mapping(function(fallback)
+ if cmp.visible() then
+ cmp.select_next_item()
+ elseif has_words_before() then
+ cmp.complete()
+ else
+ fallback()
+ end
+ end, { "i", "s" }),
+ ["<S-Tab><S-Tab>"] = cmp.mapping(function(fallback)
+ if cmp.visible() then
+ cmp.select_prev_item()
+ else
+ fallback()
+ end
+ end, { "i", "s" }),
+ },
+ autocomplete = false,
+ formatting = {
+ format = lspkind.cmp_format {
+ with_text = true,
+ menu = {
+ otter = "[🦦]",
+ nvim_lsp = "[LSP]",
+ luasnip = "[snip]",
+ buffer = "[buf]",
+ path = "[path]",
+ spell = "[spell]",
+ pandoc_references = "[ref]",
+ tags = "[tag]",
+ treesitter = "[TS]",
+ calc = "[calc]",
+ latex_symbols = "[tex]",
+ emoji = "[emoji]",
+ },
+ },
+ },
+ sources = {
+ { name = "otter" }, -- for code chunks in quarto
+ { name = "path" },
+ { name = "nvim_lsp" },
+ { name = "nvim_lsp_signature_help" },
+ { name = "luasnip", keyword_length = 3, max_item_count = 3 },
+ { name = "pandoc_references" },
+ { name = "buffer", keyword_length = 5, max_item_count = 3 },
+ { name = "spell" },
+ { name = "treesitter", keyword_length = 5, max_item_count = 3 },
+ { name = "calc" },
+ { name = "latex_symbols" },
+ { name = "emoji" },
+ },
+ view = {
+ entries = "native",
+ },
+ window = {
+ documentation = {
+ border = require("misc.style").border,
+ },
+ },
+ }
+
+ -- for friendly snippets
+ require("luasnip.loaders.from_vscode").lazy_load()
+ -- for custom snippets
+ require("luasnip.loaders.from_vscode").lazy_load { paths = { vim.fn.stdpath "config" .. "/snips" } }
+ -- link quarto and rmarkdown to markdown snippets
+ luasnip.filetype_extend("quarto", { "markdown" })
+ luasnip.filetype_extend("rmarkdown", { "markdown" })
+ end,
+}
+
+return M