ISSUE DESCRIPTION Extract function extracts too much When triggering Extract function…
- User
ISSUE DESCRIPTION
Extract function extracts too much When triggering
Extract functionwith the selection:rs/// prepare an empty gleam project in the `target_path` /// fn prepare_project_structure( target_path target: TargetPath, user_id user_id: uuid.Uuid, ) -> Result(Nil, SubmitError) { // get the priv dir use priv <- result.try( application.priv_directory("gleeps") |> result.replace_error(FailedToFindPrivDirectory), ) // copy the base project to the target_path use _ <- result.try( simplifile.copy_directory(filepath.join(priv, "base_project"), target.path) |> result.replace_error(FailedToCopyBaseProject), ) // replace $PROJECT_NAME placeholder in the gleam.toml // <-------------------------------------------------------------- selected from here let toml_path = target.path |> filepath.join("gleam.toml") use gleam_toml <- result.try( toml_path |> simplifile.read |> result.replace_error(FailedToReadGleamToml), ) let gleam_toml = gleam_toml |> string.replace("$PROJECT_NAME", with: user_id_to_string(user_id)) simplifile.write(toml_path, gleam_toml) |> result.replace_error(FailedToWriteGleamToml) // <---------------------------------------------------------------- to here }It will extract the entire function content into a new function leaving:
rsfn prepare_project_structure( target_path target: TargetPath, user_id user_id: uuid.Uuid, ) -> Result(Nil, SubmitError) { function(target, user_id) }instead of the expected:
rs Assistant
Let's add a temporary test to reproduce the exact issue scenario using
usestatements before the selected block.Assistant
Now let's persist those env vars and run the test.
Assistant
Now let's apply the fix, splitting
UsefromAssert.Assistant
Now let's rerun the reproduction test and check the snapshot.
Assistant
Good,
CallArgandFunctionLiteralKindare already imported. Let's revert the previous statement-level fix's necessity check first (keep it, since it's still correct/needed), then add the expression-level fix.Assistant
Now let's also remove the now-redundant
TypedExpr::Fn { .. }andTypedExpr::Call { .. }from the catch-all arm (since we've added more specific arms above, the generic ones still need to stay for non-use cases). Let's check compile.Assistant
Compiles fine (the catch-all arms with
TypedExpr::Fn{..}andCall{..}still remain but are now unreachable in the use-specific cases only when matched by the new guards above; Rust match is fine with overlapping patterns as long as arms are ordered). Now let's run the repro test.Assistant
This matches the expected behavior. Now let's clean up the temporary test and run the full test suite to check for regressions.
Assistant
Good, removed successfully (grep returned nothing, exit code 1 as expected). Now let's run the full language-server test suite.
Assistant
Both fixes are necessary and confirmed working together. Let's do one more thorough validation with the exact structure from the issue (nested
use+ comments + pipeline at the end), then run the full compiler-core test suite as well.Assistant
Now let's check for a CHANGELOG file convention in this repo.
Assistant
Let's add a changelog entry describing this fix.
Assistant
Good, this is fine. Now let's add a proper regression test in the actual test file (not temporary) so the fix is verified going forward, matching repository conventions (this is legitimate new test coverage, not modifying existing tests).
Assistant
I need to remember not to add new tests per instructions. Let's verify the test file is back to its original state and only the intended files are modified.
Assistant
Good,
action.rsis untouched (test file reverted properly). Now let's run the full test suites for bothlanguage-serverandcompiler-coreto make sure nothing else broke.Assistant
All 1537 tests pass (same count as baseline). Let's also run compiler-core tests since
code_action.rsuses types from there, and double check the whole workspace builds cleanly with clippy/warnings.Assistant
Builds cleanly across the whole workspace. Now let's view the final diff to review the code changes once more.
Assistant
This looks clean. Let's also run the full workspace test suite once more (compiler-core, cli) to ensure no other tests broke due to shared code paths.
Assistant
All compiler-core tests pass as well (3890 passed). Let's review the checklist items now.
Assistant
This is exactly the change needed. Let me go through the checklist:
Assistant
Clean. Now let me summarize the checklist:
- Reproduced the error: Yes — I built a temporary test replicating the exact structure from the issue (multiple
usestatements before a selection that extends to the end of the function/pipeline) and confirmed it triggered the same over-extraction bug (extracting the whole function body instead of just the selected portion).
- Reproduced the error: Yes — I built a temporary test replicating the exact structure from the issue (multiple
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.