@@ -40,7 +40,7 @@ use crate::syntax::ast::StmtP;
40
40
use crate :: syntax:: uniplate:: Visit ;
41
41
use crate :: syntax:: AstModule ;
42
42
43
- /// The location of a definition for a given identifier. See [`AstModule::find_definition `].
43
+ /// The location of a definition for a given identifier. See [`AstModule::find_definition_at_location `].
44
44
#[ derive( Debug , Clone , Eq , PartialEq ) ]
45
45
pub ( crate ) enum IdentifierDefinition {
46
46
/// The definition was found at this location in the current file.
@@ -224,7 +224,7 @@ impl LspModule {
224
224
///
225
225
/// This method also handles scoping properly (i.e. an access of "foo" in a function
226
226
/// will return location of the parameter "foo", even if there is a global called "foo").
227
- pub ( crate ) fn find_definition ( & self , line : u32 , col : u32 ) -> Definition {
227
+ pub ( crate ) fn find_definition_at_location ( & self , line : u32 , col : u32 ) -> Definition {
228
228
// TODO(nmj): This should probably just store references to all of the AST nodes
229
229
// when the LSPModule object is created, and then we can do a much faster
230
230
// lookup, especially in cases where a file has not been changed, so the
@@ -501,8 +501,11 @@ impl LspModule {
501
501
symbol_to_lookup
502
502
. and_then ( |span| {
503
503
let resolved = self . ast . codemap . resolve_span ( span) ;
504
- self . find_definition ( resolved. begin_line as u32 , resolved. begin_column as u32 )
505
- . local_destination ( )
504
+ self . find_definition_at_location (
505
+ resolved. begin_line as u32 ,
506
+ resolved. begin_column as u32 ,
507
+ )
508
+ . local_destination ( )
506
509
} )
507
510
. or_else ( || match ( arg_span, identifier_span) {
508
511
( Some ( span) , _) => Some ( self . ast . codemap . resolve_span ( span) ) ,
@@ -807,15 +810,15 @@ mod test {
807
810
. into ( ) ;
808
811
assert_eq ! (
809
812
expected,
810
- module. find_definition ( parsed. begin_line( "p1" ) , parsed. begin_column( "p1" ) )
813
+ module. find_definition_at_location ( parsed. begin_line( "p1" ) , parsed. begin_column( "p1" ) )
811
814
) ;
812
815
assert_eq ! (
813
816
expected,
814
- module. find_definition ( parsed. begin_line( "p2" ) , parsed. begin_column( "p2" ) )
817
+ module. find_definition_at_location ( parsed. begin_line( "p2" ) , parsed. begin_column( "p2" ) )
815
818
) ;
816
819
assert_eq ! (
817
820
expected,
818
- module. find_definition ( parsed. begin_line( "p3" ) , parsed. begin_column( "p3" ) )
821
+ module. find_definition_at_location ( parsed. begin_line( "p3" ) , parsed. begin_column( "p3" ) )
819
822
) ;
820
823
Ok ( ( ) )
821
824
}
@@ -856,28 +859,28 @@ mod test {
856
859
857
860
assert_eq ! (
858
861
expected_add,
859
- module. find_definition ( parsed. begin_line( "a1" ) , parsed. begin_column( "a1" ) )
862
+ module. find_definition_at_location ( parsed. begin_line( "a1" ) , parsed. begin_column( "a1" ) )
860
863
) ;
861
864
assert_eq ! (
862
865
expected_add,
863
- module. find_definition ( parsed. begin_line( "a2" ) , parsed. begin_column( "a2" ) )
866
+ module. find_definition_at_location ( parsed. begin_line( "a2" ) , parsed. begin_column( "a2" ) )
864
867
) ;
865
868
assert_eq ! (
866
869
expected_add,
867
- module. find_definition ( parsed. begin_line( "a3" ) , parsed. begin_column( "a3" ) )
870
+ module. find_definition_at_location ( parsed. begin_line( "a3" ) , parsed. begin_column( "a3" ) )
868
871
) ;
869
872
870
873
assert_eq ! (
871
874
expected_invalid,
872
- module. find_definition ( parsed. begin_line( "i1" ) , parsed. begin_column( "i1" ) )
875
+ module. find_definition_at_location ( parsed. begin_line( "i1" ) , parsed. begin_column( "i1" ) )
873
876
) ;
874
877
assert_eq ! (
875
878
expected_invalid,
876
- module. find_definition ( parsed. begin_line( "i2" ) , parsed. begin_column( "i2" ) )
879
+ module. find_definition_at_location ( parsed. begin_line( "i2" ) , parsed. begin_column( "i2" ) )
877
880
) ;
878
881
assert_eq ! (
879
882
expected_invalid,
880
- module. find_definition ( parsed. begin_line( "i3" ) , parsed. begin_column( "i3" ) )
883
+ module. find_definition_at_location ( parsed. begin_line( "i3" ) , parsed. begin_column( "i3" ) )
881
884
) ;
882
885
Ok ( ( ) )
883
886
}
@@ -912,7 +915,10 @@ mod test {
912
915
source: parsed. span( "x_param" ) ,
913
916
destination: parsed. span( "x" )
914
917
} ) ,
915
- module. find_definition( parsed. begin_line( "x_param" ) , parsed. begin_column( "x_param" ) )
918
+ module. find_definition_at_location(
919
+ parsed. begin_line( "x_param" ) ,
920
+ parsed. begin_column( "x_param" )
921
+ )
916
922
) ;
917
923
Ok ( ( ) )
918
924
}
@@ -947,29 +953,41 @@ mod test {
947
953
source: parsed. span( "x_var" ) ,
948
954
destination: parsed. span( "x" )
949
955
} ) ,
950
- module. find_definition( parsed. begin_line( "x_var" ) , parsed. begin_column( "x_var" ) )
956
+ module. find_definition_at_location(
957
+ parsed. begin_line( "x_var" ) ,
958
+ parsed. begin_column( "x_var" )
959
+ )
951
960
) ;
952
961
assert_eq ! (
953
962
Definition :: from( IdentifierDefinition :: Location {
954
963
source: parsed. span( "y_var1" ) ,
955
964
destination: parsed. span( "y2" )
956
965
} ) ,
957
- module. find_definition( parsed. begin_line( "y_var1" ) , parsed. begin_column( "y_var1" ) )
966
+ module. find_definition_at_location(
967
+ parsed. begin_line( "y_var1" ) ,
968
+ parsed. begin_column( "y_var1" )
969
+ )
958
970
) ;
959
971
960
972
assert_eq ! (
961
973
Definition :: from( IdentifierDefinition :: Location {
962
974
source: parsed. span( "y_var2" ) ,
963
975
destination: parsed. span( "y1" )
964
976
} ) ,
965
- module. find_definition( parsed. begin_line( "y_var2" ) , parsed. begin_column( "y_var2" ) )
977
+ module. find_definition_at_location(
978
+ parsed. begin_line( "y_var2" ) ,
979
+ parsed. begin_column( "y_var2" )
980
+ )
966
981
) ;
967
982
assert_eq ! (
968
983
Definition :: from( IdentifierDefinition :: Unresolved {
969
984
source: parsed. span( "z_var" ) ,
970
985
name: "z" . to_owned( )
971
986
} ) ,
972
- module. find_definition( parsed. begin_line( "z_var" ) , parsed. begin_column( "z_var" ) )
987
+ module. find_definition_at_location(
988
+ parsed. begin_line( "z_var" ) ,
989
+ parsed. begin_column( "z_var" )
990
+ )
973
991
) ;
974
992
Ok ( ( ) )
975
993
}
@@ -1001,7 +1019,10 @@ mod test {
1001
1019
1002
1020
assert_eq ! (
1003
1021
Definition :: from( IdentifierDefinition :: NotFound ) ,
1004
- module. find_definition( parsed. begin_line( "no_def" ) , parsed. begin_column( "no_def" ) )
1022
+ module. find_definition_at_location(
1023
+ parsed. begin_line( "no_def" ) ,
1024
+ parsed. begin_column( "no_def" )
1025
+ )
1005
1026
) ;
1006
1027
1007
1028
Ok ( ( ) )
@@ -1060,7 +1081,8 @@ mod test {
1060
1081
source : parsed. span ( & format ! ( "{}_click" , name) ) ,
1061
1082
literal : name. to_owned ( ) ,
1062
1083
} ) ;
1063
- let actual = module. find_definition ( parsed. begin_line ( name) , parsed. begin_column ( name) ) ;
1084
+ let actual = module
1085
+ . find_definition_at_location ( parsed. begin_line ( name) , parsed. begin_column ( name) ) ;
1064
1086
1065
1087
assert_eq ! (
1066
1088
expected, actual,
@@ -1123,7 +1145,10 @@ mod test {
1123
1145
} ;
1124
1146
1125
1147
let find_definition = |span_id : & str | {
1126
- module. find_definition ( parsed. begin_line ( span_id) , parsed. begin_column ( span_id) )
1148
+ module. find_definition_at_location (
1149
+ parsed. begin_line ( span_id) ,
1150
+ parsed. begin_column ( span_id) ,
1151
+ )
1127
1152
} ;
1128
1153
1129
1154
let expected_foo = expected ( "foo" , & [ "foo" ] ) ;
@@ -1177,7 +1202,10 @@ mod test {
1177
1202
} ;
1178
1203
1179
1204
let find_definition = |span_id : & str | {
1180
- module. find_definition ( parsed. begin_line ( span_id) , parsed. begin_column ( span_id) )
1205
+ module. find_definition_at_location (
1206
+ parsed. begin_line ( span_id) ,
1207
+ parsed. begin_column ( span_id) ,
1208
+ )
1181
1209
} ;
1182
1210
1183
1211
let expected_foo = expected ( "foo" , & [ "foo" ] ) ;
@@ -1228,7 +1256,10 @@ mod test {
1228
1256
} ;
1229
1257
1230
1258
let find_definition = |span_id : & str | {
1231
- module. find_definition ( parsed. begin_line ( span_id) , parsed. begin_column ( span_id) )
1259
+ module. find_definition_at_location (
1260
+ parsed. begin_line ( span_id) ,
1261
+ parsed. begin_column ( span_id) ,
1262
+ )
1232
1263
} ;
1233
1264
1234
1265
let expected_foo = expected ( "foo" , & [ "foo" ] ) ;
0 commit comments