@@ -27,7 +27,7 @@ use tower_lsp::lsp_types::*;
2727use crate :: Backend ;
2828use crate :: code_actions:: { CodeActionData , make_code_action_data} ;
2929use crate :: parser:: with_parsed_program;
30- use crate :: scope_collector:: { AccessKind , ScopeMap , collect_function_scope , collect_scope } ;
30+ use crate :: scope_collector:: { AccessKind , ScopeMap } ;
3131use crate :: util:: { offset_to_position, position_to_byte_offset} ;
3232
3333// ─── AST helpers ────────────────────────────────────────────────────────────
@@ -487,104 +487,15 @@ fn expression_has_side_effects(expr: &Expression<'_>) -> bool {
487487/// Build a `ScopeMap` for the file by walking the AST, identical to the
488488/// approach used in extract_variable.
489489fn build_scope_map ( content : & str , offset : u32 ) -> ScopeMap {
490- with_parsed_program ( content, "inline_variable" , |program, _content| {
491- // Try to find the enclosing function or method.
492- for stmt in program. statements . iter ( ) {
493- if let Some ( map) = try_build_scope_from_statement ( stmt, offset) {
494- return map;
495- }
496- }
497-
498- // Fallback: top-level scope.
499- let body_end = content. len ( ) as u32 ;
500- collect_scope ( program. statements . as_slice ( ) , 0 , body_end)
490+ with_parsed_program ( content, "inline_variable" , |program, content| {
491+ crate :: scope_collector:: build_scope_map_for_offset (
492+ program. statements . as_slice ( ) ,
493+ offset,
494+ content. len ( ) as u32 ,
495+ )
501496 } )
502497}
503498
504- fn try_build_scope_from_statement ( stmt : & Statement < ' _ > , offset : u32 ) -> Option < ScopeMap > {
505- match stmt {
506- Statement :: Function ( func) => {
507- let body_start = func. body . left_brace . start . offset ;
508- let body_end = func. body . right_brace . end . offset ;
509- if offset >= body_start && offset <= body_end {
510- return Some ( collect_function_scope (
511- & func. parameter_list ,
512- func. body . statements . as_slice ( ) ,
513- body_start,
514- body_end,
515- ) ) ;
516- }
517- None
518- }
519- Statement :: Class ( class) => {
520- for member in class. members . iter ( ) {
521- if let ClassLikeMember :: Method ( method) = member
522- && let MethodBody :: Concrete ( block) = & method. body
523- {
524- let body_start = block. left_brace . start . offset ;
525- let body_end = block. right_brace . end . offset ;
526- if offset >= body_start && offset <= body_end {
527- return Some ( collect_function_scope (
528- & method. parameter_list ,
529- block. statements . as_slice ( ) ,
530- body_start,
531- body_end,
532- ) ) ;
533- }
534- }
535- }
536- None
537- }
538- Statement :: Trait ( tr) => {
539- for member in tr. members . iter ( ) {
540- if let ClassLikeMember :: Method ( method) = member
541- && let MethodBody :: Concrete ( block) = & method. body
542- {
543- let body_start = block. left_brace . start . offset ;
544- let body_end = block. right_brace . end . offset ;
545- if offset >= body_start && offset <= body_end {
546- return Some ( collect_function_scope (
547- & method. parameter_list ,
548- block. statements . as_slice ( ) ,
549- body_start,
550- body_end,
551- ) ) ;
552- }
553- }
554- }
555- None
556- }
557- Statement :: Enum ( en) => {
558- for member in en. members . iter ( ) {
559- if let ClassLikeMember :: Method ( method) = member
560- && let MethodBody :: Concrete ( block) = & method. body
561- {
562- let body_start = block. left_brace . start . offset ;
563- let body_end = block. right_brace . end . offset ;
564- if offset >= body_start && offset <= body_end {
565- return Some ( collect_function_scope (
566- & method. parameter_list ,
567- block. statements . as_slice ( ) ,
568- body_start,
569- body_end,
570- ) ) ;
571- }
572- }
573- }
574- None
575- }
576- Statement :: Namespace ( ns) => {
577- for inner_stmt in ns. statements ( ) . iter ( ) {
578- if let Some ( map) = try_build_scope_from_statement ( inner_stmt, offset) {
579- return Some ( map) ;
580- }
581- }
582- None
583- }
584- _ => None ,
585- }
586- }
587-
588499// ─── Line deletion helpers ──────────────────────────────────────────────────
589500
590501/// Compute the byte range for deleting an entire statement line.
0 commit comments