|
1 | 1 | package analysis
|
2 | 2 |
|
3 | 3 | import (
|
4 |
| - "fmt" |
5 | 4 | "luahelper-lsp/langserver/check/common"
|
6 | 5 | "luahelper-lsp/langserver/check/projects"
|
7 | 6 | "luahelper-lsp/langserver/check/results"
|
8 | 7 | "luahelper-lsp/langserver/log"
|
| 8 | + "sync" |
9 | 9 | )
|
10 | 10 |
|
11 | 11 | // IgnoreInfo 忽略的信息
|
@@ -60,6 +60,9 @@ type Analysis struct {
|
60 | 60 | extMark string
|
61 | 61 | }
|
62 | 62 |
|
| 63 | +// 注解互斥锁 |
| 64 | +var mutex sync.Mutex |
| 65 | + |
63 | 66 | // CreateAnalysis 创建一个分析的结构
|
64 | 67 | func CreateAnalysis(checkTerm results.CheckTerm, entryFile string) *Analysis {
|
65 | 68 | return &Analysis{
|
@@ -120,90 +123,8 @@ func (a *Analysis) enterScope() {
|
120 | 123 | // 出一个scope
|
121 | 124 | func (a *Analysis) exitScope() {
|
122 | 125 | a.curFunc.ExitScope()
|
123 |
| - |
124 |
| - // 如果是一轮校验,判断是否要校验局部变量是否定义未使用 |
125 |
| - if !a.isFirstTerm() || a.realTimeFlag { |
126 |
| - return |
127 |
| - } |
128 |
| - |
129 |
| - // 判断是否开启了局部变量定义了是否未使用的告警 |
130 |
| - if common.GConfig.IsGlobalIgnoreErrType(common.CheckErrorLocalNoUse) { |
131 |
| - return |
132 |
| - } |
133 |
| - |
134 |
| - scope := a.curScope |
135 |
| - if scope == nil { |
136 |
| - return |
137 |
| - } |
138 |
| - |
139 |
| - fileResult := a.curResult |
140 |
| - |
141 |
| - // 扫描当前scope,判断哪些局部变量定义了未使用 |
142 |
| - for varName, varInfoList := range scope.LocVarMap { |
143 |
| - // _ 局部变量忽略, _G也忽略 |
144 |
| - if varName == "_" || varName == "_G" { |
145 |
| - continue |
146 |
| - } |
147 |
| - |
148 |
| - // class/struct/extension 中的 super / Self / Super 忽略 |
149 |
| - if a.curScope.ExtMark == "class" && (varName == "__st" || varName == "Self" || varName == "Super") { |
150 |
| - continue |
151 |
| - } |
152 |
| - |
153 |
| - if common.GConfig.IsIgnoreLocNotUseVar(varName) { |
154 |
| - // 如果为系统忽略的局部变量定义了,未使用的,忽略掉 |
155 |
| - continue |
156 |
| - } |
157 |
| - |
158 |
| - for _, oneVar := range varInfoList.VarVec { |
159 |
| - if oneVar.IsUse || oneVar.IsClose { |
160 |
| - continue |
161 |
| - } |
162 |
| - |
163 |
| - // 定义的局部函数忽略 |
164 |
| - if oneVar.ReferFunc != nil { |
165 |
| - continue |
166 |
| - } |
167 |
| - |
168 |
| - // 判断指向的关联变量,是否为系统的函数或模块 |
169 |
| - // 例如 local math = math 这样的忽略掉 |
170 |
| - expName := common.GetExpName(oneVar.ReferExp) |
171 |
| - |
172 |
| - // 1) 判断是否直接关联到的系统模块或函数 |
173 |
| - oneStr := common.GetExpSubKey(expName) |
174 |
| - if oneStr != "" { |
175 |
| - if common.GConfig.IsInSysNotUseMap(oneStr) { |
176 |
| - // 为系统的模块或函数名,忽略掉 |
177 |
| - continue |
178 |
| - } |
179 |
| - } |
180 |
| - |
181 |
| - // 2) 判断是否关联到系统模块的成员, 例如:local concat = table.concat |
182 |
| - flagG, strRet := common.StrRemovePreG(expName) |
183 |
| - if flagG { |
184 |
| - expName = "!" + strRet |
185 |
| - } |
186 |
| - moduleName, keyName := common.GetTableStrTwoStr(expName) |
187 |
| - if moduleName != "" && keyName != "" { |
188 |
| - if common.GConfig.IsInSysNotUseMap(moduleName) { |
189 |
| - // 为系统的模块或函数名,忽略掉 |
190 |
| - continue |
191 |
| - } |
192 |
| - } |
193 |
| - |
194 |
| - errorStr := fmt.Sprintf("%s declared and not used", varName) |
195 |
| - fileResult.InsertError(common.CheckErrorLocalNoUse, errorStr, oneVar.Loc) |
196 |
| - |
197 |
| - // 遍历所有的定义了未使用,只是简单的赋值 |
198 |
| - for _, subVar := range oneVar.NoUseAssignLocs { |
199 |
| - errorStr := fmt.Sprintf("%s declared and not used, this just assign", varName) |
200 |
| - fileResult.InsertError(common.CheckErrorNoUseAssign, errorStr, subVar) |
201 |
| - } |
202 |
| - |
203 |
| - // 清除掉 |
204 |
| - oneVar.NoUseAssignLocs = nil |
205 |
| - } |
206 |
| - } |
| 126 | + a.checkLocVarCall() |
| 127 | + a.checkLocFuncCall() |
207 | 128 | }
|
208 | 129 |
|
209 | 130 | // 向分析的单个工程中,添加全局定义的变量
|
|
0 commit comments