@@ -9,20 +9,25 @@ defmodule ElixirLS.LanguageServer.Providers.Rename do
99
1010 def rename ( % SourceFile { } = source_file , start_uri , line , character , new_name ) do
1111 edits =
12- with % { context: { context , char_ident } } when context in [ :local_or_var , :local_call ] <-
13- Code.Fragment . surround_context ( source_file . text , { line , character } ) ,
12+ with char_ident when not is_nil ( char_ident ) <-
13+ get_char_ident ( source_file . text , line , character ) ,
1414 % ElixirSense.Location { } = definition <-
1515 ElixirSense . definition ( source_file . text , line , character ) ,
1616 references <- ElixirSense . references ( source_file . text , line , character ) do
1717 length_old = length ( char_ident )
1818
1919 definition_references =
2020 case definition do
21- % { type: :function } ->
22- parse_definition_source_code ( definition , source_file . text )
21+ % { file: nil , type: :function } ->
22+ parse_definition_source_code ( source_file . text )
2323 |> get_all_fn_header_positions ( char_ident )
2424 |> positions_to_references ( start_uri , length_old )
2525
26+ % { file: separate_file_path , type: :function } ->
27+ parse_definition_source_code ( definition )
28+ |> get_all_fn_header_positions ( char_ident )
29+ |> positions_to_references ( SourceFile . path_to_uri ( separate_file_path ) , length_old )
30+
2631 _ ->
2732 positions_to_references (
2833 [ { definition . line , definition . column } ] ,
@@ -93,14 +98,12 @@ defmodule ElixirLS.LanguageServer.Providers.Rename do
9398 end
9499 end
95100
96- defp parse_definition_source_code ( definition , source_text )
97-
98- defp parse_definition_source_code ( % { file: nil } , source_text ) do
99- ElixirSense.Core.Parser . parse_string ( source_text , true , true , 0 )
101+ defp parse_definition_source_code ( % { file: file } ) do
102+ ElixirSense.Core.Parser . parse_file ( file , true , true , 0 )
100103 end
101104
102- defp parse_definition_source_code ( % { file: file } , _ ) do
103- ElixirSense.Core.Parser . parse_file ( file , true , true , 0 )
105+ defp parse_definition_source_code ( source_text ) when is_binary ( source_text ) do
106+ ElixirSense.Core.Parser . parse_string ( source_text , true , true , 0 )
104107 end
105108
106109 defp get_all_fn_header_positions ( parsed_source , char_ident ) do
@@ -129,4 +132,12 @@ defmodule ElixirLS.LanguageServer.Providers.Rename do
129132 end: % { line: end_line - 1 , character: end_character - 1 }
130133 }
131134 end
135+
136+ defp get_char_ident ( text , line , character ) do
137+ case Code.Fragment . surround_context ( text , { line , character } ) do
138+ % { context: { context , char_ident } } when context in [ :local_or_var , :local_call ] -> char_ident
139+ % { context: { :dot , _ , char_ident } } -> char_ident
140+ _ -> nil
141+ end
142+ end
132143end
0 commit comments