Bump nixpkgs and fix some nvim stuff (#70)

This commit is contained in:
Patrick Stevens
2024-08-28 20:00:31 +01:00
committed by GitHub
parent 5c872e2c4a
commit 3ae9cebd58
4 changed files with 64 additions and 19 deletions

View File

@@ -279,7 +279,6 @@
nixpkgs.hledger
nixpkgs.hledger-web
dotnet
nixpkgs.jitsi-meet
nixpkgs.elan
nixpkgs.coreutils-prefixed
nixpkgs.shellcheck

View File

@@ -218,11 +218,38 @@ local function nuGetVersionToString(v)
end
end
local function get_all_variables()
local variables = {}
local lines = vim.api.nvim_buf_get_lines(0, 0, -1, false)
for _, line in ipairs(lines) do
local var_name, var_value = line:match("<(%w+)>([^<]+)</(%w+)>")
if var_name and var_value then
variables[var_name] = var_value
end
end
return variables
end
local function resolve_variable(version, variables)
if version:match("^%$%((.+)%)$") then
local var_name = version:match("^%$%((.+)%)$")
return variables[var_name] or nil
end
return nil
end
---@param v string
---@nodiscard
---@return NuGetVersion
local function parse_version(v)
local variables = get_all_variables()
local major, minor, patch, pre = v:match("(%d+)%.(%d+)%.(%d+)(.*)$")
if major == nil then
local resolved = resolve_variable(v, variables)
if resolved ~= nil then
return parse_version(resolved)
end
end
-- TODO: why does this type-check if you remove the field names?
return {
major = tonumber(major) or 0,
@@ -631,6 +658,14 @@ local function prefetch_dependencies()
end
end
---@param v1 NuGetVersion
---@param v2 NuGetVersion
---@return boolean
---@nodiscard
local function nuget_versions_equal(v1, v2)
return v1.major == v2.major and v1.minor == v2.minor and v1.patch == v2.patch and v1.suffix == v2.suffix
end
vim.api.nvim_create_autocmd("FileType", {
pattern = { "fsharp_project", "csharp_project", "xml" },
callback = function()
@@ -638,13 +673,17 @@ vim.api.nvim_create_autocmd("FileType", {
local line = vim.api.nvim_get_current_line()
local package_name = line:match('PackageReference Include="([^"]+)"')
or line:match('PackageReference Update="([^"]+)"')
local current_version = nuGetVersionToString(line:match('Version="([^"]+)"'))
if not package_name then
print("No package reference found on the current line")
return
end
local current_version = parse_version(line:match('Version="([^"]+)"'))
if not current_version then
print("oh no!")
end
local package_versions = get_package_versions_sync(package_name)
if #package_versions == 0 then
@@ -664,7 +703,7 @@ vim.api.nvim_create_autocmd("FileType", {
entry_maker = function(entry)
local val = nuGetVersionToString(entry)
local display_value = val
if current_version and entry == current_version then
if current_version and nuget_versions_equal(entry, current_version) then
display_value = "[CURRENT] " .. val
end
return {
@@ -696,7 +735,11 @@ vim.api.nvim_create_autocmd("FileType", {
for dep, range in pairs(package_dependencies) do
table.insert(display, dep .. ": " .. range)
end
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, display)
local ok, err = pcall(vim.api.nvim_buf_set_lines, bufnr, 0, -1, false, display)
if not ok then
-- If we can't set lines, the window's probably gone. Ignore.
return
end
end)
end,
}),

View File

@@ -53,6 +53,9 @@ require("lspconfig")["ltex"].setup({})
require("lspconfig")["lua_ls"].setup({
on_init = function(client)
if not client.workspace_folders then
return
end
local path = client.workspace_folders[1].name
if vim.uv.fs_stat(path .. "/.luarc.json") or vim.loop.fs_stat(path .. "/.luarc.jsonc") then
return