diff --git a/.gitignore b/.gitignore index 3819313..3cf9da1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *.swp *.swo +.netrwhist diff --git a/nvim/after/ftplugin/go.lua b/nvim/after/ftplugin/go.lua index 7e13d97..0c1c3a0 100644 --- a/nvim/after/ftplugin/go.lua +++ b/nvim/after/ftplugin/go.lua @@ -1 +1 @@ -vim.cmd [[autocmd BufWritePre * lua vim.lsp.buf.format()]] +vim.cmd [[autocmd BufWritePre *.go lua vim.lsp.buf.format()]] diff --git a/nvim/after/ftplugin/javascriptreact.lua b/nvim/after/ftplugin/javascriptreact.lua new file mode 100644 index 0000000..b255580 --- /dev/null +++ b/nvim/after/ftplugin/javascriptreact.lua @@ -0,0 +1,14 @@ + vim.opt_local.tabstop = 2 + vim.opt_local.shiftwidth = 2 + vim.opt_local.softtabstop = 2 + vim.opt_local.expandtab = true +-- vim.api.nvim_create_autocmd("FileType", { +-- pattern = { "javascript", "javascriptreact" }, +-- callback = function() +-- -- Your JS/JSX settings here +-- vim.bo.tabstop = 2 +-- vim.bo.shiftwidth = 2 +-- vim.bo.softtabstop = 2 +-- vim.bo.expandtab = true +-- end +-- }) diff --git a/nvim/after/ftplugin/json.lua b/nvim/after/ftplugin/json.lua new file mode 100644 index 0000000..9f7e996 --- /dev/null +++ b/nvim/after/ftplugin/json.lua @@ -0,0 +1,7 @@ +vim.api.nvim_create_autocmd("BufWritePre", { + pattern = "*.json", + callback = function() + -- vim.cmd([[%!jq . 2>/dev/null || cat]]) + vim.cmd([[%!jq . ]]) + end, +}) diff --git a/nvim/after/ftplugin/nix.lua b/nvim/after/ftplugin/nix.lua new file mode 100644 index 0000000..45a6d74 --- /dev/null +++ b/nvim/after/ftplugin/nix.lua @@ -0,0 +1,4 @@ +vim.opt_local.tabstop = 2 +vim.opt_local.shiftwidth = 2 +vim.opt_local.softtabstop = 2 +vim.opt_local.expandtab = true diff --git a/nvim/lazy-lock.json b/nvim/lazy-lock.json index 53c440b..014530f 100644 --- a/nvim/lazy-lock.json +++ b/nvim/lazy-lock.json @@ -1,20 +1,19 @@ { - "LuaSnip": { "branch": "master", "commit": "c9b9a22904c97d0eb69ccb9bab76037838326817" }, - "cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" }, - "cmp-nvim-lsp": { "branch": "main", "commit": "99290b3ec1322070bcfb9e846450a46f6efa50f0" }, - "cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" }, - "codecompanion.nvim": { "branch": "main", "commit": "1b1bfc71f426a50ece54489078f5afe82b0af90c" }, + "LuaSnip": { "branch": "master", "commit": "21f74f7ba8c49f95f9d7c8293b147c2901dd2d3a" }, + "avante.nvim": { "branch": "main", "commit": "e89eb79abf5754645e20aa6074da10ed20bba33c" }, + "cmp-buffer": { "branch": "main", "commit": "b74fab3656eea9de20a9b8116afa3cfc4ec09657" }, + "cmp-nvim-lsp": { "branch": "main", "commit": "bd5a7d6db125d4654b50eeae9f5217f24bb22fd3" }, + "cmp-path": { "branch": "main", "commit": "c642487086dbd9a93160e1679a1327be111cbc25" }, + "fzf-lua": { "branch": "main", "commit": "a8458b79a957a6e3e217d84106a0fd4b9470ff4c" }, "github-theme": { "branch": "main", "commit": "c106c9472154d6b2c74b74565616b877ae8ed31d" }, - "gitsigns.nvim": { "branch": "main", "commit": "011dc6718bcebdf92a5336bb0da79189c3afe621" }, - "lazy.nvim": { "branch": "main", "commit": "6c3bda4aca61a13a9c63f1c1d1b16b9d3be90d7a" }, - "mason-lspconfig.nvim": { "branch": "main", "commit": "1a31f824b9cd5bc6f342fc29e9a53b60d74af245" }, - "mason.nvim": { "branch": "main", "commit": "fc98833b6da5de5a9c5b1446ac541577059555be" }, - "nvim-cmp": { "branch": "main", "commit": "c27370703e798666486e3064b64d59eaf4bdc6d5" }, - "nvim-lspconfig": { "branch": "master", "commit": "fd26f8626c03b424f7140d454031d1dcb8d23513" }, - "nvim-treesitter": { "branch": "master", "commit": "684eeac91ed8e297685a97ef70031d19ac1de25a" }, - "outline.nvim": { "branch": "main", "commit": "ae473fb51b7b6086de0876328c81a63f9c3ecfef" }, - "plenary.nvim": { "branch": "master", "commit": "857c5ac632080dba10aae49dba902ce3abf91b35" }, - "telescope-file-browser.nvim": { "branch": "master", "commit": "626998e5c1b71c130d8bc6cf7abb6709b98287bb" }, - "telescope.nvim": { "branch": "master", "commit": "814f102cd1da3dc78c7d2f20f2ef3ed3cdf0e6e4" }, - "which-key.nvim": { "branch": "main", "commit": "370ec46f710e058c9c1646273e6b225acf47cbed" } + "lazy.nvim": { "branch": "main", "commit": "f0f5bbb9e5bfae5e6468f9359ffea3d151418176" }, + "mason-lspconfig.nvim": { "branch": "main", "commit": "3590d66effccc7376d8c3dbe45e8291f9fed2843" }, + "mason.nvim": { "branch": "main", "commit": "ad7146aa61dcaeb54fa900144d768f040090bff0" }, + "nui.nvim": { "branch": "main", "commit": "de740991c12411b663994b2860f1a4fd0937c130" }, + "nvim-cmp": { "branch": "main", "commit": "a7bcf1d88069fc67c9ace8a62ba480b8fe879025" }, + "outline.nvim": { "branch": "main", "commit": "6b62f73a6bf317531d15a7ae1b724e85485d8148" }, + "plenary.nvim": { "branch": "master", "commit": "b9fd5226c2f76c951fc8ed5923d85e4de065e509" }, + "telescope-file-browser.nvim": { "branch": "master", "commit": "3610dc7dc91f06aa98b11dca5cc30dfa98626b7e" }, + "telescope.nvim": { "branch": "master", "commit": "b4da76be54691e854d3e0e02c36b0245f945c2c7" }, + "which-key.nvim": { "branch": "main", "commit": "3aab2147e74890957785941f0c1ad87d0a44c15a" } } diff --git a/nvim/lsp/basedpyright.lua b/nvim/lsp/basedpyright.lua new file mode 100644 index 0000000..25796bc --- /dev/null +++ b/nvim/lsp/basedpyright.lua @@ -0,0 +1,25 @@ +return { + cmd = { 'basedpyright-langserver', '--stdio' }, + filetypes = { 'python' }, + root_markers = { + 'pyrightconfig.json', + 'ya.make', + 'pyproject.toml', + 'setup.py', + 'setup.cfg', + 'requirements.txt', + 'Pipfile', + '.git', + }, + settings = { + python = { + analysis = { + autoSearchPaths = false, + useLibraryCodeForTypes = true, + diagnosticMode = 'openFilesOnly', + include = { + } + }, + }, + }, +} diff --git a/nvim/lsp/bashls.lua b/nvim/lsp/bashls.lua new file mode 100644 index 0000000..612caae --- /dev/null +++ b/nvim/lsp/bashls.lua @@ -0,0 +1,25 @@ +return { + cmd = { 'bash-language-server', 'start' }, + filetypes = { 'bash', 'sh', 'zsh' }, + root_markers = { '.git', vim.uv.cwd() }, + settings = { + bashIde = { + globPattern = vim.env.GLOB_PATTERN or '*@(.sh|.inc|.bash|.command)', + -- Modern formatting options (requires shfmt) + tabSize = 2, + insertSpaces = true, + -- Enable comprehensive features like Ruby LSP + enableSourceErrorDiagnostics = true, + enableCodeLens = true, + includeAllWorkspaceSymbols = true, + -- Background analysis for better performance + backgroundAnalysisMaxFiles = 500, + -- ShellCheck integration for linting + shellcheckPath = 'shellcheck', + shellcheckArguments = { + '--shell=bash', + '--format=json', + }, + }, + }, +} diff --git a/nvim/lsp/gopls.lua b/nvim/lsp/gopls.lua new file mode 100644 index 0000000..8a60d91 --- /dev/null +++ b/nvim/lsp/gopls.lua @@ -0,0 +1,20 @@ +return { + cmd = { "/home/dmchumak/.ya/tools/v3/gopls-linux/gopls" }, + filetypes = { "go", "gotempl", "gowork", "gomod" }, + root_markers = { "ya.make", "YAOWNERS", ".arcadia.root", ".cloudia.root", "go.work", "go.mod", ".git" }, + -- settings = { + -- gopls = { + -- completeUnimported = true, + -- usePlaceholders = true, + -- analyses = { + -- unusedparams = true, + -- }, + -- ["ui.inlayhint.hints"] = { + -- compositeLiteralFields = true, + -- constantValues = true, + -- parameterNames = true, + -- rangeVariableTypes = true, + -- }, + -- }, + -- }, +} diff --git a/nvim/lsp/lua_ls.lua b/nvim/lsp/lua_ls.lua new file mode 100644 index 0000000..cdef273 --- /dev/null +++ b/nvim/lsp/lua_ls.lua @@ -0,0 +1,33 @@ +return { + cmd = { "lua-language-server" }, + root_markers = { ".luarc.json", ".git", "init.lua" }, + filetypes = { "lua" }, + settings = { + Lua = { + format = { + enable = true, + defaultConfig = { + indent_style = "space", + indent_size = "2", + } + }, + runtime = { + -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) + version = "LuaJIT", + }, + diagnostics = { + -- Get the language server to recognize the `vim` global + globals = { "vim" }, + }, + workspace = { + -- Make the server aware of Neovim runtime files + library = vim.api.nvim_get_runtime_file("", true), + }, + -- Do not send telemetry data containing a randomized but unique identifier + telemetry = { + enable = false, + }, + } + } +} + diff --git a/nvim/lsp/starpls.lua b/nvim/lsp/starpls.lua new file mode 100644 index 0000000..33c748b --- /dev/null +++ b/nvim/lsp/starpls.lua @@ -0,0 +1,5 @@ +return { + cmd = { 'starpls' }, + filetypes = { 'starlark' }, + root_markers = { 'WORKSPACE' }, +} diff --git a/nvim/lua/lsp-config.lua b/nvim/lua/lsp-config.lua index d9e7506..bb3f704 100644 --- a/nvim/lua/lsp-config.lua +++ b/nvim/lua/lsp-config.lua @@ -3,58 +3,56 @@ require("mason-lspconfig").setup({ ensure_installed = { 'lua_ls', 'gopls', - 'bashls', - 'pyright', + 'bashls', -- install "shfmt" binary for formatting capabilities + 'basedpyright', }, automatic_installation = true, + automatic_enable = false }) --- Customized on_attach function --- See `:help vim.diagnostic.*` for documentation on any of the below functions --- local opts = { noremap = true, silent = true } -vim.keymap.set("n", "e", vim.diagnostic.open_float, opts) -vim.keymap.set("n", "[d", vim.diagnostic.goto_prev, opts) -vim.keymap.set("n", "]d", vim.diagnostic.goto_next, opts) -vim.keymap.set("n", "q", vim.diagnostic.setloclist, opts) +local keymap = vim.keymap.set -local on_attach = function(client, bufnr) - -- Enable completion triggered by - vim.api.nvim_buf_set_option(bufnr, "omnifunc", "v:lua.vim.lsp.omnifunc") +vim.api.nvim_create_autocmd("LspAttach", { + callback = function(ev) + local bufnr = ev.buf + local bufopts = { noremap = true, silent = true, buffer = bufnr } - if client.name == "rust_analyzer" then - -- This requires Neovim 0.10 or later - vim.lsp.inlay_hint.enable() + local client = vim.lsp.get_client_by_id(ev.data.client_id) + if not client then + return + end + + local lsp = vim.lsp + local function opt(desc, others) + return vim.tbl_extend("force", bufopts, { desc = desc }, others or {}) + end + + -- See `:help vim.lsp.*` for documentation on any of the below functions + keymap("n", "gD", lsp.buf.declaration, opt('[G]o to [d]eclaration')) + keymap("n", "gd", lsp.buf.definition, opt("[G]o to [d]efinition")) + keymap("n", "D", lsp.buf.type_definition, opt("Go to Type [D]efinition")) + keymap("n", "K", lsp.buf.hover, bufopts) + keymap("n", "gi", lsp.buf.implementation, opt("[G]o to [i]mplementation")) + keymap("n", "gr", require'telescope.builtin'.lsp_references, opt("[G]o to [r]eferences")) + keymap("n", "", lsp.buf.signature_help, bufopts) + keymap("n", "wa", lsp.buf.add_workspace_folder, bufopts) + keymap("n", "wr", lsp.buf.remove_workspace_folder, bufopts) + keymap("n", "wl", function() + print(vim.inspect(lsp.buf.list_workspace_folders())) + end, bufopts) + keymap("n", "rn", lsp.buf.rename, opt("[l]sp [R]ename")) + keymap("n", "lc", lsp.buf.code_action, opt("[l]sp [C]ode Action")) + keymap("n", "lf", function() + lsp.buf.format({ + async = true, + }) + end, opt("[l]sp [f]ormat buffer")) end - - -- See `:help vim.lsp.*` for documentation on any of the below functions - local bufopts = { noremap = true, silent = true, buffer = bufnr } - vim.keymap.set("n", "gD", vim.lsp.buf.declaration, Append(bufopts, "desc", 'Go to declaration')) - vim.keymap.set("n", "gd", vim.lsp.buf.definition, Append(bufopts, "desc", "Go to definition")) - vim.keymap.set("n", "K", vim.lsp.buf.hover, bufopts) - vim.keymap.set("n", "gi", vim.lsp.buf.implementation, Append(bufopts, "desc", "Go to implementation")) - vim.keymap.set("n", "gr", require'telescope.builtin'.lsp_references, Append(bufopts, "desc", "Go to references")) - vim.keymap.set("n", "", vim.lsp.buf.signature_help, bufopts) - vim.keymap.set("n", "wa", vim.lsp.buf.add_workspace_folder, bufopts) - vim.keymap.set("n", "wr", vim.lsp.buf.remove_workspace_folder, bufopts) - vim.keymap.set("n", "wl", function() - print(vim.inspect(vim.lsp.buf.list_workspace_folders())) - end, bufopts) - vim.keymap.set("n", "D", vim.lsp.buf.type_definition, bufopts) - vim.keymap.set("n", "rn", vim.lsp.buf.rename, bufopts) - vim.keymap.set("n", "ca", vim.lsp.buf.code_action, bufopts) - vim.keymap.set("n", "lf", function() - vim.lsp.buf.format({ - async = true, - }) - end, bufopts) -end +}) -- Add the border on hover and on signature help popup window -local handlers = { - ['textDocument/hover'] = vim.lsp.with(vim.lsp.handlers.hover, { border = "rounded" }), - ['textDocument/signatureHelp'] = vim.lsp.with(vim.lsp.handlers.signature_help, { border = "rounded" }), -} +vim.o.winborder = 'rounded' -- Add border to the diagnostic popup window vim.diagnostic.config({ @@ -65,76 +63,14 @@ vim.diagnostic.config({ underline = true, update_in_insert = false, -- Don't update diagnostics in insert mode severity_sort = true, -- Sort diagnostics by severity - float = { border = "rounded" }, + jump = { float = true }, }) -local capabilities = require('cmp_nvim_lsp').default_capabilities() +keymap("n", "e", vim.diagnostic.open_float, opts) +keymap("n", "q", vim.diagnostic.setloclist, opts) -require("lspconfig").lua_ls.setup({ - on_attach = on_attach, - settings = { - Lua = { - format = { - enable = true, - defaultConfig = { - indent_style = "space", - indent_size = "2", - } - }, - runtime = { - -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) - version = "LuaJIT", - }, - diagnostics = { - -- Get the language server to recognize the `vim` global - globals = { "vim" }, - }, - workspace = { - -- Make the server aware of Neovim runtime files - library = vim.api.nvim_get_runtime_file("", true), - }, - -- Do not send telemetry data containing a randomized but unique identifier - telemetry = { - enable = false, - }, - } - }, - capabilities = capabilities, - handlers = handlers -}) -require("lspconfig").gopls.setup { capabilities = capabilities, handlers = handlers, on_attach = on_attach, - cmd = IsYandex and { "/home/dmchumak/.ya/tools/v3/gopls-linux/gopls" }, - root_dir = IsYandex and require('lspconfig').util.root_pattern("YAOWNERS", "ya.make", ".arcadia.root", ".cloudia.root", "go.work", "go.mod", ".git"), - -- settings = { - -- gopls = { - -- arcadiaIndexDirs = { - -- "/home/horseinthesky/bl/cloud-go/cloud/cloud-go/cloudgate", - -- }, - -- }, - -- }, -} -require("lspconfig").bashls.setup { capabilities = capabilities, handlers = handlers, - on_attach = on_attach, - settings = { - bashIde = { - globPattern = "*@(.sh|.inc|.bash|.command)" - } - } -} -require("lspconfig").pyright.setup { capabilities = capabilities, handlers = handlers, - on_attach = on_attach, - -- more details on configuring pyright can be found here - -- https://microsoft.github.io/pyright/#/settings?id=pyright-settings - settings = { - python = { - analysis = { - include = { - '~/arcadia', - '~/arcadia/yt/python', - '~/arcadia/contrib/libs/protobuf/python', - '~/arcadia/contrib/python', - } - } - } - } -} +vim.lsp.enable("lua_ls") +vim.lsp.enable("bashls") +vim.lsp.enable("gopls") +vim.lsp.enable("basedpyright") +vim.lsp.enable("starpls") diff --git a/nvim/lua/options.lua b/nvim/lua/options.lua index 59bc461..d8cf1c9 100644 --- a/nvim/lua/options.lua +++ b/nvim/lua/options.lua @@ -39,3 +39,11 @@ vim.keymap.set('v','y','"+y') -- Keymap to navigate between tabs vim.keymap.set('n', 'H', 'gT') vim.keymap.set('n', 'L', 'gt') + +-- Makeing :W and :Q work same as :w and :q +vim.cmd("command! -bar -nargs=* -complete=file -range=% -bang W ,write ") +vim.cmd("command! -bar -nargs=* -complete=file -range=% -bang Write ,write ") +vim.cmd("command! -bar -nargs=* -complete=file -range=% -bang Wq ,wq ") +vim.cmd("command! -bar -bang Q quit") +vim.cmd("command! -bar -bang Qall qall") +vim.cmd("command! -bar -bang Qa qall") diff --git a/nvim/lua/plugins/codecompanion.lua b/nvim/lua/plugins/codecompanion.lua index 7c1b4f6..4fcc405 100644 --- a/nvim/lua/plugins/codecompanion.lua +++ b/nvim/lua/plugins/codecompanion.lua @@ -1,37 +1,37 @@ -require("codecompanion").setup({ - strategies = { - chat = { - adapter = "deepseek", - }, - inline = { - adapter = "deepseek", - }, - cmd = { - adapter = "deepseek", - } - }, - adapters = { - deepseek = function() - return require("codecompanion.adapters").extend("deepseek", { - env = { - api_key = (function() - local path = os.getenv("HOME") .. "/.config/deepseek_api_key" - local file = io.open(path, "r") - if not file then - vim.notify("Deepseek API key not found at " .. path, vim.log.levels.WARN) - return nil - end - local content = file:read("*a"):gsub("%s+", "") - file:close() - return content - end)(), - }, - schema = { - model = { - default = "deepseek-chat", - }, - }, - }) - end, - }, -}) +-- require("codecompanion").setup({ +-- strategies = { +-- chat = { +-- adapter = "deepseek", +-- }, +-- inline = { +-- adapter = "deepseek", +-- }, +-- cmd = { +-- adapter = "deepseek", +-- } +-- }, +-- adapters = { +-- deepseek = function() +-- return require("codecompanion.adapters").extend("deepseek", { +-- env = { +-- api_key = (function() +-- local path = os.getenv("HOME") .. "/.config/deepseek_api_key" +-- local file = io.open(path, "r") +-- if not file then +-- vim.notify("Deepseek API key not found at " .. path, vim.log.levels.WARN) +-- return nil +-- end +-- local content = file:read("*a"):gsub("%s+", "") +-- file:close() +-- return content +-- end)(), +-- }, +-- schema = { +-- model = { +-- default = "deepseek-chat", +-- }, +-- }, +-- }) +-- end, +-- }, +-- }) diff --git a/nvim/lua/plugins/completions.lua b/nvim/lua/plugins/completions.lua index 60d949c..0114b4d 100644 --- a/nvim/lua/plugins/completions.lua +++ b/nvim/lua/plugins/completions.lua @@ -10,6 +10,7 @@ cmp.setup({ luasnip.lsp_expand(args.body) end }, + preselect = cmp.PreselectMode.None; window = { documentation = cmp.config.window.bordered(), completion = { border = 'rounded' } diff --git a/nvim/lua/plugins/init.lua b/nvim/lua/plugins/init.lua index a9adf06..41e8d7e 100644 --- a/nvim/lua/plugins/init.lua +++ b/nvim/lua/plugins/init.lua @@ -14,10 +14,6 @@ vim.opt.rtp:prepend(lazypath) local plugins = { "williamboman/mason.nvim", "williamboman/mason-lspconfig.nvim", - { - "neovim/nvim-lspconfig", - dependencies = { 'hrsh7th/cmp-nvim-lsp' } - }, { 'projekt0n/github-nvim-theme', name = 'github-theme', @@ -51,9 +47,8 @@ local plugins = { "folke/which-key.nvim", event = "VeryLazy", opts = { - -- your configuration comes here - -- or leave it empty to use the default settings - -- refer to the configuration section below + preset = "modern", + show_help = false, -- workaround for border glitch https://github.com/folke/which-key.nvim/issues/967#issuecomment-2842309305 }, keys = { { @@ -84,14 +79,61 @@ local plugins = { -- Your setup opts here }, }, + -- { + -- "olimorris/codecompanion.nvim", + -- opts = {}, + -- dependencies = { + -- "nvim-lua/plenary.nvim", + -- "nvim-treesitter/nvim-treesitter", + -- }, + -- }, { - "olimorris/codecompanion.nvim", - opts = {}, + "yetone/avante.nvim", + build = vim.fn.has("win32") ~= 0 + and "powershell -ExecutionPolicy Bypass -File Build.ps1 -BuildFromSource false" + or "make", + event = "VeryLazy", + version = false, -- Never set this value to "*"! Never! + ---@module 'avante' + ---@type avante.Config + opts = { + provider = "yaqwencode", + providers = { + yadeepseek = { + __inherited_from = "openai", + api_key_name = "cmd:cat ~/.config/eliza_api_key", + endpoint = "https://api.eliza.yandex.net/raw/internal/deepseek/v1", + model = "deepseek-0324", + use_ReAct_prompt = true, + }, + yaqwencode = { + __inherited_from = "openai", + api_key_name = "cmd:cat ~/.config/eliza_api_key", + endpoint = "https://api.eliza.yandex.net/raw/internal/qwen3-coder-480b-a35b-runtime/v1", + model = "qwen3-coder-480b-a35b-runtime", + use_ReAct_prompt = true, + }, + yaclaude = { + __inherited_from = "openai", + api_key_name = "cmd:cat ~/.config/eliza_api_key", + endpoint = "https://api.eliza.yandex.net/raw/anthropic/v1", + model = "claude-opus-4-5-20251101", + -- use_ReAct_prompt = true, + }, + }, + }, dependencies = { "nvim-lua/plenary.nvim", - "nvim-treesitter/nvim-treesitter", + "MunifTanjim/nui.nvim", + --- The below dependencies are optional, + "nvim-telescope/telescope.nvim", -- for file_selector provider telescope + "hrsh7th/nvim-cmp", -- autocompletion for avante commands and mentions + "ibhagwan/fzf-lua", -- for file_selector provider fzf + -- "stevearc/dressing.nvim", -- for input provider dressing + -- "folke/snacks.nvim", -- for input provider snacks + -- "nvim-tree/nvim-web-devicons", -- or echasnovski/mini.icons }, - }, + } } require("lazy").setup(plugins) @@ -104,4 +146,4 @@ vim.cmd([[ require("plugins/telescope") require("plugins/completions") require("plugins/gitsigns") -require("plugins/codecompanion") +-- require("plugins/codecompanion") diff --git a/nvim/lua/ytils.lua b/nvim/lua/ytils.lua new file mode 100644 index 0000000..0ccc346 --- /dev/null +++ b/nvim/lua/ytils.lua @@ -0,0 +1,248 @@ +local M = {} +local NIL = "" + +local unpack = table.unpack or unpack + +M.ARC_REPO_ROOT_ENV = "ARC_ROOT" + +M._arc_repo_roots = { + "/home/dmchumak/arcadia/", +} + +local is_windows = vim.loop.os_uname().version:match("Windows") + +M.table = (function() + -- finds the index of value in the table + ---@param t table + ---@param value any + ---@return integer? + local function find(t, value) + for ix, ix_value in ipairs(t) do + if ix_value == value then + return ix + end + end + return nil + end + + return { + find = find, + } +end)() + +M.path = (function() + -- stolen form + -- https://github.com/neovim/nvim-lspconfig/tree/71b39616b14c152da34fcc787fa27f09bf280e72/lua/lspconfig/util.lua#L124 + local function is_fs_root(path) + if is_windows then + return path:match("^%a:$") + else + return path == "/" + end + end + + -- stolen from https://github.com/neovim/nvim-lspconfig/tree/71b39616b14c152da34fcc787fa27f09bf280e72/lua/lspconfig/util.lua#L142 + ---@param path string + ---@return string? + local function dirname(path) + local strip_dir_pat = "/([^/]+)$" + local strip_sep_pat = "/$" + if not path or #path == 0 then + return + end + local result = path:gsub(strip_sep_pat, ""):gsub(strip_dir_pat, "") + if #result == 0 then + if is_windows then + return path:sub(1, 2):upper() + else + return "/" + end + end + return result + end + + return { + is_fs_root = is_fs_root, + dirname = dirname, + } +end)() + +if os.getenv(M.ARC_REPO_ROOT_ENV) then + table.insert(M._arc_repo_roots, 1, os.getenv(M.ARC_REPO_ROOT_ENV)) +end + +function M.is_inside_arc(path) + for _, prefix in ipairs(M._arc_repo_roots) do + if path:find(prefix, 1, true) == 1 then + return true + end + end + + return false +end + +function M.is_ok_root_dir(path) + -- local util = require("dgronskiy_nvim.util") + + if M.path.is_fs_root(path) then + return false + end + + if path == os.getenv("HOME") then + return false + end + + -- No-Go's: + -- * /data/a/trunk + -- * /data/a/dev + -- * /data/a/MLDWH-XXX + local path_and_parent = { path, M.path.dirname(path) } + for _, check_against in ipairs(M._arc_repo_roots) do + if M.table.find(path_and_parent, check_against) then + return false + end + end + + return true +end + +-- TODO: move ok_root_dirs into global config file + +-- root_dir function in terms of `lspconfig`. Get inspiration here: +-- https://github.com/neovim/nvim-lspconfig/tree/bfdf2e91e7297a54bcc09d3e092a12bff69a1cf4/lua/lspconfig/util.lua#L268 +function M.guarded_pyright_root_directory(startpath) + local is_inside_arc = M.is_inside_arc(startpath) + local root_dir = nil + + if is_inside_arc then + local util = require("lspconfig.util") + root_dir = util.root_pattern("pyrightconfig.json")(startpath) + else + -- use default from here + -- https://github.com/neovim/nvim-lspconfig/blob/d1871c84b218931cc758dbbde1fec8e90c6d465c/lua/lspconfig/configs/pyright.lua#L47 + root_dir = require("lspconfig.configs.pyright").default_config.root_dir(startpath) + end + + local is_ok_root_dir = M.is_ok_root_dir(root_dir) + root_dir = is_ok_root_dir and root_dir or nil + + -- if not M.is_ok_root_dir(root_dir) then + -- logger:warn("patching + -- vim.notify( + -- "Inside Arc=" + -- .. tostring(is_inside_arc) + -- .. "\nFile= " + -- .. startpath + -- .. "\nRoot dir= " + -- .. root_dir + -- .. "\n\nPatching root_dir to nil" + -- ) + -- root_dir = nil + -- end + return root_dir +end + +-- func! GetArcanumLink(mode) +-- let l:root = system("arc root") +-- let l:link = "https://a.yandex-team.ru/arc_vcs/" . expand("%:p")[len(l:root):] +-- if a:mode == "normal" +-- return l:link . "\\#L" . getcurpos()[1] +-- else +-- let l:start = getpos("'<") +-- let l:finish = getpos("'>") +-- return l:link . "\\#L" . l:start[1] . "-" . l:finish[1] +-- endif +-- endf + +---comment +---@return string? # nil in case of an error +function M.GetArcRoot() + local stdout = vim.fn.system("arc root 2>/dev/null") + if vim.api.nvim_get_vvar("shell_error") ~= 0 then + print(stdout) + return + end + return stdout:gsub("\n", "") +end + +--- +---@param file_path string +---@param arc_root string +---@return string? # nil in case of en error +function M.GetArcRelativePath(file_path, arc_root) + if string.sub(arc_root, -1, -1) ~= "/" then + arc_root = arc_root .. "/" + end + + if string.sub(file_path, 1, string.len(arc_root)) ~= arc_root then + print(string.format("file_path [%s] is not in the repo [%s]", file_path, arc_root)) + return + end + + local file_relative_path = string.sub(file_path, string.len(arc_root) + 1) + return file_relative_path +end + +--- +---@return string? # nil in case of an error +function M.GetArcHeadCommit() + local stdout = vim.fn.system("arc rev-parse HEAD 2>/dev/null") + if vim.api.nvim_get_vvar("shell_error") ~= 0 then + print(stdout) + return + end + + return stdout:gsub("\n", "") +end + +---comment +---@return string? # nil in case of an error +function M.GetArcanumLink(opts) + local url_lines_requester = (function(opts) + local line1, line2 + if opts and opts.linerange then + line1, line2 = unpack(opts.linerange) + else + line1 = vim.api.nvim_win_get_cursor(0)[1] + line2 = line1 + end + + -- print(vim.inspect(line1)) + + line1, line2 = math.min(line1, line2), math.max(line1, line2) + if line1 == line2 then + return "#L" .. tostring(line1) + else + return "#L" .. tostring(line1) .. "-" .. tostring(line2) + end + end)(opts) + + local arc_root = M.GetArcRoot() + if not arc_root then + return + end + + local file_path = vim.fn.expand("%:p") ---@type string + local file_relative_path = M.GetArcRelativePath(file_path, arc_root) + if not file_relative_path then + return + end + + local revision = M.GetArcHeadCommit() + revision = revision and ("?rev=" .. revision) or "" + + local url = "https://a.yandex-team.ru/arcadia/" .. file_relative_path .. revision .. url_lines_requester + return url + + -- return "https://a.yandex-team.ru/arcadia/" .. .. "#L" + --?rev=r14586396#L10 +end + +---@param link string +---@return nil +function M.ArcLinkOpen(link) + -- https://a.yandex-team.ru/arcadia/ads/libs/py_rearrange/__init__.py#L96 + local prefix = "https://a.yandex-team.ru/arcadia" +end + +return M diff --git a/shell/alias.sh b/shell/alias.sh index 2e48880..06d37a4 100644 --- a/shell/alias.sh +++ b/shell/alias.sh @@ -1,4 +1,4 @@ -alias l="ls -lah" +alias l="ls -lahG" alias lg="LANG=en_US-UTF-8 lazygit" alias v="vim" alias n="nvim"