Extract function extracts too much When triggering Extract function with the selection:…
- User
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
I’ll trace the extract-function selection/range logic, add a regression test for this
use-before-selection case, then implement and run the focused test suite. - Assistant
The failure is tied to how
usestatements and their continuation spans interact with a selection that reaches the function’s tail. I’m reproducing that boundary case directly before changing the range predicate. - Assistant
The regression now reproduces exactly: when the selection ends at the final expression’s exclusive boundary, it shares the synthetic
usecontinuation’s end boundary, so the old “strictly inside” check mistakes both earlierusestatements as selected. I’m changing that check to key off whether the selection starts inside the statement; equal end boundaries will no longer pull the enclosing continuation into the extraction. - Assistant
The focused regression now produces the intended result: both preceding
uselines remain, the comment stays at the call site, and only the selected tail statements move. I’m checking all extract-related language-server tests now for compatibility with existinguseand anonymous-function cases.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.