Open source AI coding agent. Designed for large projects and real world tasks.
Go aiai-agentsai-developer-toolsai-toolsclicommand-linedeveloper-toolsgitgolanggpt-4llmopenaipolyglot-programmingterminalterminal-basedterminal-ui
Improve file map processing with better error handling
Dane Schneider1183075e07fb
diff --git a/app/server/syntax/file_map/map.go b/app/server/syntax/file_map/map.goindex 40b3aa55..b12ae697 100644--- a/app/server/syntax/file_map/map.go+++ b/app/server/syntax/file_map/map.go@@ -79,27 +79,40 @@ func MapFile(ctx context.Context, filename string, content []byte) (*FileMap, erparser, lang, fallbackParser, fallbackLang = syntax.GetParserForPath(filename)- if parser == nil {+ if parser == nil && fallbackParser == nil {// return nil, fmt.Errorf("unsupported file type: %s", ext)return &FileMap{Definitions: []Definition{},}, nil}- // Parse file- tree, err := parser.ParseCtx(ctx, nil, content)- if err != nil {- // return nil, fmt.Errorf("failed to parse file: %v", err)- return &FileMap{- Definitions: []Definition{},- }, nil+ if parser != nil {+ defer parser.Close()+ }++ if fallbackParser != nil {+ defer fallbackParser.Close()+ }++ var tree *tree_sitter.Tree+ var err error++ if parser != nil {+ // Parse file+ tree, err = parser.ParseCtx(ctx, nil, content)+ if err != nil {+ // return nil, fmt.Errorf("failed to parse file: %v", err)+ return &FileMap{+ Definitions: []Definition{},+ }, nil+ }+ defer tree.Close()}- defer tree.Close()- if tree.RootNode().Type() == "error" {+ if tree == nil || tree.RootNode().Type() == "error" {fallbackTree, err := fallbackParser.ParseCtx(ctx, nil, content)if err != nil {- // return nil, fmt.Errorf("failed to parse file with fallback parser: %v", err)+ // return nil, fmt.Errorf("failed to parse file: %v", err)return &FileMap{Definitions: []Definition{},}, nildiff --git a/app/server/syntax/file_map/multi.go b/app/server/syntax/file_map/multi.goindex 2c4f9c16..4092184b 100644--- a/app/server/syntax/file_map/multi.go+++ b/app/server/syntax/file_map/multi.go@@ -16,6 +16,7 @@ import (tree_sitter "github.com/smacker/go-tree-sitter")+// No longer used - all mapping is done via GetFileMap handler// handles concurrent processing of multiple files for mappingfunc ProcessMapFiles(ctx context.Context, inputs map[string]string) (shared.FileMapBodies, error) {log.Println("ProcessMapFiles")@@ -33,17 +34,21 @@ func ProcessMapFiles(ctx context.Context, inputs map[string]string) (shared.Filelog.Printf("ProcessMapFiles: Max workers: %d", maxWorkers)sem := make(chan struct{}, maxWorkers)- sortedPaths := make([]string, 0, len(inputs))- for path := range inputs {- sortedPaths = append(sortedPaths, path)- }- // sort paths by content length, longest first for more efficient cpu utilization- sort.Slice(sortedPaths, func(i, j int) bool {- return len(inputs[sortedPaths[i]]) > len(inputs[sortedPaths[j]])- })+ for path, content := range inputs {+ if !shared.HasFileMapSupport(path) {+ mu.Lock()+ bodies[path] = "[NO MAP]"+ mu.Unlock()+ errCh <- nil+ continue+ } else if len(content) > shared.MaxContextMapSingleInputSize { // 1MB+ mu.Lock()+ bodies[path] = "[NO MAP - TOO LARGE]"+ mu.Unlock()+ errCh <- nil+ continue+ }- for _, path := range sortedPaths {- content := inputs[path]sem <- struct{}{}go func(path, content string) {defer func() { <-sem }()