Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
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
4 changes: 3 additions & 1 deletion .dagger/main.dang
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import Dagger

type Dang {
"""
The source directory for the Dang project.
"""
pub source: Directory! @defaultPath(path: "/") @ignorePatterns(patterns: [
pub source: Directory! @defaultPath("/") @ignorePatterns([
# TODO: respecting .gitignore would be nice
"Session.vim"
"dang"
Expand Down
15 changes: 2 additions & 13 deletions cmd/dang/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,6 @@ func run(ctx context.Context, cfg Config) error {
logger := slog.New(handler)
slog.SetDefault(logger)

// Load GraphQL configuration
config := dang.LoadGraphQLConfig()
provider := dang.NewGraphQLClientProvider(config)

// Get configured GraphQL client and schema
client, schema, err := provider.GetClientAndSchema(ctx)
if err != nil {
return fmt.Errorf("failed to setup GraphQL client: %w", err)
}
defer provider.Close() //nolint:errcheck

// Check if the path is a directory or file
fileInfo, err := os.Stat(cfg.File)
if err != nil {
Expand All @@ -130,12 +119,12 @@ func run(ctx context.Context, cfg Config) error {

if fileInfo.IsDir() {
// Evaluate directory as a module
if _, err := dang.RunDir(ctx, client, schema, cfg.File, cfg.Debug); err != nil {
if _, err := dang.RunDir(ctx, cfg.File, cfg.Debug); err != nil {
return err
}
} else {
// Evaluate single file
if err := dang.RunFile(ctx, client, schema, cfg.File, cfg.Debug); err != nil {
if err := dang.RunFile(ctx, cfg.File, cfg.Debug); err != nil {
return err
}
}
Expand Down
2 changes: 1 addition & 1 deletion dagger-sdk/dagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"sdk": {
"source": "go"
},
"include": ["../*"]
"include": ["../go.mod", "../go.sum", "../pkg/*"]
}
29 changes: 19 additions & 10 deletions dagger-sdk/entrypoint/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,6 @@ func main() {
handler := slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: level})
slog.SetDefault(slog.New(handler))

schema, err := Introspect(ctx, dag)
if err != nil {
WriteError(ctx, err)
os.Exit(2)
}

fnCall := dag.CurrentFunctionCall()
parentName, err := fnCall.ParentName(ctx)
if err != nil {
Expand Down Expand Up @@ -95,14 +89,14 @@ func main() {

modSrcDir := os.Args[1]

err = invoke(ctx, dag, schema, modSrcDir, []byte(parentJson), parentName, fnName, inputArgs)
err = invoke(ctx, dag, modSrcDir, []byte(parentJson), parentName, fnName, inputArgs)
if err != nil {
WriteError(ctx, err)
os.Exit(2)
}
}

func invoke(ctx context.Context, dag *dagger.Client, schema *introspection.Schema, modSrcDir string, parentJSON []byte, parentName string, fnName string, inputArgs map[string][]byte) (rerr error) {
func invoke(ctx context.Context, dag *dagger.Client, modSrcDir string, parentJSON []byte, parentName string, fnName string, inputArgs map[string][]byte) (rerr error) {
fnCall := dag.CurrentFunctionCall()
defer func() {
if rerr != nil {
Expand All @@ -112,6 +106,18 @@ func invoke(ctx context.Context, dag *dagger.Client, schema *introspection.Schem
}
}()

schema, err := Introspect(ctx, dag)
if err != nil {
WriteError(ctx, err)
os.Exit(2)
}

ctx = dang.ContextWithImportConfigs(ctx, dang.ImportConfig{
Name: "Dagger",
Client: dag.GraphQLClient(),
Schema: schema,
})

ctx = ioctx.StdoutToContext(ctx, os.Stdout)
ctx = ioctx.StderrToContext(ctx, os.Stderr)

Expand All @@ -138,7 +144,7 @@ func invoke(ctx context.Context, dag *dagger.Client, schema *introspection.Schem
})
}

env, err := dang.RunDir(ctx, dag.GraphQLClient(), schema, modSrcDir, debug)
env, err := dang.RunDir(ctx, modSrcDir, debug)
if err != nil {
return err
}
Expand Down Expand Up @@ -305,6 +311,9 @@ func anyToDang(ctx context.Context, env dang.EvalEnv, val any, fieldType hm.Type
// Otherwise, assume it's an object ID
sel := dang.FunCall{
Fun: &dang.Select{
Receiver: &dang.Symbol{
Name: "Dagger",
},
Field: fmt.Sprintf("load%sFromID", modType.Named),
},
Args: dang.Record{
Expand Down Expand Up @@ -512,7 +521,7 @@ func createFunction(ctx context.Context, dag *dagger.Client, mod *dang.Module, n
switch dir.Name {
case "defaultPath":
for _, arg := range dir.Args {
if arg.Key == "path" {
if arg.Key == "path" { // TODO: positional
val, err := evalConstantValue(arg.Value)
if err != nil {
return nil, fmt.Errorf("failed to evaluate directive argument %s.%s.%s: %w", arg.Key, dir.Name, arg.Key, err)
Expand Down
7 changes: 7 additions & 0 deletions dagger-sdk/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ type DangSdk struct {

func New(
// +defaultPath="/"
// +ignore=[
// "*",
// "!**/go.mod",
// "!**/go.sum",
// "!pkg",
// "!dagger-sdk"
// ]
source *dagger.Directory,
) *DangSdk {
return &DangSdk{
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ require (
github.com/spf13/cobra v1.9.1
github.com/stretchr/testify v1.11.1
github.com/vektah/gqlparser/v2 v2.5.30
github.com/vito/is v0.0.5
go.opentelemetry.io/otel v1.38.0
golang.org/x/sync v0.17.0
gotest.tools/v3 v3.5.2
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,6 @@ github.com/urfave/cli/v2 v2.27.7 h1:bH59vdhbjLv3LAvIu6gd0usJHgoTTPhCFib8qqOwXYU=
github.com/urfave/cli/v2 v2.27.7/go.mod h1:CyNAG/xg+iAOg0N4MPGZqVmv2rCoP267496AOXUZjA4=
github.com/vektah/gqlparser/v2 v2.5.30 h1:EqLwGAFLIzt1wpx1IPpY67DwUujF1OfzgEyDsLrN6kE=
github.com/vektah/gqlparser/v2 v2.5.30/go.mod h1:D1/VCZtV3LPnQrcPBeR/q5jkSQIPti0uYCP/RI0gIeo=
github.com/vito/is v0.0.5 h1:Rkpwa1eZ372A4DFq92xblSkTm0X7aNUgEQ5fuM/RNK0=
github.com/vito/is v0.0.5/go.mod h1:340fJtnLGRYg4rup7bXx0HMP52pz/PgPa0wNT2hOS40=
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 h1:gEOO8jv9F4OT7lGCjxCBTO/36wtF6j2nSip77qHd4x4=
Expand Down
2 changes: 2 additions & 0 deletions mod/apko/apko.dang
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Dagger

pub description =
"Builds containers from simple lists of packages using the Apko CLI."

Expand Down
2 changes: 2 additions & 0 deletions mod/dev/main.dang
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Dagger

type Dev {
pub source: Directory! @defaultPath(path: "/") @ignorePatterns(patterns: [
# TODO: respecting .gitignore would be nice
Expand Down
7 changes: 4 additions & 3 deletions mod/doug/main.dang
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
"""
A Dagger-native sandboxed coding agent.
"""
import Dagger

let maxResponseLength = 30000
let workspacePath = "/workspace"

"""
A Dagger-native sandboxed coding agent.
"""
type Doug {
let source: Directory! @defaultPath(path: "/")

Expand Down
10 changes: 6 additions & 4 deletions mod/test-enum/main.dang
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ type TestEnum {
Gets log level priority
"""
pub getLevelPriority(level: LogLevel!): Int! {
if level == LogLevel.DEBUG { 0 }
else if level == LogLevel.INFO { 1 }
else if level == LogLevel.WARN { 2 }
else { 3 }
case (level) {
LogLevel.DEBUG => 0
LogLevel.INFO => 1
LogLevel.WARN => 2
else => 3
}
}
}
61 changes: 61 additions & 0 deletions pkg/dang/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"iter"
"slices"

"github.com/vito/dang/pkg/hm"
"github.com/vito/dang/pkg/introspection"
Expand Down Expand Up @@ -495,6 +496,66 @@ func (c *CompositeModule) AddClass(name string, class Env) {
c.primary.AddClass(name, class)
}

// TrackUnqualifiedTypeImport delegates to the primary module
func (c *CompositeModule) TrackUnqualifiedTypeImport(symbolName, importName string) bool {
if mod, ok := c.primary.(*Module); ok {
return mod.TrackUnqualifiedTypeImport(symbolName, importName)
}
return false
}

// TrackUnqualifiedValueImport delegates to the primary module
func (c *CompositeModule) TrackUnqualifiedValueImport(symbolName, importName string) bool {
if mod, ok := c.primary.(*Module); ok {
return mod.TrackUnqualifiedValueImport(symbolName, importName)
}
return false
}

// CheckTypeConflict delegates to the primary module
func (c *CompositeModule) CheckTypeConflict(symbolName string) []string {
imports := c.primary.CheckTypeConflict(symbolName)
// Fall back to lexical scope if primary isn't a Module
for _, importer := range c.lexical.CheckTypeConflict(symbolName) {
if !slices.Contains(imports, importer) {
imports = append(imports, importer)
}
}
return imports
}

// CheckValueConflict delegates to the primary module
func (c *CompositeModule) CheckValueConflict(symbolName string) []string {
imports := c.primary.CheckValueConflict(symbolName)
// Fall back to lexical scope if primary isn't a Module
for _, importer := range c.lexical.CheckValueConflict(symbolName) {
if !slices.Contains(imports, importer) {
imports = append(imports, importer)
}
}
return imports
}

// TrackUnqualifiedDirectiveImport delegates to the primary module
func (c *CompositeModule) TrackUnqualifiedDirectiveImport(directiveName, importName string) bool {
if mod, ok := c.primary.(*Module); ok {
return mod.TrackUnqualifiedDirectiveImport(directiveName, importName)
}
return false
}

// CheckDirectiveConflict delegates to the primary module
func (c *CompositeModule) CheckDirectiveConflict(directiveName string) []string {
imports := c.primary.CheckDirectiveConflict(directiveName)
// Fall back to lexical scope if primary isn't a Module
for _, importer := range c.lexical.CheckDirectiveConflict(directiveName) {
if !slices.Contains(imports, importer) {
imports = append(imports, importer)
}
}
return imports
}

// AddDirective adds a directive to the primary environment
func (c *CompositeModule) AddDirective(name string, directive *DirectiveDecl) {
c.primary.AddDirective(name, directive)
Expand Down
Loading