Conversation
There was a problem hiding this comment.
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.
| 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 |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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)
| if workspace_toml then | ||
| tomlfile:write(workspace_toml) | ||
| tomlfile:print("") | ||
| end |
#7605