Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ go 1.23.4

require (
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible
github.com/bytedance/sonic v1.14.1
github.com/cloudwego/eino v0.3.52
github.com/cloudwego/eino-ext/components/model/ark v0.1.16
github.com/cloudwego/eino-ext/components/model/claude v0.1.1
Expand Down Expand Up @@ -43,6 +42,7 @@ require (
github.com/bahlo/generic-list-go v0.2.0 // indirect
github.com/buger/jsonparser v1.1.1 // indirect
github.com/bytedance/gopkg v0.1.3 // indirect
github.com/bytedance/sonic v1.14.1 // indirect
github.com/bytedance/sonic/loader v0.3.0 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/cloudwego/base64x v0.1.6 // indirect
Expand Down
10 changes: 8 additions & 2 deletions lang/golang/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,12 @@ func (p *GoParser) collectGoMods(startDir string) error {
if err != nil || !strings.HasSuffix(path, "go.mod") {
return nil
}
name, _, err := getModuleName(path)

name, err := getModuleName(path)
if err != nil {
return err
return fmt.Errorf("failed to get module name: %w", err)
}

rel, err := filepath.Rel(p.homePageDir, filepath.Dir(path))
if err != nil {
return fmt.Errorf("module path %v is not in the repo", path)
Expand Down Expand Up @@ -154,6 +156,10 @@ func getDeps(dir string) (map[string]string, error) {
return nil, fmt.Errorf("failed to execute 'go mod tidy', err: %v, output: %s", err, string(output))
}

if hasNoDeps(filepath.Join(dir, "go.mod")) {
return map[string]string{}, nil
}

cmd = exec.Command("go", "list", "-json", "all")
cmd.Dir = dir
output, err = cmd.CombinedOutput()
Expand Down
38 changes: 15 additions & 23 deletions lang/golang/parser/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,11 @@
package parser

import (
"bufio"
"bytes"
"container/list"
"fmt"
"go/ast"
"go/build"
"go/types"
"io"
"os"
"os/exec"
"path"
Expand All @@ -32,6 +29,7 @@ import (

"github.com/Knetic/govaluate"
. "github.com/cloudwego/abcoder/lang/uniast"
"golang.org/x/mod/modfile"
)

func shouldIgnoreDir(path string) bool {
Expand Down Expand Up @@ -152,33 +150,27 @@ func getPackageAlias(importPath string) string {
return alias
}

func getModuleName(modFilePath string) (string, []byte, error) {
file, err := os.Open(modFilePath)
func hasNoDeps(modFilePath string) bool {
content, err := os.ReadFile(modFilePath)
if err != nil {
return "", nil, fmt.Errorf("failed to open file: %v", err)
return false
}
defer file.Close()
data, err := io.ReadAll(file)

modf, err := modfile.Parse(modFilePath, content, nil)
if err != nil {
return "", nil, fmt.Errorf("failed to read file: %v", err)
}
scanner := bufio.NewScanner(bytes.NewBuffer(data))
for scanner.Scan() {
line := scanner.Text()
if strings.HasPrefix(line, "module") {
// Assuming 'module' keyword is followed by module name
parts := strings.Split(line, " ")
if len(parts) > 1 {
return parts[1], data, nil
}
}
return false
}

if err := scanner.Err(); err != nil {
return "", data, fmt.Errorf("failed to scan file: %v", err)
return len(modf.Require) == 0
}

func getModuleName(modFilePath string) (string, error) {
content, err := os.ReadFile(modFilePath)
if err != nil {
return "", fmt.Errorf("failed to read file: %w", err)
}

return "", data, nil
return modfile.ModulePath(content), nil
}

func isGoBuiltins(name string) bool {
Expand Down
Loading