Skip to content

Commit

Permalink
优化性能,只增量处理有变更的文件的enum宏段
Browse files Browse the repository at this point in the history
  • Loading branch information
yinfei8 committed Jul 1, 2024
1 parent 3600ddd commit 7f53062
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
26 changes: 26 additions & 0 deletions luahelper-lsp/langserver/check/check_lsp_annotate.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,32 @@ func (a *AllProject) getNotCacheAnnotateFile(strFile string) (annotateFile *comm
return annotateFile
}

// checkAllAnnotateEnum 检查所有的枚举注释代码段是否有重复的值
func (a *AllProject) checkFileMapAnnotateEnum(enumFileMap map[string]struct{}) {
if len(enumFileMap) == 0 {
return
}

if common.GConfig.IsGlobalIgnoreErrType(common.CheckErrorEnumValue) {
return
}

time1 := time.Now()

// 1) 首先统一校验是type是否有定义
for strFile := range enumFileMap {
fileStruct, _ := a.GetCacheFileStruct(strFile)
if fileStruct == nil {
continue
}

a.checkFileEnum(fileStruct)
}

ftime := time.Since(time1).Milliseconds()
log.Debug("checkAllAnnotateEnum time:%d", ftime)
}

// checkAllAnnotateEnum 检查所有的枚举注释代码段是否有重复的值
func (a *AllProject) checkAllAnnotateEnum() {
if len(a.fileStructMap) == 0 {
Expand Down
7 changes: 5 additions & 2 deletions luahelper-lsp/langserver/check/check_lsp_filechange.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,14 @@ func (a *AllProject) HandleFileEventChanges(fileEventVec []FileEventStruct) (cha

// 删除文件的列表
deleteFileMap := map[string]struct{}{}
// 需要处理的注解的文件
enumFileMap := map[string]struct{}{}

// 1) 处理有变化的文件
time0 := time.Now()
for _, fileEvents := range fileEventVec {
strFile := fileEvents.StrFile
enumFileMap[strFile] = struct{}{}
if fileEvents.Type == FileEventCreated {
a.allFilesMap[strFile] = common.CompleteFilePathToPreStr(strFile)
a.fileIndexInfo.InsertOneFile(strFile)
Expand Down Expand Up @@ -187,8 +190,8 @@ func (a *AllProject) HandleFileEventChanges(fileEventVec []FileEventStruct) (cha

a.checkAllAnnotate()

// 8) 检查所有的枚举注释代码段是否有重复的值
a.checkAllAnnotateEnum()
// 8) 检查所有的枚举注释代码段是否有重复的值【只处理有变更的文件】
a.checkFileMapAnnotateEnum(enumFileMap)
return true
}

Expand Down

0 comments on commit 7f53062

Please sign in to comment.