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:/// 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 nightlyADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use to restore the file to its original state. You can also reset all changes in the repository using command. Additionally, you can use and to temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you call ) using or commands. However you don't need to use or before submitting your changes. In fact, only submits currently unstaged changes because it uses to get the changes that need to be submitted.
- Assistant
I’ll first inspect the repository structure and locate the extract-function implementation plus related tests. Then I’ll reproduce the selection-boundary behavior with the existing test/tooling, identify whether the bug is in range conversion, AST node selection, or edit construction, and make the smallest source-only fix. I’ll run the affected tests and review the final diff before submitting.
- Assistant
The repository is the Gleam compiler, and the issue likely lives in the language server’s code actions. I’ll now search for “extract function” and selection/range handling, then inspect the nearest unit/integration tests to understand the intended inclusive/exclusive semantics.
- Assistant
rgis unavailable in this environment, so I’ll use recursivegrepinstead; this does not affect the investigation. - Assistant
The implementation uses AST source spans converted to LSP ranges and has a suspicious boundary rule:
completely_withinis strict, whilewithin/overlapstreat endpoints as inclusive. The reported selection is line-oriented and ends at the final selected statement, so I’m checking the exact visitor logic and recent history for a known boundary regression rather than changing behavior blindly. - Assistant
The likely failure is now localized: the enclosing function body is represented as a block expression, and
can_extract_expressionrejects it only when the selection is strictly inside the block. A selection beginning inside the body but ending exactly at the body’s final statement is therefore treated as selecting the whole block, causing the block-specific extraction path to move all statements. I’ll verify this against the existing extraction tests and then adjust only block selection boundary handling so exact full-block selections retain their current behavior. - Assistant
The source change is in place and deliberately scoped to
TypedExpr::Block; ordinary expression extraction keeps the existing strict-boundary semantics. The Rust toolchain is not configured in this container, socargo testand formatting cannot run yet. I’ll check available toolchains and use static inspection plus any repository-provided binaries/scripts, then refine if needed. - Assistant
Static checks show the patch is whitespace-clean, and no Rust toolchain is installed (
rustup toolchain listis empty), so the affected test suite cannot be executed in this environment. The boundary logic now handles selections that begin within a block and end at or before its closing span, while selections beginning at the block boundary still take the original whole-block path. I’ll perform a final diff review and submit only this source change.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.