mirror of
https://github.com/boxpositron/absolute-vim.git
synced 2026-02-28 11:40:36 +00:00
feat(dap.lua): add virtual text setup for better debugging experience
feat(dap.lua): add support for process.env.PORT environment variable to be able to run app on a configurable port feat(lsp-config.lua): add support for detecting python environment using DPE module feat(lualine.lua): add support for noice statusline component feat(mason.lua): update installed language servers list feat(noice.lua): add configuration for noice plugin feat(none-ls.lua): remove black and mypy formatters from null-ls setup fix(nvim-cmp.lua): change completeopt value to "menu,menuone,preview,noinsert" and add autocomplete trigger event on text change feat(nvim-cmp.lua): add border and winhighlight settings for documentation window to improve visual appearance feat(nvim-cmp.lua): add 'nvim_lsp_signature_help' as a source for autocompletion refactor(colorscheme.lua): refactor SetupWindowPreferences function to dynamically set blend values for highlight groups feat(init.lua): add setting for 'completeopt' to "menuone" feat(plugins/noice.lua): add configuration for 'noice.nvim' plugin with dependencies and event trigger feat(plugins/nvim-treesitter.lua): update configuration to run TSUpdate command silently feat(utils): add Lua utility functions to detect and manage Lua versions and paths feat(utils): add Python utility functions to check and resolve Python environments style(theme): update current theme to 'catppuccin' in Lua script
This commit is contained in:
@@ -1,21 +1,35 @@
|
||||
local dap = require("dap")
|
||||
local dapui = require("dapui")
|
||||
local dap_python = require("dap-python")
|
||||
local virtual_text = require("nvim-dap-virtual-text")
|
||||
|
||||
-- Setup Virtual Text
|
||||
virtual_text.setup({
|
||||
prefix = " ",
|
||||
hl = "Comment",
|
||||
lines = 3,
|
||||
enabled = true,
|
||||
})
|
||||
|
||||
|
||||
local mason_path = vim.fn.glob(vim.fn.stdpath("data") .. "/mason")
|
||||
local debugpy_path = mason_path .. "/packages/debugpy/venv/bin/python"
|
||||
|
||||
dapui.setup()
|
||||
dap_python.setup(debugpy_path)
|
||||
|
||||
dap.listeners.after.event_initialized["dapui_config"] = function()
|
||||
dapui.open()
|
||||
end
|
||||
|
||||
dap.listeners.before.event_terminated["dapui_config"] = function()
|
||||
dapui.close()
|
||||
end
|
||||
|
||||
dap.listeners.before.event_exited["dapui_config"] = function()
|
||||
dapui.close()
|
||||
end
|
||||
|
||||
|
||||
local path = "~/.local/share/nvim/mason/packages/debugpy/venv/bin/python"
|
||||
dap_python.setup(path)
|
||||
|
||||
-- Setup Mappings
|
||||
local opts = { noremap = true, silent = true }
|
||||
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
vim.g["jedi#popup_on_dot"] = 1
|
||||
vim.g["jedi#use_tabs_not_buffers"] = 0
|
||||
vim.g["jedi#popup_select_first"] = 0
|
||||
vim.g["jedi#show_call_signatures"] = "2"
|
||||
|
||||
|
||||
-- Keybindings
|
||||
vim.g["jedi#goto_command"] = "" -- "<leader>d"
|
||||
vim.g["jedi#goto_assignments_command"] = "<leader>gD"
|
||||
vim.g["jedi#goto_stubs_command"] = "" -- "<leader>s"
|
||||
vim.g["jedi#goto_definitions_command"] = "gd"
|
||||
vim.g["jedi#documentation_command"] = "K"
|
||||
vim.g["jedi#usages_command"] = "<leader>n"
|
||||
vim.g["jedi#completions_command"] = "<C-Space>"
|
||||
vim.g["jedi#rename_command"] = "<leader>rn"
|
||||
vim.g["jedi#rename_command_keep_name"] = "" -- "<leader>R"
|
||||
@@ -2,6 +2,8 @@
|
||||
local lspconfig = require("lspconfig")
|
||||
local cmp_nvim_lsp = require("cmp_nvim_lsp")
|
||||
|
||||
local DPE = require("absolute.utils.detect-python-env")
|
||||
|
||||
local opts = { noremap = true, silent = true }
|
||||
local on_attach = function(client, bufnr)
|
||||
opts.buffer = bufnr
|
||||
@@ -73,7 +75,7 @@ lspconfig["html"].setup({
|
||||
})
|
||||
|
||||
-- configure typescript server with plugin
|
||||
lspconfig["tsserver"].setup({
|
||||
lspconfig["ts_ls"].setup({
|
||||
capabilities = capabilities,
|
||||
on_attach = on_attach,
|
||||
})
|
||||
@@ -111,8 +113,20 @@ lspconfig["svelte"].setup({
|
||||
lspconfig["emmet_ls"].setup({
|
||||
capabilities = capabilities,
|
||||
on_attach = on_attach,
|
||||
filetypes = { "html", "typescriptreact", "javascriptreact", "css", "sass", "scss", "less", "svelte", "vue" },
|
||||
filetypes = {
|
||||
"html",
|
||||
"typescriptreact",
|
||||
"javascriptreact",
|
||||
"css",
|
||||
"sass",
|
||||
"scss",
|
||||
"less",
|
||||
"svelte",
|
||||
"vue",
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
-- configure python lsp
|
||||
lspconfig["pylsp"].setup({
|
||||
filetypes = { "python" },
|
||||
@@ -124,22 +138,29 @@ lspconfig["pylsp"].setup({
|
||||
rope_autoimport = {
|
||||
enabled = true,
|
||||
completions = { enabled = true },
|
||||
rename = { enabled = false },
|
||||
},
|
||||
black = { enabled = true },
|
||||
autopep8 = { enabled = false },
|
||||
yapf = { enabled = false },
|
||||
flake8 = { enabled = true },
|
||||
jedi_completion = {
|
||||
enabled = true,
|
||||
include_params = true,
|
||||
fuzzy = true,
|
||||
},
|
||||
pylsp_mypy = {
|
||||
enabled = true,
|
||||
overrides = DPE.ResolvePythonEnvironment(),
|
||||
report_progress = true,
|
||||
live_mode = true,
|
||||
},
|
||||
-- import sorting
|
||||
pyls_isort = { enabled = true },
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
--
|
||||
-- -- configure jedi language server
|
||||
-- lspconfig["jedi_language_server"].setup({
|
||||
-- capabilities = capabilities,
|
||||
-- on_attach = on_attach,
|
||||
-- })
|
||||
|
||||
-- configure docker server
|
||||
lspconfig["dockerls"].setup({
|
||||
capabilities = capabilities,
|
||||
@@ -226,13 +247,27 @@ lspconfig["astro"].setup({
|
||||
on_attach = on_attach,
|
||||
})
|
||||
|
||||
|
||||
-- configure kotlin server
|
||||
lspconfig["kotlin_language_server"].setup({
|
||||
capabilities = capabilities,
|
||||
on_attach = on_attach,
|
||||
})
|
||||
|
||||
|
||||
-- configure clang server
|
||||
|
||||
lspconfig["clangd"].setup({
|
||||
capabilities = capabilities,
|
||||
on_attach = on_attach,
|
||||
})
|
||||
|
||||
-- configure arduino language server
|
||||
|
||||
lspconfig["arduino_language_server"].setup({
|
||||
capabilities = capabilities,
|
||||
on_attach = on_attach,
|
||||
})
|
||||
|
||||
-- configure biome server
|
||||
lspconfig["biome"].setup({
|
||||
capabilities = capabilities,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
local lualine = require("lualine")
|
||||
local lazy_status = require("lazy.status") -- to configure lazy pending updates count
|
||||
|
||||
local noice = require("noice")
|
||||
|
||||
local colors = {
|
||||
blue = "#65D1FF",
|
||||
@@ -94,23 +94,12 @@ lualine.setup({
|
||||
theme = my_lualine_theme,
|
||||
},
|
||||
sections = {
|
||||
-- lualine_c = {
|
||||
-- -- ...other lualine components
|
||||
-- {
|
||||
-- require('tmux-status').tmux_windows,
|
||||
-- cond = require('tmux-status').show,
|
||||
-- padding = { left = 3 },
|
||||
-- },
|
||||
-- },
|
||||
-- lualine_z = {
|
||||
-- -- ...other lualine components
|
||||
-- {
|
||||
-- require('tmux-status').tmux_session,
|
||||
-- cond = require('tmux-status').show,
|
||||
-- padding = { left = 3 },
|
||||
-- },
|
||||
-- },
|
||||
lualine_x = {
|
||||
{
|
||||
noice.api.statusline.mode.get,
|
||||
cond = noice.api.statusline.mode.has,
|
||||
color = { fg = "#ff9e64" },
|
||||
},
|
||||
{
|
||||
GetFlutterToolsStatusLine,
|
||||
cond = IsFlutterToolsActive,
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
require("mason").setup()
|
||||
require("mason-lspconfig").setup({
|
||||
ensure_installed = {
|
||||
"tsserver",
|
||||
"ts_ls",
|
||||
"astro",
|
||||
"biome",
|
||||
"rust_analyzer",
|
||||
"html",
|
||||
"emmet_ls",
|
||||
"lua_ls",
|
||||
'arduino_language_server',
|
||||
'clangd',
|
||||
"tailwindcss",
|
||||
"svelte",
|
||||
"cssls",
|
||||
|
||||
92
lua/absolute/after/noice.lua
Normal file
92
lua/absolute/after/noice.lua
Normal file
@@ -0,0 +1,92 @@
|
||||
local noice = require("noice")
|
||||
local notify = require("notify")
|
||||
|
||||
|
||||
notify.setup({
|
||||
top_down = false,
|
||||
animate = false,
|
||||
stages = "static",
|
||||
})
|
||||
|
||||
noice.setup({
|
||||
routes = {
|
||||
{
|
||||
filter = {
|
||||
event = "msg_show",
|
||||
min_height = 20,
|
||||
},
|
||||
view = "cmdline_output",
|
||||
},
|
||||
{
|
||||
filter = {
|
||||
event = "lsp",
|
||||
kind = "progress",
|
||||
cond = function(message)
|
||||
local client = vim.tbl_get(message.opts, "progress", "client")
|
||||
|
||||
return client == "lua_ls"
|
||||
end
|
||||
},
|
||||
opts = { skip = true },
|
||||
}
|
||||
},
|
||||
lsp = {
|
||||
-- override markdown rendering so that **cmp** and other plugins use **Treesitter**
|
||||
override = {
|
||||
["vim.lsp.util.convert_input_to_markdown_lines"] = true,
|
||||
["vim.lsp.util.stylize_markdown"] = true,
|
||||
["cmp.entry.get_documentation"] = true, -- requires hrsh7th/nvim-cmp
|
||||
},
|
||||
},
|
||||
cmdline = {
|
||||
format = {
|
||||
search_down = {
|
||||
view = "cmdline",
|
||||
},
|
||||
search_up = {
|
||||
view = "cmdline",
|
||||
},
|
||||
},
|
||||
},
|
||||
views = {
|
||||
cmdline_popup = {
|
||||
relative = "editor",
|
||||
position = {
|
||||
row = 5,
|
||||
col = "50%",
|
||||
},
|
||||
size = {
|
||||
width = 60,
|
||||
height = "auto",
|
||||
},
|
||||
border = {
|
||||
style = { "╭", "─", "╮", "│", "╯", "─", "╰", "│" },
|
||||
padding = { 0, 1 },
|
||||
},
|
||||
filter_options = {},
|
||||
win_options = {
|
||||
winhighlight = {
|
||||
Normal = "Normal",
|
||||
}
|
||||
},
|
||||
},
|
||||
popupmenu = {
|
||||
relative = "editor",
|
||||
position = {
|
||||
row = 8,
|
||||
col = "50%",
|
||||
},
|
||||
size = {
|
||||
width = 60,
|
||||
height = 10,
|
||||
},
|
||||
border = {
|
||||
style = "rounded",
|
||||
padding = { 0, 1 },
|
||||
},
|
||||
win_options = {
|
||||
winhighlight = { Normal = "Normal", FloatBorder = "DiagnosticInfo" },
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
@@ -1,41 +1,9 @@
|
||||
local null_ls = require("null-ls")
|
||||
|
||||
|
||||
function CheckPoetryVirtualEnv()
|
||||
local poetry = vim.fn.system("poetry env info -p 2>/dev/null")
|
||||
if poetry == "" then
|
||||
return nil
|
||||
end
|
||||
return poetry
|
||||
end
|
||||
|
||||
function ResolvePythonEnvironment()
|
||||
-- Get system global python env
|
||||
local python = vim.fn.system("which python3")
|
||||
-- Check of virtual environments exists
|
||||
local virtual = os.getenv("VIRTUAL_ENV") or os.getenv("CONDA_PREFIX") or CheckPoetryVirtualEnv()
|
||||
|
||||
if virtual == nil then
|
||||
-- Check if poetry environment exists
|
||||
|
||||
return {
|
||||
"--python-executable", python
|
||||
}
|
||||
end
|
||||
|
||||
return {
|
||||
"--python-executable", virtual .. "/bin/python3"
|
||||
}
|
||||
end
|
||||
|
||||
null_ls.setup({
|
||||
sources = {
|
||||
null_ls.builtins.formatting.stylua,
|
||||
null_ls.builtins.formatting.prettierd,
|
||||
null_ls.builtins.formatting.shfmt,
|
||||
null_ls.builtins.formatting.black,
|
||||
null_ls.builtins.diagnostics.mypy.with({
|
||||
extra_args = ResolvePythonEnvironment()
|
||||
}),
|
||||
},
|
||||
})
|
||||
|
||||
@@ -1,37 +1,27 @@
|
||||
local cmp = require("cmp")
|
||||
local types = require('cmp.types')
|
||||
local luasnip = require("luasnip")
|
||||
local lspkind = require("lspkind")
|
||||
|
||||
-- loads vscode style snippets from installed plugins (e.g. friendly-snippets)
|
||||
require("luasnip.loaders.from_vscode").lazy_load()
|
||||
|
||||
local function border(hl_name)
|
||||
return {
|
||||
{ "╭", hl_name },
|
||||
{ "─", hl_name },
|
||||
{ "╮", hl_name },
|
||||
{ "│", hl_name },
|
||||
{ "╯", hl_name },
|
||||
{ "─", hl_name },
|
||||
{ "╰", hl_name },
|
||||
{ "│", hl_name },
|
||||
}
|
||||
end
|
||||
|
||||
cmp.setup({
|
||||
completion = {
|
||||
completeopt = "menu,menuone,preview,noselect",
|
||||
completeopt = "menu,menuone,preview,noinsert",
|
||||
autocomplete = { types.cmp.TriggerEvent.TextChanged },
|
||||
},
|
||||
window = {
|
||||
documentation = {
|
||||
border = { '┌', '─', '┐', '│', '┘', '─', '└', '│' },
|
||||
winhighlight = 'Normal:CmpPmenu,FloatBorder:CmpPmenuBorder,CursorLine:PmenuSel,Search:None',
|
||||
},
|
||||
completion = {
|
||||
side_padding = 1,
|
||||
winhighlight = "Normal:CmpPmenu,CursorLine:CmpSel,Search:None",
|
||||
border = { '┌', '─', '┐', '│', '┘', '─', '└', '│' },
|
||||
winhighlight = 'Normal:CmpPmenu,FloatBorder:CmpPmenuBorder,CursorLine:PmenuSel,Search:None',
|
||||
scrollbar = false,
|
||||
},
|
||||
documentation = {
|
||||
border = border "CmpDocBorder",
|
||||
winhighlight = "Normal:CmpDoc",
|
||||
},
|
||||
},
|
||||
snippet = { -- configure how nvim-cmp interacts with snippet engine
|
||||
expand = function(args)
|
||||
@@ -39,16 +29,17 @@ cmp.setup({
|
||||
end,
|
||||
},
|
||||
mapping = cmp.mapping.preset.insert({
|
||||
["<C-Space>"] = cmp.mapping.complete(), -- show completion suggestions
|
||||
["<C-o>"] = cmp.mapping.complete(), -- show completion suggestions
|
||||
["<C-e>"] = cmp.mapping.abort(), -- close completion menu
|
||||
["<CR>"] = cmp.mapping.confirm({ select = true }), -- accept current selection
|
||||
}),
|
||||
-- sources for autocompletion
|
||||
sources = cmp.config.sources({
|
||||
{ name = "otter" }, -- custom source for otter completion
|
||||
{ name = "nvim_lsp" },
|
||||
{ name = "luasnip" }, -- snippets
|
||||
{ name = "buffer" }, -- text within current buffer
|
||||
{ name = "path" }, -- file system paths
|
||||
{ name = "path" }, -- file system paths,
|
||||
{ name = 'nvim_lsp_signature_help' },
|
||||
}),
|
||||
-- configure lspkind for vs-code like pictograms in completion menu
|
||||
formatting = {
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
local otter = require("otter")
|
||||
|
||||
-- table of embedded languages to look for.
|
||||
-- required (no default)
|
||||
local languages = { "python", "lua" }
|
||||
|
||||
-- enable completion/diagnostics
|
||||
-- defaults are true
|
||||
local completion = true
|
||||
local diagnostics = true
|
||||
-- treesitter query to look for embedded languages
|
||||
-- uses injections if nil or not set
|
||||
local tsquery = nil
|
||||
|
||||
otter.activate(languages, completion, diagnostics, tsquery)
|
||||
@@ -1,8 +1,12 @@
|
||||
local tsj = require("treesj")
|
||||
|
||||
|
||||
local langs = {}
|
||||
|
||||
tsj.setup({
|
||||
use_default_keymaps = false,
|
||||
max_join_length = 1000,
|
||||
langs = langs,
|
||||
})
|
||||
|
||||
local opts = { silent = true, noremap = true }
|
||||
|
||||
@@ -1,11 +1,24 @@
|
||||
local function SetupWindowPreferences()
|
||||
vim.api.nvim_set_hl(0, "Normal", { bg = "none" })
|
||||
vim.api.nvim_set_hl(0, "NormalFloat", { bg = "none" })
|
||||
vim.api.nvim_set_hl(0, "NormalNC", { bg = "none" })
|
||||
-- Utility function to get the blend value or set a default
|
||||
local function get_blend_value(group_name, default_blend)
|
||||
-- Retrieve highlight settings for the group using the new API
|
||||
local current_highlight = vim.api.nvim_get_hl(0, { name = group_name })
|
||||
return current_highlight.blend or default_blend
|
||||
end
|
||||
|
||||
-- Set the Normal group with dynamic blend
|
||||
local normal_blend = get_blend_value("Normal", 50)
|
||||
vim.api.nvim_set_hl(0, "Normal", { bg = "none", blend = normal_blend })
|
||||
|
||||
-- Set the NormalFloat group with dynamic blend
|
||||
local normal_float_blend = get_blend_value("NormalFloat", 50)
|
||||
vim.api.nvim_set_hl(1, "NormalFloat", { bg = "none", blend = normal_float_blend })
|
||||
|
||||
-- Set the NormalNC group with dynamic blend
|
||||
local normal_nc_blend = get_blend_value("NormalNC", 50)
|
||||
vim.api.nvim_set_hl(0, "NormalNC", { bg = "none", blend = normal_nc_blend })
|
||||
end
|
||||
|
||||
|
||||
|
||||
local colorschemes = {
|
||||
["tokyonight-day"] = "Tokyo Night Day",
|
||||
["tokyonight-night"] = "Tokyo Night Night",
|
||||
@@ -35,7 +48,7 @@ local function SyncWezTerm()
|
||||
assert(file)
|
||||
file:write(colorscheme)
|
||||
file:close()
|
||||
vim.notify("Setting WezTerm color scheme to " .. colorscheme, vim.log.levels.INFO)
|
||||
-- vim.notify("Setting WezTerm color scheme to " .. colorscheme, vim.log.levels.INFO)
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
local lua_utils = require("absolute.utils.detect-lua")
|
||||
|
||||
package.path = package.path .. lua_utils.GetLatestLuaVersion()
|
||||
|
||||
|
||||
|
||||
-- disable nvim intro
|
||||
vim.opt.shortmess:append "sI"
|
||||
|
||||
@@ -37,6 +43,7 @@ vim.opt.updatetime = 50
|
||||
|
||||
vim.opt.colorcolumn = ""
|
||||
|
||||
vim.o.completeopt = "menuone"
|
||||
vim.g.mapleader = " "
|
||||
vim.g.maplocalleader = ";"
|
||||
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
return {
|
||||
"nvim-tree/nvim-tree.lua",
|
||||
dependencies = { "nvim-tree/nvim-web-devicons" },
|
||||
config = function()
|
||||
require("absolute.after.nvim-tree");
|
||||
end
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
return {
|
||||
"jmbuhr/otter.nvim",
|
||||
config = function()
|
||||
require("absolute.after.otter")
|
||||
end,
|
||||
ft = { "py", "lua" }
|
||||
}
|
||||
@@ -1,8 +1,6 @@
|
||||
package.path = package.path .. ";" .. vim.fn.expand("$HOME") .. "/.luarocks/share/lua/5.1/?/init.lua;"
|
||||
package.path = package.path .. ";" .. vim.fn.expand("$HOME") .. "/.luarocks/share/lua/5.1/?.lua;"
|
||||
|
||||
|
||||
require("absolute.core")
|
||||
require("absolute.lazy")
|
||||
require("absolute.helpers")
|
||||
require("absolute.remap")
|
||||
|
||||
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
return {
|
||||
"mfussenegger/nvim-dap",
|
||||
dependencies = {
|
||||
-- "theHamsta/nvim-dap-virtual-text",
|
||||
"theHamsta/nvim-dap-virtual-text",
|
||||
"rcarriga/nvim-dap-ui",
|
||||
"nvim-neotest/nvim-nio",
|
||||
"nvim-telescope/telescope-dap.nvim",
|
||||
{ "mfussenegger/nvim-dap-python", ft = "python", dependencies = { "mfussenegger/nvim-dap" } },
|
||||
{
|
||||
"mfussenegger/nvim-dap-python",
|
||||
ft = "python",
|
||||
dependencies = { "mfussenegger/nvim-dap" },
|
||||
},
|
||||
-- "Pocco81/DAPInstall.nvim"
|
||||
},
|
||||
config = function()
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
return {
|
||||
"davidhalter/jedi-vim",
|
||||
config = function()
|
||||
require("absolute.after.jedi")
|
||||
end
|
||||
}
|
||||
15
lua/absolute/plugins/noice.lua
Normal file
15
lua/absolute/plugins/noice.lua
Normal file
@@ -0,0 +1,15 @@
|
||||
return {
|
||||
"folke/noice.nvim",
|
||||
event = "VeryLazy",
|
||||
dependencies = {
|
||||
-- if you lazy-load any plugin below, make sure to add proper `module="..."` entries
|
||||
"MunifTanjim/nui.nvim",
|
||||
-- OPTIONAL:
|
||||
-- `nvim-notify` is only needed, if you want to use the notification view.
|
||||
-- If not available, we use `mini` as the fallback
|
||||
"rcarriga/nvim-notify",
|
||||
},
|
||||
config = function()
|
||||
require("absolute.after.noice")
|
||||
end,
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
return {
|
||||
"nvim-treesitter/nvim-treesitter",
|
||||
config = function()
|
||||
vim.cmd([[:TSUpdate]])
|
||||
vim.cmd([[:silent !TSUpdate]])
|
||||
require("absolute.after.nvim-treesitter")
|
||||
end
|
||||
}
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
return {
|
||||
"christopher-francisco/tmux-status.nvim",
|
||||
lazy = true,
|
||||
opts = {},
|
||||
}
|
||||
39
lua/absolute/utils/detect-lua.lua
Normal file
39
lua/absolute/utils/detect-lua.lua
Normal file
@@ -0,0 +1,39 @@
|
||||
function GetLuaPath(version)
|
||||
local path = vim.fn.expand("$HOME") .. "/.luarocks/share/lua/" .. version .. "/?.lua;"
|
||||
path = path .. vim.fn.expand("$HOME") .. "/.luarocks/share/lua/" .. version .. "/?/init.lua;"
|
||||
return path
|
||||
end
|
||||
|
||||
function GetInstalledLuaVersion()
|
||||
-- List the directory contents of the lua rocks directory
|
||||
local rocks = vim.fn.glob(vim.fn.expand("$HOME") .. "/.luarocks/share/lua/")
|
||||
|
||||
-- Split the string into a table
|
||||
|
||||
rocks = vim.split(rocks, "\n")
|
||||
|
||||
-- Sort the table highest to lowest
|
||||
|
||||
table.sort(rocks, function(a, b)
|
||||
return tonumber(a) > tonumber(b)
|
||||
end)
|
||||
|
||||
return rocks
|
||||
end
|
||||
|
||||
function GetLatestLuaVersion()
|
||||
local rocks = GetInstalledLuaVersion()
|
||||
local preferredVersion = rocks[1]
|
||||
|
||||
local path = GetLuaPath(preferredVersion)
|
||||
|
||||
return path
|
||||
end
|
||||
|
||||
M = {}
|
||||
|
||||
M.GetLuaPath = GetLuaPath
|
||||
M.GetInstalledLuaVersion = GetInstalledLuaVersion
|
||||
M.GetLatestLuaVersion = GetLatestLuaVersion
|
||||
|
||||
return M
|
||||
33
lua/absolute/utils/detect-python-env.lua
Normal file
33
lua/absolute/utils/detect-python-env.lua
Normal file
@@ -0,0 +1,33 @@
|
||||
function CheckPoetryVirtualEnv()
|
||||
local poetry = vim.fn.system("poetry env info -p 2>/dev/null")
|
||||
if poetry == "" then
|
||||
return nil
|
||||
end
|
||||
return poetry
|
||||
end
|
||||
|
||||
function ResolvePythonEnvironment()
|
||||
-- Get system global python env
|
||||
local python = vim.fn.system("which python3")
|
||||
-- Check of virtual environments exists
|
||||
local virtual = os.getenv("VIRTUAL_ENV") or os.getenv("CONDA_PREFIX") or CheckPoetryVirtualEnv()
|
||||
|
||||
if virtual == nil then
|
||||
-- Check if poetry environment exists
|
||||
|
||||
return {
|
||||
"--python-executable", python
|
||||
}
|
||||
end
|
||||
|
||||
return {
|
||||
"--python-executable", virtual .. "/bin/python"
|
||||
}
|
||||
end
|
||||
|
||||
M = {}
|
||||
|
||||
M.ResolvePythonEnvironment = ResolvePythonEnvironment
|
||||
M.CheckPoetryVirtualEnv = CheckPoetryVirtualEnv
|
||||
|
||||
return M
|
||||
Reference in New Issue
Block a user