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
I'll start by exploring the repository structure to locate the extract function implementation.
- Assistant
Let me search for the extract function implementation in the language server.
- Assistant
Found relevant files. Let me look at the code_action.rs file for extract function logic.
- Assistant
There's ExtractVariable. Let me search more specifically for Extract Function.
- Assistant
Let me read the ExtractFunction implementation thoroughly.
- Assistant
Continuing to read the ExtractFunction implementation.
- Assistant
Let me continue reading the code_actions method and the visitor.
- Assistant
Looking at the visitor implementation where selection detection happens.
- Assistant
Let me look at
can_extract_statementand how use statements are handled. - Assistant
Inspecting how
usestatements are visited and the helpers for range checks. - Assistant
Let me look at the visit_typed_statement for ExtractFunction more carefully.
- Assistant
I need to understand how Use statements and their locations work.
- Assistant
Let me look at the Use struct and Statement location for Use.
- Assistant
Checking how Visiting typed use works by default.
- Assistant
Let me read those functions.
- Assistant
Let me read the rest of visit_typed_statement and related methods.
- Assistant
I need to open the correct file again.
- Assistant
Checking how typed functions and their bodies are visited.
- Assistant
Let me read visit_typed_expr_fn.
- Assistant
Looking at existing tests related to extract function and use.
- Assistant
Let me search more specifically for extract function use tests.
- Assistant
There might be more tests. Let me get more of them.
- Assistant
There may be more after those. Let me check.
- Assistant
Hmm only 18 extract function tests. Let me look for more tests after partially_selected and also search for "use" within the extract section.
- Assistant
Let me look at how tests work so I can reproduce the bug.
- Assistant
Let me look at the ASSERT_CODE_ACTION macro and how snapshots work.
- Assistant
Let me look at GitHub issues related to this and also check
within/completely_withinhelpers. - Assistant
Let me look at the range helpers carefully.
- Assistant
I need to check the location of desugared use calls.
- Assistant
Let me look at how use is typed.
- Assistant
Checking statement sequence location.
- Assistant
Let me look at line 759 and surrounding context.
- Assistant
Looking at how extracting Use was previously fixed, and what
can_extract_expressionshould exclude. - Assistant
Let me check existing extract-use snapshots and code related to use fn kind.
- Assistant
There's special handling at line 10676 and around line 808. Let me check those.
- Assistant
Let me look at how extract_code_in_tail_position works and the function creation.
- Assistant
I'll write a temporary test that reproduces the issue from the report.
- Assistant
I'll add a temporary test to reproduce the bug, then remove it before submitting.
- Assistant
I accidentally ruptured the previous test. Let me fix that.
- Assistant
Checking how other tests use
result.tryand whether stdlib is available. - Assistant
Looking at how other try tests work around line 7411.
- Assistant
Simplifying the temp test to match existing patterns.
- Assistant
Running the reproduction test.
- Assistant
Need to set up rustup first.
- Assistant
Now let's run the test.
- Assistant
Need toţa use the hyphenated package name.
- Assistant
Selection in my test ended at the start of
write. Let me match the full end of the last expression. - Assistant
Hmm empty. Let me search more carefully.
- Assistant
Let me look at that.
- Assistant
I'll update the test to select through the end of the last expression.
- Assistant
I edited the wrong file. Fixing that.
- Assistant
Good tests.rs is fixed. Now update action.rs.
- Assistant
Cleaning leftover snapshot and re-running the test.
- Assistant
Checking how SrcSpan maps to LSP ranges.
- Assistant
Let me broaden the search.
- Assistant
Let me find the definition.
- Assistant
Let me look at that.
- Assistant
Checking SrcSpan and how line/column numbers are computed.
- Assistant
Let me look at both.
- Assistant
Searching for a GitHub issue that matches this bug report.
- Assistant
Let me read the changelog for 1.17 about extract function.
- Assistant
The selection ends on a comment after the last statement—that’s likely the bug. Verifying.
- Assistant
I keep editing the wrong file. Using
--fileexplicitly. - Assistant
Now run the test again.
- Assistant
Bug reproduced. I'll fix
can_extract_expressionso use-desugared calls/fns aren't treated as extractable expressions. - Assistant
Checking how to detect use-related expressions.
- Assistant
Let me look at is_use_implicit_callback.
- Assistant
Looking at the partially selected test and related snapshots to understand intended behavior.
- Assistant
There's already a related test. Let me check those snapshots.
- Assistant
Looking at how the extracted location is used for generating the edits.
- Assistant
Implementing the fix in
can_extract_expression. - Assistant
Cleaning up the comment typos and verifying imports.
- Assistant
Running the reproduction test to verify the fix.
- Assistant
Checking whether my changes compiled and adding debug insight.
- Assistant
Forcing a rebuild to ensure code changes are picked up.
- Assistant
Verifying the file has my changes and forcing a clean rebuild.
- Assistant
Typo in command: head-40 instead of head -40.
- Assistant
Forcing a full rebuild.
- Assistant
Checking TypedStatement.so location for Use.
- Assistant
The real issue is that Use's
statement.location()spans the whole body. Fixingcan_extract_statementfor Use. - Assistant
Running the reproduction test again.
- Assistant
Looking good. Checking the full snapshot output.
- Assistant
Fix works. Running existing extract-function tests and cleaning up the temporary test.
- Assistant
175 extract-related tests passed. Running use-specific extractmachen tests and cleaning up.
- Assistant
Cleaning up the temporary test and leftover snapshot files.
- Assistant
Reviewing the final diff.
- Assistant
Verifying a couple more edge cases quickly.
- Assistant
Run the edge tests.
- Assistant
First edge case works. Checking the second by accepting the first snapshot partially.
- Assistant
Both edge cases Work. Cleaning up temporary tests.
- Assistant
The test filter failed due to shell piping. Re-running properly.
- Assistant
Checking whether the blank line between tests was restored.
- Assistant
Checking the original blank line around that region.
- Assistant
Restoring the blank line after the Expression match arm for consistent stile.
- Assistant
I may have broken the match statement. Checking the full function.
- Assistant
Restoring the missing
match statement {. - Assistant
Final verification of compile and tests.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.