Merge branch 'nvim-develop' of git.pro100code.ru:t0xa/t0vim into nvim-develop
This commit is contained in:
commit
835d2fa3c4
6 changed files with 117 additions and 10 deletions
|
@ -1 +0,0 @@
|
||||||
print("Hello from golang file")
|
|
59
lua/custom/README.md
Normal file
59
lua/custom/README.md
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
# Справка по интересным моментам в коде
|
||||||
|
## Функция получения версии `python` в `lsp.lua`
|
||||||
|
|
||||||
|
```lua
|
||||||
|
local function get_python_version()
|
||||||
|
local handle = io.popen("python --version 2>&1") -- Redirect stderr to stdout
|
||||||
|
if handle then
|
||||||
|
local result = handle:read("*a")
|
||||||
|
handle:close()
|
||||||
|
-- Check if the output contains a version number
|
||||||
|
local version = result:match("Python (%d+%.%d+%.%d+)")
|
||||||
|
if version then
|
||||||
|
return version
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
handle = io.popen("python3 --version 2>&1") -- Redirect stderr to stdout
|
||||||
|
if handle then
|
||||||
|
local result = handle:read("*a")
|
||||||
|
handle:close()
|
||||||
|
-- Check if the output contains a version number
|
||||||
|
local version = result:match("Python (%d+%.%d+%.%d+)")
|
||||||
|
if version then
|
||||||
|
return version
|
||||||
|
end
|
||||||
|
end
|
||||||
|
-- TODO: Add some exception handling if python not installed on user machine
|
||||||
|
return "Python 0.0.0"
|
||||||
|
end
|
||||||
|
```
|
||||||
|
Что тут есть примечательного:
|
||||||
|
- Получение данных, выполняя команду в shell оболочке системы с помощью
|
||||||
|
`io.popen`. *Важно*: Данная функция может работать не во всех ОС
|
||||||
|
- Функция выполняет команду, указанную в аргументе, и возвращает *файловый
|
||||||
|
дескриптор*, который можно использовать для чтения вывода команды (или
|
||||||
|
записи в нее)
|
||||||
|
|
||||||
|
Разберем флоу подробнее:
|
||||||
|
Если про `python --version` - все понятно, то вот:
|
||||||
|
```lua
|
||||||
|
2>&1
|
||||||
|
```
|
||||||
|
Уже надо прояснить:
|
||||||
|
- В UNIX-подобных системах есть три стандартных потока - `stdin` = 0; `stdout` = 1;
|
||||||
|
`strerr` = 2;
|
||||||
|
- По умолчанию `io.popen` передает только вывод `stdout` в handle, поэтому для обработки
|
||||||
|
ошибок, надо дополнительно захватывать поток `stderr`
|
||||||
|
- `2>&1` означает, что мы хотим перенаправить поток ошибок 2 в стандартный вывод 1;
|
||||||
|
- Это нужно для того, чтобы захватить не только вывод команды, но и возможные ошибки
|
||||||
|
(например если питон не установлен);
|
||||||
|
- `>&` - оператор перенаправления потоков.
|
||||||
|
|
||||||
|
Дополнительно:
|
||||||
|
`*a` внутри `read` - конструкция формата чтения файловых объектов в `Lua`. Они
|
||||||
|
указывают - как именно стоит читать данные из файла или потока. Помимо `a` есть
|
||||||
|
еще:
|
||||||
|
- `*a` - читать все содержимое
|
||||||
|
- `*l` - читать строку
|
||||||
|
- `*n` - читать число.
|
|
@ -92,13 +92,42 @@ local ensure_installed = {
|
||||||
"prettier",
|
"prettier",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
local function get_python_version()
|
||||||
|
local handle = io.popen("python --version 2>&1") -- Redirect stderr to stdout
|
||||||
|
if handle then
|
||||||
|
local result = handle:read("*a")
|
||||||
|
handle:close()
|
||||||
|
-- Check if the output contains a version number
|
||||||
|
local version = result:match("Python (%d+%.%d+%.%d+)")
|
||||||
|
if version then
|
||||||
|
return version
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
handle = io.popen("python3 --version 2>&1") -- Redirect stderr to stdout
|
||||||
|
if handle then
|
||||||
|
local result = handle:read("*a")
|
||||||
|
handle:close()
|
||||||
|
-- Check if the output contains a version number
|
||||||
|
local version = result:match("Python (%d+%.%d+%.%d+)")
|
||||||
|
if version then
|
||||||
|
return version
|
||||||
|
end
|
||||||
|
end
|
||||||
|
-- TODO: Add some exception handling if python not installed on user machine
|
||||||
|
return "Python 0.0.0"
|
||||||
|
end
|
||||||
|
|
||||||
-- Now we need to make things work in Astra
|
-- Now we need to make things work in Astra
|
||||||
-- Main Astra cockblock - low python version, that prevents installation of
|
-- Main Astra cockblock - low python version, that prevents installation of
|
||||||
-- some modules, so in order to prevent mason from whining - disable some
|
-- some modules, so in order to prevent mason from whining - disable some
|
||||||
-- autoinstall modules depending on currently installed python version
|
-- autoinstall modules depending on currently installed python version
|
||||||
-- NOTE: You must install removed dependencies manually
|
-- NOTE: You must install removed dependencies manually
|
||||||
local python_version = io.popen("python --version"):read("*a")
|
local python_version = get_python_version()
|
||||||
local _, minor, _ = python_version:match("Python (%d+)%.(%d+)%.(%d+)")
|
if python_version == nil then
|
||||||
|
python_version = "Python 3.13"
|
||||||
|
end
|
||||||
|
local _, minor, _ = python_version:match(".*(%d+)%.(%d+)%.(%d+)")
|
||||||
if tonumber(minor) < 8 then
|
if tonumber(minor) < 8 then
|
||||||
for i, k in pairs(servers_to_install) do
|
for i, k in pairs(servers_to_install) do
|
||||||
-- Ruff is not supported for python lower than 3.8
|
-- Ruff is not supported for python lower than 3.8
|
||||||
|
|
|
@ -8,13 +8,13 @@ ls.config.set_config {
|
||||||
store_selection_keys = "<c-s>",
|
store_selection_keys = "<c-s>",
|
||||||
}
|
}
|
||||||
|
|
||||||
vim.keymap.set({ "i", "s" }, "<c-k>", function()
|
vim.keymap.set({ "i", "s" }, "<c-j>", function()
|
||||||
if ls.expand_or_jumpable() then
|
if ls.expand_or_jumpable() then
|
||||||
ls.expand_or_jump()
|
ls.expand_or_jump()
|
||||||
end
|
end
|
||||||
end, { silent = true })
|
end, { silent = true })
|
||||||
|
|
||||||
vim.keymap.set({ "i", "s" }, "<c-j>", function()
|
vim.keymap.set({ "i", "s" }, "<c-k>", function()
|
||||||
if ls.jumpable() then
|
if ls.jumpable() then
|
||||||
ls.jump(-1)
|
ls.jump(-1)
|
||||||
end
|
end
|
||||||
|
|
|
@ -14,6 +14,24 @@ local fmta = require("luasnip.extras.fmt").fmta
|
||||||
local rep = require("luasnip.extras").rep
|
local rep = require("luasnip.extras").rep
|
||||||
|
|
||||||
ls.add_snippets("python", {
|
ls.add_snippets("python", {
|
||||||
|
s(
|
||||||
|
{ trig = "ctable", dscr = "Create method or function with test stub" },
|
||||||
|
fmt(
|
||||||
|
[[
|
||||||
|
{} = Table(
|
||||||
|
"{}",
|
||||||
|
metadata_obj,
|
||||||
|
Column("id", Integer, primary_key=True),
|
||||||
|
{}
|
||||||
|
)
|
||||||
|
]],
|
||||||
|
{
|
||||||
|
i(1),
|
||||||
|
rep(1),
|
||||||
|
i(0)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
),
|
||||||
s({ trig = "cmethod", dscr = "Create method or function with test stub" },
|
s({ trig = "cmethod", dscr = "Create method or function with test stub" },
|
||||||
fmta(
|
fmta(
|
||||||
[[
|
[[
|
||||||
|
|
|
@ -13,8 +13,8 @@ opt.number = true
|
||||||
opt.relativenumber = true
|
opt.relativenumber = true
|
||||||
|
|
||||||
-- Tabulation and indentation settings
|
-- Tabulation and indentation settings
|
||||||
opt.shiftwidth = 2 -- Set spaces for tabs == 2
|
opt.shiftwidth = 2 -- Set spaces for tabs == 2
|
||||||
opt.tabstop = 2 -- Set spaces for indent with == 2
|
opt.tabstop = 2 -- Set spaces for indent with == 2
|
||||||
opt.expandtab = true -- use number of spaces to insert a <Tab>
|
opt.expandtab = true -- use number of spaces to insert a <Tab>
|
||||||
opt.softtabstop = 2
|
opt.softtabstop = 2
|
||||||
|
|
||||||
|
@ -24,3 +24,5 @@ opt.swapfile = false
|
||||||
-- Add line at 80 symbols
|
-- Add line at 80 symbols
|
||||||
opt.colorcolumn = "80"
|
opt.colorcolumn = "80"
|
||||||
|
|
||||||
|
-- config to set up clipboard as default register
|
||||||
|
opt.clipboard:append("unnamedplus")
|
||||||
|
|
Loading…
Reference in a new issue