Extract function extracts too much When triggering Extract function with the selection:…
- User
Extract function extracts too much When triggering
Extract functionwith the selection:/// 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:
fn prepare_project_structure( target_path target: TargetPath, user_id user_id: uuid.Uuid, ) -> Result(Nil, SubmitError) { function(target, user_id) }instead of the expected:
/// 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 function(target, user_id) } fn function( target: TargetPath, user_id: uuid.Uuid, ) -> Result(Nil, SubmitError) { 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) }Using gleam
1.16.0in neovim nightlyInterface
No new interfaces are introduced.
- Assistant
Now let me look at the existing extract function tests to understand the test setup and reproduce the issue.
- Assistant
Let me add a reproduction test:
- Assistant
TypedStatement::Uselocation spans the entire rest of the block. Now let me check the test position helpers to craft a selection ending exactly at the end of the block: - Assistant
Still captured — now the desugared
Callexpression is being extracted instead. Let me check what location the desugared use call has: - Assistant
The output is now correct. Accept the snapshot and run the full test suite to check for regressions:
- Assistant
All 1537 existing tests pass; only the new snapshot is pending.
cargo-instaisn't installed, so accept the snapshot manually: - Assistant
All 1538 existing tests pass and the nested-use case now produces the correct extraction. Accept the snapshot:
- Assistant
All 1539 tests pass. Now let me update the changelog:
- Assistant
Let me fix the attribution — I shouldn't credit someone who didn't write this:
- Assistant
This now produces exactly the expected result. Accept the snapshot and run the whole suite:
- Assistant
Everything is green. Let me review the final diff:
- Assistant
One problem: I referenced issue
#4919in test comments but haven't verified that number. Let me check: - Assistant
The real issue is #5700. Fix the references:
- Assistant
Fixed. The bug had three interacting causes, all stemming from the fact that a
useexpression's desugared AST nodes span the entire rest of the enclosing block:Root cause
When a selection inside a
usecallback extends to the last statement of the block, the selection's end coincides exactly with the end of the statement's span. The existing check requires strict containment on both ends, so it incorrectly concluded the whole was selected — extracting the entire function body.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.