@@ -2,7 +2,8 @@ use std::collections::HashSet;
2
2
3
3
use code_analysis:: { DbIndex , LuaDeclId , LuaDocument , SemanticModel } ;
4
4
use emmylua_parser:: {
5
- LuaAst , LuaAstNode , LuaAstToken , LuaForRangeStat , LuaForStat , LuaLocalFuncStat , LuaLocalStat , LuaNameExpr , LuaParamList
5
+ LuaAst , LuaAstNode , LuaAstToken , LuaForRangeStat , LuaForStat , LuaLocalFuncStat , LuaLocalStat ,
6
+ LuaNameExpr , LuaParamList ,
6
7
} ;
7
8
use rowan:: TextRange ;
8
9
@@ -76,7 +77,7 @@ fn build_local_stat_annotator(
76
77
let locals = local_stat. get_local_name_list ( ) ;
77
78
for local_name in locals {
78
79
let mut annotator = EmmyAnnotator {
79
- typ : EmmyAnnotatorType :: Local ,
80
+ typ : EmmyAnnotatorType :: ReadOnlyLocal ,
80
81
ranges : vec ! [ ] ,
81
82
} ;
82
83
let name_token = local_name. get_name_token ( ) ?;
@@ -87,12 +88,15 @@ fn build_local_stat_annotator(
87
88
. push ( document. to_lsp_range ( name_token_range) ?) ;
88
89
89
90
let decl_id = LuaDeclId :: new ( file_id, local_name. get_position ( ) ) ;
90
- let ref_ranges = db
91
- . get_reference_index ( )
92
- . get_local_references ( & file_id, & decl_id) ;
91
+ let reference_index = db. get_reference_index ( ) ;
92
+ let ref_ranges = reference_index. get_local_references ( & file_id, & decl_id) ;
93
93
if let Some ( ref_ranges) = ref_ranges {
94
94
for range in ref_ranges {
95
95
use_range_set. insert ( * range) ;
96
+ if reference_index. is_write_range ( file_id, * range) {
97
+ annotator. typ = EmmyAnnotatorType :: MutLocal
98
+ }
99
+
96
100
annotator. ranges . push ( document. to_lsp_range ( * range) ?) ;
97
101
}
98
102
}
@@ -113,7 +117,7 @@ fn build_params_annotator(
113
117
let file_id = document. get_file_id ( ) ;
114
118
for param_name in param_list. get_params ( ) {
115
119
let mut annotator = EmmyAnnotator {
116
- typ : EmmyAnnotatorType :: Param ,
120
+ typ : EmmyAnnotatorType :: ReadonlyParam ,
117
121
ranges : vec ! [ ] ,
118
122
} ;
119
123
let name_token = param_name. get_name_token ( ) ?;
@@ -124,12 +128,15 @@ fn build_params_annotator(
124
128
. push ( document. to_lsp_range ( name_token_range) ?) ;
125
129
126
130
let decl_id = LuaDeclId :: new ( file_id, param_name. get_position ( ) ) ;
127
- let ref_ranges = db
128
- . get_reference_index ( )
129
- . get_local_references ( & file_id, & decl_id) ;
131
+ let reference_index = db. get_reference_index ( ) ;
132
+ let ref_ranges = reference_index. get_local_references ( & file_id, & decl_id) ;
130
133
if let Some ( ref_ranges) = ref_ranges {
131
134
for range in ref_ranges {
132
135
use_range_set. insert ( * range) ;
136
+ if reference_index. is_write_range ( file_id, * range) {
137
+ annotator. typ = EmmyAnnotatorType :: MutParam
138
+ }
139
+
133
140
annotator. ranges . push ( document. to_lsp_range ( * range) ?) ;
134
141
}
135
142
}
@@ -181,7 +188,7 @@ fn build_for_stat_annotator(
181
188
let name_range = name_token. get_range ( ) ;
182
189
183
190
let mut annotator = EmmyAnnotator {
184
- typ : EmmyAnnotatorType :: Param ,
191
+ typ : EmmyAnnotatorType :: ReadonlyParam ,
185
192
ranges : vec ! [ ] ,
186
193
} ;
187
194
@@ -216,7 +223,7 @@ fn build_for_range_annotator(
216
223
let name_range = name_token. get_range ( ) ;
217
224
218
225
let mut annotator = EmmyAnnotator {
219
- typ : EmmyAnnotatorType :: Param ,
226
+ typ : EmmyAnnotatorType :: ReadonlyParam ,
220
227
ranges : vec ! [ ] ,
221
228
} ;
222
229
@@ -252,7 +259,7 @@ fn build_local_func_stat_annotator(
252
259
let name_range = name_token. get_range ( ) ;
253
260
254
261
let mut annotator = EmmyAnnotator {
255
- typ : EmmyAnnotatorType :: Local ,
262
+ typ : EmmyAnnotatorType :: ReadOnlyLocal ,
256
263
ranges : vec ! [ ] ,
257
264
} ;
258
265
@@ -273,4 +280,4 @@ fn build_local_func_stat_annotator(
273
280
result. push ( annotator) ;
274
281
275
282
Some ( ( ) )
276
- }
283
+ }
0 commit comments