@@ -2,7 +2,8 @@ use std::collections::HashSet;
22
33use code_analysis:: { DbIndex , LuaDeclId , LuaDocument , SemanticModel } ;
44use emmylua_parser:: {
5- LuaAst , LuaAstNode , LuaAstToken , LuaForRangeStat , LuaForStat , LuaLocalFuncStat , LuaLocalStat , LuaNameExpr , LuaParamList
5+ LuaAst , LuaAstNode , LuaAstToken , LuaForRangeStat , LuaForStat , LuaLocalFuncStat , LuaLocalStat ,
6+ LuaNameExpr , LuaParamList ,
67} ;
78use rowan:: TextRange ;
89
@@ -76,7 +77,7 @@ fn build_local_stat_annotator(
7677 let locals = local_stat. get_local_name_list ( ) ;
7778 for local_name in locals {
7879 let mut annotator = EmmyAnnotator {
79- typ : EmmyAnnotatorType :: Local ,
80+ typ : EmmyAnnotatorType :: ReadOnlyLocal ,
8081 ranges : vec ! [ ] ,
8182 } ;
8283 let name_token = local_name. get_name_token ( ) ?;
@@ -87,12 +88,15 @@ fn build_local_stat_annotator(
8788 . push ( document. to_lsp_range ( name_token_range) ?) ;
8889
8990 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) ;
9393 if let Some ( ref_ranges) = ref_ranges {
9494 for range in ref_ranges {
9595 use_range_set. insert ( * range) ;
96+ if reference_index. is_write_range ( file_id, * range) {
97+ annotator. typ = EmmyAnnotatorType :: MutLocal
98+ }
99+
96100 annotator. ranges . push ( document. to_lsp_range ( * range) ?) ;
97101 }
98102 }
@@ -113,7 +117,7 @@ fn build_params_annotator(
113117 let file_id = document. get_file_id ( ) ;
114118 for param_name in param_list. get_params ( ) {
115119 let mut annotator = EmmyAnnotator {
116- typ : EmmyAnnotatorType :: Param ,
120+ typ : EmmyAnnotatorType :: ReadonlyParam ,
117121 ranges : vec ! [ ] ,
118122 } ;
119123 let name_token = param_name. get_name_token ( ) ?;
@@ -124,12 +128,15 @@ fn build_params_annotator(
124128 . push ( document. to_lsp_range ( name_token_range) ?) ;
125129
126130 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) ;
130133 if let Some ( ref_ranges) = ref_ranges {
131134 for range in ref_ranges {
132135 use_range_set. insert ( * range) ;
136+ if reference_index. is_write_range ( file_id, * range) {
137+ annotator. typ = EmmyAnnotatorType :: MutParam
138+ }
139+
133140 annotator. ranges . push ( document. to_lsp_range ( * range) ?) ;
134141 }
135142 }
@@ -181,7 +188,7 @@ fn build_for_stat_annotator(
181188 let name_range = name_token. get_range ( ) ;
182189
183190 let mut annotator = EmmyAnnotator {
184- typ : EmmyAnnotatorType :: Param ,
191+ typ : EmmyAnnotatorType :: ReadonlyParam ,
185192 ranges : vec ! [ ] ,
186193 } ;
187194
@@ -216,7 +223,7 @@ fn build_for_range_annotator(
216223 let name_range = name_token. get_range ( ) ;
217224
218225 let mut annotator = EmmyAnnotator {
219- typ : EmmyAnnotatorType :: Param ,
226+ typ : EmmyAnnotatorType :: ReadonlyParam ,
220227 ranges : vec ! [ ] ,
221228 } ;
222229
@@ -252,7 +259,7 @@ fn build_local_func_stat_annotator(
252259 let name_range = name_token. get_range ( ) ;
253260
254261 let mut annotator = EmmyAnnotator {
255- typ : EmmyAnnotatorType :: Local ,
262+ typ : EmmyAnnotatorType :: ReadOnlyLocal ,
256263 ranges : vec ! [ ] ,
257264 } ;
258265
@@ -273,4 +280,4 @@ fn build_local_func_stat_annotator(
273280 result. push ( annotator) ;
274281
275282 Some ( ( ) )
276- }
283+ }
0 commit comments