Skip to content

fix: invalid dependency section warnings #160

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 19, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 55 additions & 52 deletions lua/crates/toml.lua
Original file line number Diff line number Diff line change
Expand Up @@ -267,72 +267,76 @@ end
function M.parse_section(text, line_nr, header_col)
---@type string, integer, string
local prefix, suffix_s, suffix = text:match("^(.*)dependencies()(.*)$")
if prefix and suffix then
prefix = vim.trim(prefix)
suffix = vim.trim(suffix)
---@type TomlSection
local section = {
text = text,
invalid = false,
kind = TomlSectionKind.DEFAULT,
---end bound is assigned when the section ends
---@diagnostic disable-next-line: param-type-mismatch
lines = Span.new(line_nr, nil),
header_col = header_col,
}
if not (prefix and suffix) then
return nil
end

local target = prefix
prefix = vim.trim(prefix)
suffix = vim.trim(suffix)

---@type TomlSection
local section = {
text = text,
invalid = false,
kind = TomlSectionKind.DEFAULT,
---end bound is assigned when the section ends
---@diagnostic disable-next-line: param-type-mismatch
lines = Span.new(line_nr, nil),
header_col = header_col,
}

local dev_target = prefix:match("^(.*)dev%-$")
if dev_target then
target = vim.trim(dev_target)
section.kind = TomlSectionKind.DEV
end
local target = prefix

local build_target = prefix:match("^(.*)build%-$")
if build_target then
target = vim.trim(build_target)
section.kind = TomlSectionKind.BUILD
end
local dev_target = prefix:match("^(.*)dev%-$")
if dev_target then
target = vim.trim(dev_target)
section.kind = TomlSectionKind.DEV
end

local workspace_target = target:match("^(.*)workspace%s*%.$")
if workspace_target then
section.workspace = true
target = vim.trim(workspace_target)
end
local build_target = prefix:match("^(.*)build%-$")
if build_target then
target = vim.trim(build_target)
section.kind = TomlSectionKind.BUILD
end

if target then
local t = target:match("^target%s*%.(.+)%.$")
if t then
section.target = vim.trim(t)
target = ""
end
end
local workspace_target = target:match("^(.*)workspace%s*%.$")
if workspace_target then
section.workspace = true
target = vim.trim(workspace_target)
end

if suffix then
local n_s, n, n_e = suffix:match("^%.%s*()(.+)()%s*$")
if n then
section.name = vim.trim(n)
local offset = header_col.s + 1 + suffix_s - 1
section.name_col = Span.new(n_s - 1 + offset, n_e - 1 + offset)
suffix = ""
end
if target ~= "" then
local t = target:match("^target%s*%.(.+)%.$")
if t then
section.target = vim.trim(t)
target = ""
else
-- not a depndency section
return nil
end
end

section.invalid = (target ~= "" or suffix ~= "")
or (section.workspace and section.kind ~= TomlSectionKind.DEFAULT)
or (section.workspace and section.target ~= nil)

return Section.new(section)
if suffix then
local n_s, n, n_e = suffix:match("^%.%s*()(.+)()%s*$")
if n then
section.name = vim.trim(n)
local offset = header_col.s + 1 + suffix_s - 1
section.name_col = Span.new(n_s - 1 + offset, n_e - 1 + offset)
suffix = ""
end
end

return nil
section.invalid = (suffix ~= "")
or (section.workspace and section.kind ~= TomlSectionKind.DEFAULT)
or (section.workspace and section.target ~= nil)

return Section.new(section)
end

---@param name string
---@return string
local function table_bool_pattern(name)
return "^%s*".. name .. "%s*=%s*()([^%s]*)()%s*$"
return "^%s*" .. name .. "%s*=%s*()([^%s]*)()%s*$"
end

---@param name string
Expand Down Expand Up @@ -677,7 +681,6 @@ function M.parse_crates(buf)
dep_section_crate = dep_section_crate or empty_crate
dep_section_crate.feat = feat
end

elseif dep_section then
local crate = M.parse_inline_crate(line, line_nr)
if crate then
Expand Down