From f403145ef4624e7d0cfdbb14b153e8009c800280 Mon Sep 17 00:00:00 2001 From: lalawue Date: Wed, 20 Jul 2022 00:41:57 +0800 Subject: [PATCH] update to LuaHelper 0.2.17 --- .../check/analysis/analysis_search.go | 20 +++- .../check/analysis/analysis_stat.go | 14 +-- luahelper-lsp/langserver/check/check_all.go | 22 ++++- .../langserver/check/check_find_var_refer.go | 2 +- .../langserver/check/check_first_hanlde.go | 34 +++++++ .../langserver/check/check_lsp_define.go | 2 +- .../langserver/check/check_lsp_filechange.go | 6 +- .../langserver/check/common/dir_manager.go | 31 +++---- .../check/common/file_index_info.go | 93 +++++++++++++++++++ .../langserver/check/common/global_conf.go | 2 +- luahelper-lsp/langserver/check/common/util.go | 12 --- .../langserver/check/projects/projects.go | 8 +- .../langserver/check/results/file_result.go | 14 +-- .../langserver/textdocument_define_test.go | 70 ++++++++++++++ luahelper-vscode/CHANGELOG.md | 6 ++ luahelper-vscode/package.json | 4 +- 16 files changed, 278 insertions(+), 62 deletions(-) create mode 100644 luahelper-lsp/langserver/check/common/file_index_info.go diff --git a/luahelper-lsp/langserver/check/analysis/analysis_search.go b/luahelper-lsp/langserver/check/analysis/analysis_search.go index 9722afc..d830da9 100644 --- a/luahelper-lsp/langserver/check/analysis/analysis_search.go +++ b/luahelper-lsp/langserver/check/analysis/analysis_search.go @@ -124,17 +124,29 @@ func (a *Analysis) getFuncCallReferFunc(node *ast.FuncCallStat) (referFunc *comm strName := strTabName[1:] // 2.1) 查找局部变量的引用 - var referInfo *common.ReferInfo + var findVar *common.VarInfo + + // 需要先判断该变量是否直接含义key的函数 loc = common.GetTablePrefixLoc(taExp) if locVar, ok := scope.FindLocVar(strName, loc); ok { - referInfo = locVar.ReferInfo + findVar = locVar } else { // 2.2) 局部变量没有找到,查找全局变量 if ok, oneVar := fileResult.FindGlobalVarInfo(strName, false, ""); ok { - referInfo = oneVar.ReferInfo + findVar = oneVar } } + if findVar == nil { + return nil, strName + } + + subVar := common.GetVarSubGlobalVar(findVar, strKeyName) + if subVar != nil { + return subVar.ReferFunc, strKeyName + } + + referInfo := findVar.ReferInfo if referInfo == nil { return nil, strName } @@ -1313,7 +1325,7 @@ func (a *Analysis) GetImportReferByCallExp(funcExp *ast.FuncCallExp) *common.Ref } // 先查找该引用是否有效 - fileResult.CheckReferFile(oneRefer, a.Projects.GetAllFilesMap()) + fileResult.CheckReferFile(oneRefer, a.Projects.GetAllFilesMap(), a.Projects.GetFileIndexInfo()) // 全局的引用文件里面增加一个引用对象 // if fileResult.ReferVec == nil { diff --git a/luahelper-lsp/langserver/check/analysis/analysis_stat.go b/luahelper-lsp/langserver/check/analysis/analysis_stat.go index 3489881..cb862af 100644 --- a/luahelper-lsp/langserver/check/analysis/analysis_stat.go +++ b/luahelper-lsp/langserver/check/analysis/analysis_stat.go @@ -88,9 +88,7 @@ func (a *Analysis) cgFuncCallParamCheck(node *ast.FuncCallStat) { fileResult := a.curResult nArgs := len(node.Args) - var referFunc *common.FuncInfo - var referStr string - referFunc, referStr = a.getFuncCallReferFunc(node) + referFunc, referStr := a.getFuncCallReferFunc(node) if referFunc == nil { return } @@ -100,7 +98,6 @@ func (a *Analysis) cgFuncCallParamCheck(node *ast.FuncCallStat) { } paramLen := len(referFunc.ParamList) - if nArgs > paramLen { //调用处参数个数大于定义参数个数的,直接告警 errorStr := fmt.Sprintf("%s call func param num(%d) > func define param num(%d)", referStr, nArgs, paramLen) @@ -108,7 +105,6 @@ func (a *Analysis) cgFuncCallParamCheck(node *ast.FuncCallStat) { return } else if nArgs < paramLen { // 函数调用处参数个数小于定义参数个数的,支持注解辅助检查 - // 如果未获取过 if !referFunc.ParamDefaultInit { referFunc.ParamDefaultInit = true @@ -219,7 +215,7 @@ func (a *Analysis) funcCallParamTypeCheck(node *ast.FuncCallStat, referFunc *com } } -//获取表达式类型字符串,如果是引用,则递归查找,(即支持类型传递) +//GetAnnTypeStrForRefer 获取表达式类型字符串,如果是引用,则递归查找,(即支持类型传递) func (a *Analysis) GetAnnTypeStrForRefer(referExp ast.Exp, idx int) (retVec []string) { retVec = []string{} argType := common.GetAnnTypeFromExp(referExp) @@ -277,10 +273,10 @@ func (a *Analysis) GetAnnTypeStrForRefer(referExp ast.Exp, idx int) (retVec []st if argType == "LuaTypeRefer" { //若仍是LuaTypeRefer 递归推导 return a.GetAnnTypeStrForRefer(varInfo.ReferExp, varIdx) - } else { - retVec = append(retVec, argType) - return retVec } + + retVec = append(retVec, argType) + return retVec } func (a *Analysis) cgBreakStat(node *ast.BreakStat) { diff --git a/luahelper-lsp/langserver/check/check_all.go b/luahelper-lsp/langserver/check/check_all.go index e1c3904..b4b616a 100644 --- a/luahelper-lsp/langserver/check/check_all.go +++ b/luahelper-lsp/langserver/check/check_all.go @@ -12,8 +12,11 @@ import ( // AllProject 所有工程包含的内容 type AllProject struct { - // 所有需要分析的文件map - allFilesMap map[string]struct{} + // 所有需要分析的文件map。key值为前缀,截取前面.部分的字符串, 例如 test.lua, 返回test。 + allFilesMap map[string]string + + // 文件名的缓存信息 + fileIndexInfo *common.FileIndexInfo // entryFile string // 所有的工程入口分析文件 @@ -49,7 +52,7 @@ type AllProject struct { func CreateAllProject(allFilesList []string, entryFileArr []string, clientExpPathList []string) *AllProject { // 第一阶段(生成AST,第一次遍历AST),用多协程分析所有的扫描出来的文件 allProject := &AllProject{ - allFilesMap: map[string]struct{}{}, + allFilesMap: map[string]string{}, entryFilesList: entryFileArr, clientExpFileMap: map[string]struct{}{}, fileStructMap: map[string]*results.FileStruct{}, @@ -59,11 +62,13 @@ func CreateAllProject(allFilesList []string, entryFileArr []string, clientExpPat checkTerm: results.CheckTermFirst, completeCache: common.CreateCompleteCache(), fileLRUMap: common.NewLRUCache(20), + fileIndexInfo: common.CreateFileIndexInfo(), } // 传人的所有文件列表转换成map for _, fileName := range allFilesList { - allProject.allFilesMap[fileName] = struct{}{} + allProject.allFilesMap[fileName] = common.CompleteFilePathToPreStr(fileName) + allProject.fileIndexInfo.InsertOneFile(fileName) } // 传人的插件客户端额外的文件列表转换成map @@ -154,10 +159,15 @@ func (a *AllProject) rebuidCreateTypeMap() { } // GetAllFilesMap 获取分析的文件map列表 -func (a *AllProject) GetAllFilesMap() (allFilesMap map[string]struct{}) { +func (a *AllProject) GetAllFilesMap() (allFilesMap map[string]string) { return a.allFilesMap } +// GetFileIndexInfo 获取文件的缓存结构 +func (a *AllProject) GetFileIndexInfo() *common.FileIndexInfo { + return a.fileIndexInfo +} + // IsInAllFilesMap 指定的文件,是否在已经分析的map列表中 func (a *AllProject) IsInAllFilesMap(strFile string) bool { _, flag := a.allFilesMap[strFile] @@ -174,6 +184,8 @@ func (a *AllProject) RemoveFile(strFile string) { // 1) 所有需要分析的文件,删除它 delete(a.allFilesMap, strFile) + a.fileIndexInfo.RemoveOneFile(strFile) + // 2)删除第一阶段的文件指针 _, beforeExitFlag := a.GetFirstFileStuct(strFile) delete(a.fileStructMap, strFile) diff --git a/luahelper-lsp/langserver/check/check_find_var_refer.go b/luahelper-lsp/langserver/check/check_find_var_refer.go index a2fc809..78eef60 100644 --- a/luahelper-lsp/langserver/check/check_find_var_refer.go +++ b/luahelper-lsp/langserver/check/check_find_var_refer.go @@ -750,7 +750,7 @@ func (a *AllProject) getImportReferSymbol(luaInFile string, funcExp *ast.FuncCal } // 先查找该引用是否有效 - fileStruct.FileResult.CheckReferFile(oneRefer, a.allFilesMap) + fileStruct.FileResult.CheckReferFile(oneRefer, a.allFilesMap, a.fileIndexInfo) if !oneRefer.Valid { return nil } diff --git a/luahelper-lsp/langserver/check/check_first_hanlde.go b/luahelper-lsp/langserver/check/check_first_hanlde.go index 0c8545b..966b764 100644 --- a/luahelper-lsp/langserver/check/check_first_hanlde.go +++ b/luahelper-lsp/langserver/check/check_first_hanlde.go @@ -266,6 +266,40 @@ func (a *AllProject) HandleFirstAllProject() { // 重建 common.GConfig.RebuildSameFileNameVar(a.allFilesMap) + // time2 := time.Now() + // // 创建所有文件的目录结构 + // for strFile := range a.allFilesMap { + // splitVec := strings.Split(strFile, "/") + // vecLen := len(splitVec) + + // tmpFileDir := a.allFilesDirStruct + // for index := range splitVec { + // if index == vecLen - 1 { + // if tmpFileDir.FilesMap == nil { + // tmpFileDir.FilesMap = map[string]struct{}{} + // } + // tmpFileDir.FilesMap[strFile] = struct{}{} + // break + // } + + // subStr := strings.Join(splitVec[0:index + 1], "/") + // if subFileDir, ok := tmpFileDir.SubDirList[subStr]; ok { + // tmpFileDir = subFileDir + // } else { + // oneFileDir := &common.FileDirSturct{} + // oneFileDir.CurDir = subStr + // if tmpFileDir.SubDirList == nil { + // tmpFileDir.SubDirList = map[string]*common.FileDirSturct{} + // } + + // tmpFileDir.SubDirList[subStr] = oneFileDir + // tmpFileDir = oneFileDir + // } + // } + // } + // tc2 := time.Since(time2) + // ftime2 := tc2.Milliseconds() + // log.Debug("allFilesDirStruct cost time=%d(ms)", ftime2) a.firstCreateAndTraverseAst(filesList, false) diff --git a/luahelper-lsp/langserver/check/check_lsp_define.go b/luahelper-lsp/langserver/check/check_lsp_define.go index 4669f0e..fb14b98 100644 --- a/luahelper-lsp/langserver/check/check_lsp_define.go +++ b/luahelper-lsp/langserver/check/check_lsp_define.go @@ -104,7 +104,7 @@ func (a *AllProject) FindOpenFileDefine(strFile string, strOpenFile string) (def } // 1) 文件匹配的完整路径 - strOpenFile = common.GConfig.GetDirManager().GetBestMatchReferFile(strFile, strOpenFile, a.allFilesMap) + strOpenFile = common.GConfig.GetDirManager().GetBestMatchReferFile(strFile, strOpenFile, a.allFilesMap, a.fileIndexInfo) // 2) 判断是否为直接打开某一个文件 if strOpenFile == "" { diff --git a/luahelper-lsp/langserver/check/check_lsp_filechange.go b/luahelper-lsp/langserver/check/check_lsp_filechange.go index 6a8a071..d7b5d57 100644 --- a/luahelper-lsp/langserver/check/check_lsp_filechange.go +++ b/luahelper-lsp/langserver/check/check_lsp_filechange.go @@ -39,7 +39,9 @@ func (a *AllProject) HandleFileEventChanges(fileEventVec []FileEventStruct) (cha for _, fileEvents := range fileEventVec { strFile := fileEvents.StrFile if fileEvents.Type == FileEventCreated { - a.allFilesMap[strFile] = struct{}{} + a.allFilesMap[strFile] = common.CompleteFilePathToPreStr(strFile) + a.fileIndexInfo.InsertOneFile(strFile) + needAgainFileVec = append(needAgainFileVec, strFile) if dirManager.IsInDir(strFile) { needReferFileMap[strFile] = struct{}{} @@ -116,7 +118,7 @@ func (a *AllProject) HandleFileEventChanges(fileEventVec []FileEventStruct) (cha continue } - fileStruct.FileResult.ReanalyseReferInfo(needReferFileMap, a.allFilesMap) + fileStruct.FileResult.ReanalyseReferInfo(needReferFileMap, a.allFilesMap, a.fileIndexInfo) } // 引用关系变了,诊断信息也要跟着改变 changeDiagnostic = true diff --git a/luahelper-lsp/langserver/check/common/dir_manager.go b/luahelper-lsp/langserver/check/common/dir_manager.go index cc2e739..ef91b5e 100644 --- a/luahelper-lsp/langserver/check/common/dir_manager.go +++ b/luahelper-lsp/langserver/check/common/dir_manager.go @@ -636,7 +636,7 @@ func calcMatchStrScore(fileName string, referFileName string, condidateStr strin // referFile 为引用的lua文件名 // allFilesMap 为项目中所有包含的lua文件 // 返回值为匹配最合适的文件 -func (d *DirManager) GetBestMatchReferFile(curFile string, referFile string, allFilesMap map[string]struct{}) (findStr string) { +func (d *DirManager) GetBestMatchReferFile(curFile string, referFile string, allFilesMap map[string]string, fileIndexInfo *FileIndexInfo) (findStr string) { // 首先判断传人的文件是否带有后缀的 suffixFlag := false seperateIndex := strings.Index(referFile, ".") @@ -646,30 +646,27 @@ func (d *DirManager) GetBestMatchReferFile(curFile string, referFile string, all } candidateVec := []string{} - lenReferFile := len(referFile) - for strFile := range allFilesMap { - referFileTmp := referFile + strVec := strings.Split(referFile, "/") + referfileName := strVec[len(strVec)-1] - if suffixFlag { - if len(strFile) > lenReferFile { - referFileTmp = "/" + referFile - } + var fileNameMap map[string]string + if suffixFlag { + fileNameMap = fileIndexInfo.GetFileNameMap(referfileName) + } else { + fileNameMap = fileIndexInfo.GetPreFileNameMap(referfileName) + } - // 如果是带了后缀,拿后缀的去匹配 + referFileTmp := "/" + referFile + for strFile, pathToPreStr := range fileNameMap { + if suffixFlag { if !strings.HasSuffix(strFile, referFileTmp) { continue - } + } } else { - // 如果不带后缀,map中的路径名先提取 - preFile := completeFilePathToPreStr(strFile) + preFile := pathToPreStr if preFile == "" { continue } - - if len(preFile) > lenReferFile { - referFileTmp = "/" + referFile - } - if !strings.HasSuffix(preFile, referFileTmp) { continue } diff --git a/luahelper-lsp/langserver/check/common/file_index_info.go b/luahelper-lsp/langserver/check/common/file_index_info.go new file mode 100644 index 0000000..1bc5f42 --- /dev/null +++ b/luahelper-lsp/langserver/check/common/file_index_info.go @@ -0,0 +1,93 @@ +package common + +import "strings" + +// // FileDirSturct 文件的层级目录结构 +// type FileDirSturct struct { +// CurDir string // 当前的目录,例如 g:/compangyproject +// FilesMap map[string]struct{} // 该目录下包含的具体的lua文件。全路径,例如为:g:/compangyproject/one.lua +// SubDirList map[string]*FileDirSturct // 当前目录下,包含的所有子文件夹,嵌套的结构 +// } + +// // GetFirstContentDir 递归向下获取第一个包含有用内容的子目录 +// func (f *FileDirSturct) GetFirstContentDir() *FileDirSturct { +// if len(f.FilesMap) == 0 && len(f.SubDirList) == 1 { +// for _, subDir := range f.SubDirList { +// return subDir.GetFirstContentDir() +// } +// return nil +// } + +// return f +// } + +// FileIndexInfo 文件索引信息,文件名映射到全路径 +type FileIndexInfo struct { + fileNameMap map[string](map[string]string) // 文件名(包括后缀名)映射到所有的完整路径 + freFileNameMap map[string](map[string]string) // 文件名(不包括后缀名)映射到所有的完整路径 +} + +// CreateFileIndexInfo 创建文件索引对象 +func CreateFileIndexInfo() *FileIndexInfo { + return &FileIndexInfo{ + fileNameMap: map[string](map[string]string){}, + freFileNameMap: map[string](map[string]string){}, + } +} + +// InsertOneFile 缓存中插入一个文件名 +func (f *FileIndexInfo) InsertOneFile(strFile string) { + // CompleteFilePathToPreStr + strVec := strings.Split(strFile, "/") + fileName := strVec[len(strVec)-1] + + completePathToPreStr := CompleteFilePathToPreStr(strFile) + if valeMap, ok := f.fileNameMap[fileName]; ok { + valeMap[strFile] = completePathToPreStr + } else { + f.fileNameMap[fileName] = map[string]string{} + f.fileNameMap[fileName][strFile] = completePathToPreStr + } + + seperateIndex := strings.Index(fileName, ".") + if seperateIndex < 0 { + return + } + + preStr := fileName[0:seperateIndex] + if valeMap, ok := f.freFileNameMap[preStr]; ok { + valeMap[strFile] = completePathToPreStr + } else { + f.freFileNameMap[preStr] = map[string]string{} + f.freFileNameMap[preStr][strFile] = completePathToPreStr + } +} + +// RemoveOneFile 清除指定的文件 +func (f *FileIndexInfo) RemoveOneFile(strFile string) { + strVec := strings.Split(strFile, "/") + fileName := strVec[len(strVec)-1] + if valeMap, ok := f.fileNameMap[fileName]; ok { + delete(valeMap, fileName) + } + + seperateIndex := strings.Index(fileName, ".") + if seperateIndex < 0 { + return + } + + preStr := fileName[0:seperateIndex] + if valeMap, ok := f.freFileNameMap[preStr]; ok { + delete(valeMap, preStr) + } +} + +// GetFileNameMap 获取文件名(包括后缀名)映射的所有文件名称 +func (f *FileIndexInfo) GetFileNameMap(strFile string) map[string]string { + return f.fileNameMap[strFile] +} + +// GetPreFileNameMap 获取文件名(不包括后缀名)映射的所有文件名称 +func (f *FileIndexInfo) GetPreFileNameMap(strFile string) map[string]string { + return f.freFileNameMap[strFile] +} diff --git a/luahelper-lsp/langserver/check/common/global_conf.go b/luahelper-lsp/langserver/check/common/global_conf.go index 85fa79e..b724028 100644 --- a/luahelper-lsp/langserver/check/common/global_conf.go +++ b/luahelper-lsp/langserver/check/common/global_conf.go @@ -1228,7 +1228,7 @@ func (g *GlobalConfig) IsIgnoreRequireModuleError(strName string) bool { // RebuildSameFileNameVar 重构应该忽略的同文件名的变量 // allFilesMap为最新的加载的所有文件名,包含了前缀 -func (g *GlobalConfig) RebuildSameFileNameVar(allFilesMap map[string]struct{}) { +func (g *GlobalConfig) RebuildSameFileNameVar(allFilesMap map[string]string) { if !g.IgnoreFileNameVarFlag { return } diff --git a/luahelper-lsp/langserver/check/common/util.go b/luahelper-lsp/langserver/check/common/util.go index 8f13928..eb00e42 100644 --- a/luahelper-lsp/langserver/check/common/util.go +++ b/luahelper-lsp/langserver/check/common/util.go @@ -919,18 +919,6 @@ func GetUnopExpType(exp *ast.UnopExp) LuaType { return LuaTypeRefer } -func completeFilePathToPreStr(pathFile string) (preStr string) { - // 完整路径提前前缀 - // 字符串中,查找第一个. - seperateIndex := strings.Index(pathFile, ".") - if seperateIndex < 0 { - return "" - } - - preStr = pathFile[0:seperateIndex] - return preStr -} - // GetMakeTableConstructorExp 获取构造的时候的TableConstructorExp func GetMakeTableConstructorExp(valExp ast.Exp) (tableNode *ast.TableConstructorExp) { switch exp := valExp.(type) { diff --git a/luahelper-lsp/langserver/check/projects/projects.go b/luahelper-lsp/langserver/check/projects/projects.go index 12e00d7..d62dfc7 100644 --- a/luahelper-lsp/langserver/check/projects/projects.go +++ b/luahelper-lsp/langserver/check/projects/projects.go @@ -23,7 +23,13 @@ type Projects interface { GetFirstReferFileResult(referInfo *common.ReferInfo) *results.FileResult // GetAllFilesMap 获取所有的文件map - GetAllFilesMap() map[string]struct{} + GetAllFilesMap() map[string]string + + // GetFileIndexInfo 获取文件的缓存结构 + GetFileIndexInfo() *common.FileIndexInfo + + // GetAllFilesPreStrMap 获取所有文件的前置路径map + //GetAllFilesPreStrMap() map[string]string // GetFuncDefaultParamInfo 在函数注解中获取默认参数标记 GetFuncDefaultParamInfo(fileName string, lastLine int, paramNameList []string) (paramDefaultNum int) diff --git a/luahelper-lsp/langserver/check/results/file_result.go b/luahelper-lsp/langserver/check/results/file_result.go index eac498e..945ac14 100644 --- a/luahelper-lsp/langserver/check/results/file_result.go +++ b/luahelper-lsp/langserver/check/results/file_result.go @@ -217,7 +217,7 @@ func (f *FileResult) FindGlobalVarInfo(strName string, gFlag bool, strProPre str // 查找引用一个文件的结果 // allFilesMap 为所有加载文件map -func (f *FileResult) CheckReferFile(referInfo *common.ReferInfo, allFilesMap map[string]struct{}) { +func (f *FileResult) CheckReferFile(referInfo *common.ReferInfo, allFilesMap map[string]string, fileIndexInfo *common.FileIndexInfo) { strFile := referInfo.ReferStr strFile = pathpre.GetRemovePreStr(strFile) curFile := f.Name @@ -245,7 +245,7 @@ func (f *FileResult) CheckReferFile(referInfo *common.ReferInfo, allFilesMap map // 1.2) 非全路径匹配 if !common.GConfig.ReferMatchPathFlag { // 如果配置为非全路径匹配,尝试模糊匹配路径 - bestFilePath := common.GConfig.GetDirManager().GetBestMatchReferFile(curFile, strFile, allFilesMap) + bestFilePath := common.GConfig.GetDirManager().GetBestMatchReferFile(curFile, strFile, allFilesMap, fileIndexInfo) if bestFilePath != "" { // lua文件存在,正常 referInfo.ReferValidStr = bestFilePath @@ -340,7 +340,7 @@ func (f *FileResult) CheckReferFile(referInfo *common.ReferInfo, allFilesMap map } // b) 如果配置为非全路径匹配,尝试模糊匹配路径 - strBestFileTmp := dirManager.GetBestMatchReferFile(curFile, strNewFile, allFilesMap) + strBestFileTmp := dirManager.GetBestMatchReferFile(curFile, strNewFile, allFilesMap, fileIndexInfo) if strBestFileTmp != "" { // 匹配到了,判断对应的文件,是否存在 // lua文件存在,正常 @@ -351,7 +351,7 @@ func (f *FileResult) CheckReferFile(referInfo *common.ReferInfo, allFilesMap map // c) suffixStrFile = strOldFile + "/init.lua" initFile := strNewFile + "/init.lua" // 如果配置为全路径匹配,尝试模糊匹配路径 - strBestFileTmp = dirManager.GetBestMatchReferFile(curFile, initFile, allFilesMap) + strBestFileTmp = dirManager.GetBestMatchReferFile(curFile, initFile, allFilesMap, fileIndexInfo) if strBestFileTmp != "" { referInfo.ReferValidStr = strBestFileTmp return @@ -359,7 +359,7 @@ func (f *FileResult) CheckReferFile(referInfo *common.ReferInfo, allFilesMap map initFile = strNewFile + "/init.mooc" // 如果配置为全路径匹配,尝试模糊匹配路径 - strBestFileTmp = dirManager.GetBestMatchReferFile(curFile, initFile, allFilesMap) + strBestFileTmp = dirManager.GetBestMatchReferFile(curFile, initFile, allFilesMap, fileIndexInfo) if strBestFileTmp != "" { referInfo.ReferValidStr = strBestFileTmp return @@ -421,7 +421,7 @@ func (f *FileResult) isReferFileContainFiles(needReferFileMap map[string]struct{ // ReanalyseReferInfo 重新分析这个文件的所有引用关系,引用有文件变动(有文件增加或减少) // allFilesMap map[string]bool 为所有加载的文件列表 -func (f *FileResult) ReanalyseReferInfo(needReferFileMap map[string]struct{}, allFilesMap map[string]struct{}) { +func (f *FileResult) ReanalyseReferInfo(needReferFileMap map[string]struct{}, allFilesMap map[string]string, fileIndexInfo *common.FileIndexInfo) { // 1) 首先判断是否有包含改动的引用关系 if !f.isHasErrorNoFile() && !f.isReferFileContainFiles(needReferFileMap) { return @@ -443,7 +443,7 @@ func (f *FileResult) ReanalyseReferInfo(needReferFileMap map[string]struct{}, al // 3) 然后重新扫描所有的引用关系 for _, oneRefer := range f.ReferVec { oneRefer.Valid = true - f.CheckReferFile(oneRefer, allFilesMap) + f.CheckReferFile(oneRefer, allFilesMap, fileIndexInfo) } } diff --git a/luahelper-lsp/langserver/textdocument_define_test.go b/luahelper-lsp/langserver/textdocument_define_test.go index cd11259..cf10fd0 100644 --- a/luahelper-lsp/langserver/textdocument_define_test.go +++ b/luahelper-lsp/langserver/textdocument_define_test.go @@ -509,3 +509,73 @@ func TestProjectDefineFile6(t *testing.T) { t.Fatalf("location error") } } + + +// 跳转指向self的函数 +func TestProjectDefine7(t *testing.T) { + _, filename, _, _ := runtime.Caller(0) + paths, _ := filepath.Split(filename) + + strRootPath := paths + "../testdata/define" + strRootPath, _ = filepath.Abs(strRootPath) + + strRootURI := "file://" + strRootPath + lspServer := createLspTest(strRootPath, strRootURI) + context := context.Background() + + fileName := strRootPath + "/" + "test5.lua" + data, err := ioutil.ReadFile(fileName) + + if err != nil { + t.Fatalf("read file:%s err=%s", fileName, err.Error()) + } + + openParams := lsp.DidOpenTextDocumentParams{ + TextDocument: lsp.TextDocumentItem{ + URI: lsp.DocumentURI(fileName), + Text: string(data), + }, + } + err1 := lspServer.TextDocumentDidOpen(context, openParams) + if err1 != nil { + t.Fatalf("didopen file:%s err=%s", fileName, err1.Error()) + } + + onePosition := lsp.Position{ + Line: 4, + Character: 10, + } + + resultRange := lsp.Range{ + Start: lsp.Position{ + Line: 7, + Character: 13, + }, + End: lsp.Position{ + Line: 7, + Character: 16, + }, + } + + defineParams := lsp.TextDocumentPositionParams{ + TextDocument: lsp.TextDocumentIdentifier{ + URI: lsp.DocumentURI(fileName), + }, + Position: onePosition, + } + + resLocationList, err2 := lspServer.TextDocumentDefine(context, defineParams) + if err2 != nil { + t.Fatalf("define error") + } + if len(resLocationList) != 1 { + t.Fatalf("location size error") + } + + res0 := resLocationList[0].Range + + if res0.Start.Line != resultRange.Start.Line || res0.Start.Character != resultRange.Start.Character || + res0.End.Line != resultRange.End.Line || res0.End.Character != resultRange.End.Character { + t.Fatalf("location error") + } +} \ No newline at end of file diff --git a/luahelper-vscode/CHANGELOG.md b/luahelper-vscode/CHANGELOG.md index e854e13..2508a4b 100644 --- a/luahelper-vscode/CHANGELOG.md +++ b/luahelper-vscode/CHANGELOG.md @@ -1,5 +1,11 @@ # Change Log +## 0.2.17 (July 19, 2022) ++ 针对大工程require引起卡顿问题,进行了优化 ++ 优化了self的推导([issues:96](https://github.com/Tencent/LuaHelper/issues/96)) ++ 增强了函数参数不匹配的校验 ++ [Github](https://github.com/Tencent/LuaHelper) https://github.com/Tencent/LuaHelper + ## 0.2.16 (June 1, 2022) + 增加了试验的类型告警项 + 优化了self的推导([issues:96](https://github.com/Tencent/LuaHelper/issues/96)) diff --git a/luahelper-vscode/package.json b/luahelper-vscode/package.json index 582bab3..975ecd6 100644 --- a/luahelper-vscode/package.json +++ b/luahelper-vscode/package.json @@ -2,7 +2,7 @@ "name": "MoocHelper", "displayName": "MoocHelper", "description": "MoocHelper, Intellisense, Linting, Debugging, Code formatting, High-performance, and more.", - "version": "0.2.16", + "version": "0.2.17", "publisher": "lalawue", "author": { "name": "lalawue", @@ -762,7 +762,7 @@ "description": "%luahelper.Warn.CheckDuplicateIf%" }, "luahelper.Warn.CheckSelfAssign": { - "default": true, + "default": false, "scope": "resource", "type": "boolean", "description": "%luahelper.Warn.CheckSelfAssign%"