Skip to content

Commit 8592f90

Browse files
committed
scope 增加类标记,忽略 super/Self/Super 在的 outline 的显示
1 parent 28aae61 commit 8592f90

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed

Diff for: luahelper-lsp/langserver/check/analysis/analysis.go

+5-7
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"luahelper-lsp/langserver/check/projects"
99
"luahelper-lsp/langserver/check/results"
1010
"luahelper-lsp/langserver/log"
11-
"strings"
1211
)
1312

1413
// IgnoreInfo 忽略的信息
@@ -141,15 +140,18 @@ func (a *Analysis) exitScope() {
141140

142141
fileResult := a.curResult
143142

144-
isMooc := strings.HasSuffix(fileResult.Name, ".mooc")
145-
146143
// 扫描当前scope,判断哪些局部变量定义了未使用
147144
for varName, varInfoList := range scope.LocVarMap {
148145
// _ 局部变量忽略, _G也忽略
149146
if varName == "_" || varName == "_G" {
150147
continue
151148
}
152149

150+
// class/struct/extension 中的 super / Self / Super 忽略
151+
if a.curScope.ExtMark == "class" && (varName == "__st" || varName == "Self" || varName == "Super") {
152+
continue
153+
}
154+
153155
if common.GConfig.IsIgnoreLocNotUseVar(varName) {
154156
// 如果为系统忽略的局部变量定义了,未使用的,忽略掉
155157
continue
@@ -191,10 +193,6 @@ func (a *Analysis) exitScope() {
191193
}
192194
}
193195

194-
if isMooc && (varName == "Self" || varName == "Super") {
195-
continue
196-
}
197-
198196
errorStr := fmt.Sprintf("%s declared and not used", varName)
199197
fileResult.InsertError(common.CheckErrorLocalNoUse, errorStr, oneVar.Loc)
200198

Diff for: luahelper-lsp/langserver/check/analysis/analysis_stat.go

+1
Original file line numberDiff line numberDiff line change
@@ -1243,6 +1243,7 @@ func (a *Analysis) cgClassStat(node *ast.ClassDefStat) {
12431243
subScope := common.CreateScopeInfo(backupScope, nil, node.Loc)
12441244
backupScope.AppendSubScope(subScope)
12451245
a.curScope = subScope
1246+
a.curScope.ExtMark = "class"
12461247

12471248
for _, nf := range node.Vars {
12481249
a.cgLocalVarDeclStat(nf)

Diff for: luahelper-lsp/langserver/check/common/scope_info.go

+7
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ type ScopeInfo struct {
2020
NotVarMap map[string]NotValStruct // 存放这个块中所有的 if not a ; a这样的局部变量,检查后面的语法
2121
MidNotVarMap map[string]NotValStruct // 中间存放的,例如某一个模块里面 if not a or b then,后面又有if not a then,在这个块里面存放临时的数据
2222
Loc lexer.Location // 位置信息
23+
ExtMark string // 标记 class/struct/extension 信息
2324
}
2425

2526
// CreateScopeInfo 创建一个ScopeInfo指针
@@ -31,6 +32,7 @@ func CreateScopeInfo(parent *ScopeInfo, funcInfo *FuncInfo, loc lexer.Location)
3132
LocVarMap: nil,
3233
NotVarMap: nil,
3334
MidNotVarMap: nil,
35+
ExtMark: "",
3436
}
3537
}
3638

@@ -417,6 +419,11 @@ func (scope *ScopeInfo) FindAllLocalVal(gScopes []*ScopeInfo) (allSymbolStruct [
417419
continue
418420
}
419421

422+
// 过滤 class/struct/extenstion 中的 super / Self / Super
423+
if scope.ExtMark == "class" && (strVar == "__st" || strVar == "Self" || strVar == "Super") {
424+
continue
425+
}
426+
420427
oneSymbol := FileSymbolStruct{
421428
Name: strVar,
422429
Kind: IKVariable,

Diff for: luahelper-lsp/langserver/check/compiler/parser/mooc_parse_stat.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1068,7 +1068,7 @@ func (p *moocParser) parserClassDefStat(global bool, keyToken lexer.TkKind) ast.
10681068
// 取巧使用 Super
10691069
if super != nil {
10701070
varList = append(varList, &ast.LocalVarDeclStat{
1071-
NameList: []string{"_"},
1071+
NameList: []string{"__st"},
10721072
VarLocList: locList,
10731073
AttrList: attrList,
10741074
ExpList: []ast.Exp{super},

0 commit comments

Comments
 (0)