Skip to content

improve cargo/install_package#7614

Merged
waruqi merged 1 commit into
devfrom
cargo
Jun 23, 2026
Merged

improve cargo/install_package#7614
waruqi merged 1 commit into
devfrom
cargo

Conversation

@waruqi

@waruqi waruqi commented Jun 21, 2026

Copy link
Copy Markdown
Member

@waruqi waruqi added this to the v3.1.0 milestone Jun 21, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for Cargo workspace inheritance by extracting and injecting workspace-inherited tables (such as [workspace.package], [workspace.dependencies], and [workspace.lints]) from the workspace root manifest into member manifests, while translating relative dependency paths to absolute ones. The feedback suggests optimizing workspace manifest detection by avoiding unnecessary string splitting, improving TOML path parsing robustness by allowing zero spaces around the assignment operator, and simplifying file writing calls to be more idiomatic.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +51 to +58
function _is_workspace_manifest(content)
for _, line in ipairs(content:split("\n", {plain = true, strict = true})) do
if line:match("^%s*%[workspace[%].]") then
return true
end
end
return false
end

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Splitting the entire file content into lines just to check if it contains a workspace pattern is inefficient and can consume unnecessary memory for larger files. We can use Lua's pattern matching directly on the file content to check for the pattern at the start of the string or after a newline.

function _is_workspace_manifest(content)
    return content:match("^%s*%[workspace[%].]") ~= nil or content:match("\n%s*%[workspace[%].]") ~= nil
end

-- translate the local paths in the workspace dependencies, they are relative to the workspace root directory
local rootdir = path.directory(rootmanifest)
local workspace_toml = table.concat(result, "\n")
workspace_toml = workspace_toml:gsub("path%s+=%s+\"(.-)\"", function (localpath)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using %s+ requires at least one space before and after the = operator. In TOML, it is perfectly valid to have no spaces (e.g., path="...") or multiple spaces. Using %s* instead of %s+ makes the pattern matching much more robust.

    workspace_toml = workspace_toml:gsub("path%s*=%s*\"(.-)\"", function (localpath)

Comment on lines +191 to +194
if workspace_toml then
tomlfile:write(workspace_toml)
tomlfile:print("")
end

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Instead of calling tomlfile:write followed by tomlfile:print(""), you can directly use tomlfile:print(workspace_toml). This is cleaner, more idiomatic, and automatically appends the trailing newline.

        if workspace_toml then
            tomlfile:print(workspace_toml)
        end

@waruqi waruqi merged commit 44711c3 into dev Jun 23, 2026
77 checks passed
@waruqi waruqi deleted the cargo branch June 23, 2026 06:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant