diff --git a/luahelper-lsp/langserver/check/check_lsp_define.go b/luahelper-lsp/langserver/check/check_lsp_define.go index dc3bee9..4669f0e 100644 --- a/luahelper-lsp/langserver/check/check_lsp_define.go +++ b/luahelper-lsp/langserver/check/check_lsp_define.go @@ -304,18 +304,7 @@ func (a *AllProject) getVarCommonFuncParam(strFile string, varStruct *common.Def } // 5)冒号 函数,self语法进行转换 - if common.ChangeFuncSelfToReferVar(minFunc, varStruct) { - minFunc = minFunc.GetParent() - // 由于 moocscript 的 class/struct AST 是拼凑的,而不是标准的 table:function() 格式, - // 这里特别处理一下 - loc := minFunc.Loc - clsScope := a.findClassStructScopeInfo(minScope) - if clsScope != nil && clsScope.Parent != nil { - loc = clsScope.Parent.LocVarMap[varStruct.StrVec[0]].GetLastOneVar().Loc - } - varStruct.PosLine = loc.StartLine - varStruct.PosCh = loc.StartColumn - } + common.ChangeFuncSelfToReferVar(minFunc, varStruct) // 6) 判断是否找的在table的定义处, 如果是不缺前面的定义 if len(varStruct.StrVec) == 1 && !varStruct.BracketsFlag { diff --git a/luahelper-lsp/langserver/check/common/util.go b/luahelper-lsp/langserver/check/common/util.go index 0391ada..8f13928 100644 --- a/luahelper-lsp/langserver/check/common/util.go +++ b/luahelper-lsp/langserver/check/common/util.go @@ -1030,21 +1030,21 @@ func GetExpLoc(node ast.Exp) (loc lexer.Location) { // function a:test1() // self.b = 3 -- 传人的为self.b // end -func ChangeFuncSelfToReferVar(fi *FuncInfo, varStruct *DefineVarStruct) bool { +func ChangeFuncSelfToReferVar(fi *FuncInfo, varStruct *DefineVarStruct) { firstColonFunc := fi.FindFirstColonFunc() if firstColonFunc == nil { - return false + return } if !firstColonFunc.IsColon { - return false + return } if firstColonFunc.RelateVar == nil { - return false + return } if len(varStruct.StrVec) < 1 { - return false + return } if IsSelf(fi.FileName, varStruct.StrVec[0]) { @@ -1057,9 +1057,13 @@ func ChangeFuncSelfToReferVar(fi *FuncInfo, varStruct *DefineVarStruct) bool { strArray = append(strArray, varStruct.StrVec[1:]...) varStruct.StrVec = strArray } - return true + // 通过 scope 寻找 table name 定义的位置,肯定在 ':' 函数之前 + relateVar, _ := firstColonFunc.MainScope.FindLocVar(varStruct.StrVec[0], firstColonFunc.Loc) + if relateVar != nil { + varStruct.PosLine = relateVar.Loc.StartLine + varStruct.PosCh = relateVar.Loc.StartColumn + } } - return false } // ChangeSelfToVarComplete 冒号 函数,self语法进行转换