Compare commits
2 Commits
ebe143ee28
...
2fa073ea87
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2fa073ea87 | ||
|
|
880bbd18e0 |
@@ -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": "3d5bced1b9ae69fa3f9b1942e28af5dbc537f946" },
|
||||
"cmp-buffer": { "branch": "main", "commit": "b74fab3656eea9de20a9b8116afa3cfc4ec09657" },
|
||||
"cmp-nvim-lsp": { "branch": "main", "commit": "a8912b88ce488f411177fc8aed358b04dc246d7b" },
|
||||
"cmp-path": { "branch": "main", "commit": "e52e640b7befd8113b3350f46e8cfcfe98fcf730" },
|
||||
"codecompanion.nvim": { "branch": "main", "commit": "e23e8e5a5643b089607f21f576f6e63174cc44dc" },
|
||||
"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" },
|
||||
"mason-lspconfig.nvim": { "branch": "main", "commit": "bb3a17efc797c34c054463174e5522442576ebd8" },
|
||||
"mason.nvim": { "branch": "main", "commit": "8024d64e1330b86044fed4c8494ef3dcd483a67c" },
|
||||
"nvim-cmp": { "branch": "main", "commit": "b5311ab3ed9c846b585c0c15b7559be131ec4be9" },
|
||||
"nvim-lspconfig": { "branch": "master", "commit": "169745f176f58becad80363c3f8f2315ed6bb365" },
|
||||
"nvim-treesitter": { "branch": "master", "commit": "42fc28ba918343ebfd5565147a42a26580579482" },
|
||||
"outline.nvim": { "branch": "main", "commit": "0eb9289ab39c91caf8b3ed0e3a17764809d69558" },
|
||||
"plenary.nvim": { "branch": "master", "commit": "857c5ac632080dba10aae49dba902ce3abf91b35" },
|
||||
"telescope-file-browser.nvim": { "branch": "master", "commit": "626998e5c1b71c130d8bc6cf7abb6709b98287bb" },
|
||||
"telescope.nvim": { "branch": "master", "commit": "814f102cd1da3dc78c7d2f20f2ef3ed3cdf0e6e4" },
|
||||
"telescope-file-browser.nvim": { "branch": "master", "commit": "7bf55ed0ff5be182ad3301cff266581fc1c56cce" },
|
||||
"telescope.nvim": { "branch": "master", "commit": "b4da76be54691e854d3e0e02c36b0245f945c2c7" },
|
||||
"which-key.nvim": { "branch": "main", "commit": "370ec46f710e058c9c1646273e6b225acf47cbed" }
|
||||
}
|
||||
|
||||
25
nvim/lsp/basedpyright.lua
Normal file
25
nvim/lsp/basedpyright.lua
Normal file
@@ -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 = {
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
25
nvim/lsp/bashls.lua
Normal file
25
nvim/lsp/bashls.lua
Normal file
@@ -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',
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
20
nvim/lsp/gopls.lua
Normal file
20
nvim/lsp/gopls.lua
Normal file
@@ -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,
|
||||
-- },
|
||||
-- },
|
||||
-- },
|
||||
}
|
||||
33
nvim/lsp/lua_ls.lua
Normal file
33
nvim/lsp/lua_ls.lua
Normal file
@@ -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,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,57 +4,55 @@ require("mason-lspconfig").setup({
|
||||
'lua_ls',
|
||||
'gopls',
|
||||
'bashls',
|
||||
'pyright',
|
||||
'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", "<leader>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", "<leader>q", vim.diagnostic.setloclist, opts)
|
||||
local keymap = vim.keymap.set
|
||||
|
||||
local on_attach = function(client, bufnr)
|
||||
-- Enable completion triggered by <c-x><c-o>
|
||||
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", "<leader>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", "<C-k>", lsp.buf.signature_help, bufopts)
|
||||
keymap("n", "<leader>wa", lsp.buf.add_workspace_folder, bufopts)
|
||||
keymap("n", "<leader>wr", lsp.buf.remove_workspace_folder, bufopts)
|
||||
keymap("n", "<leader>wl", function()
|
||||
print(vim.inspect(lsp.buf.list_workspace_folders()))
|
||||
end, bufopts)
|
||||
keymap("n", "<leader>rn", lsp.buf.rename, opt("[l]sp [R]ename"))
|
||||
keymap("n", "<leader>lc", lsp.buf.code_action, opt("[l]sp [C]ode Action"))
|
||||
keymap("n", "<leader>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", "<C-k>", vim.lsp.buf.signature_help, bufopts)
|
||||
vim.keymap.set("n", "<leader>wa", vim.lsp.buf.add_workspace_folder, bufopts)
|
||||
vim.keymap.set("n", "<leader>wr", vim.lsp.buf.remove_workspace_folder, bufopts)
|
||||
vim.keymap.set("n", "<leader>wl", function()
|
||||
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
|
||||
end, bufopts)
|
||||
vim.keymap.set("n", "<leader>D", vim.lsp.buf.type_definition, bufopts)
|
||||
vim.keymap.set("n", "<leader>rn", vim.lsp.buf.rename, bufopts)
|
||||
vim.keymap.set("n", "<leader>ca", vim.lsp.buf.code_action, bufopts)
|
||||
vim.keymap.set("n", "<leader>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,107 +63,13 @@ 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", "<leader>e", vim.diagnostic.open_float, opts)
|
||||
keymap("n", "<leader>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").nixd.setup { capabilities = capabilities, handlers = handlers,
|
||||
cmd = { 'nixd' },
|
||||
filetypes = { 'nix' },
|
||||
root_dir = function(fname)
|
||||
return require('lspconfig.util').root_pattern(
|
||||
'flake.nix',
|
||||
'shell.nix',
|
||||
'default.nix',
|
||||
'.git'
|
||||
)(fname) or vim.fn.getcwd()
|
||||
end,
|
||||
on_attach = on_attach,
|
||||
settings = {
|
||||
nixd = {
|
||||
formatting = {
|
||||
command = { "nixpkgs-fmt" } -- Uses nixpkgs-fmt for formatting
|
||||
},
|
||||
eval = {
|
||||
depth = 3, -- Evaluation depth
|
||||
workers = 2, -- Number of evaluation workers
|
||||
},
|
||||
completion = {
|
||||
autoImport = true -- Auto-import completions
|
||||
},
|
||||
nixpkgs = {
|
||||
expr = "import <nixpkgs> {}", -- Default nixpkgs expression
|
||||
-- path = "/path/to/your/nixpkgs" -- Optional explicit path
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
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")
|
||||
|
||||
@@ -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' }
|
||||
|
||||
@@ -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 = {
|
||||
{
|
||||
|
||||
248
nvim/lua/ytils.lua
Normal file
248
nvim/lua/ytils.lua
Normal file
@@ -0,0 +1,248 @@
|
||||
local M = {}
|
||||
local NIL = "<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
|
||||
Reference in New Issue
Block a user