Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
tstirrat15 committed Nov 6, 2024
1 parent 2ed76ca commit 27c5d38
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
30 changes: 27 additions & 3 deletions pkg/composableschemadsl/compiler/importer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"
"path"
"path/filepath"
"slices"

"github.com/rs/zerolog/log"

Expand All @@ -13,9 +14,10 @@ import (
)

type importContext struct {
pathSegments []string
sourceFolder string
names *mapz.Set[string]
pathSegments []string
sourceFolder string
requestedDefinitions []string
names *mapz.Set[string]
}

const SchemaFileSuffix = ".zed"
Expand Down Expand Up @@ -47,6 +49,28 @@ func importFile(importContext importContext) (*CompiledSchema, error) {
return compiled, nil
}

// TODO: is there a way to do this without mutating?
func filterDefinitions(requestedDefinitions []string, schema *CompiledSchema) {

Check failure on line 53 in pkg/composableschemadsl/compiler/importer.go

View workflow job for this annotation

GitHub Actions / Lint Go

func `filterDefinitions` is unused (unused)
schema.CaveatDefinitions = filterDefinitionList(requestedDefinitions, schema.CaveatDefinitions)
schema.ObjectDefinitions = filterDefinitionList(requestedDefinitions, schema.ObjectDefinitions)
schema.OrderedDefinitions = filterDefinitionList(requestedDefinitions, schema.OrderedDefinitions)
}

func filterDefinitionList[DefinitionType SchemaDefinition](requestedDefinitions []string, definitionList []DefinitionType) []DefinitionType {

Check failure on line 59 in pkg/composableschemadsl/compiler/importer.go

View workflow job for this annotation

GitHub Actions / Lint Go

func `filterDefinitionList` is unused (unused)
definitionSet := mapz.NewSet(requestedDefinitions...)
return slices.Collect(
func(yield func(DefinitionType) bool) {
for _, definition := range definitionList {
if definitionSet.Has(definition.GetName()) {
if !yield(definition) {
return
}
}
}
},
)
}

func constructFilePath(segments []string) string {
return path.Join(segments...) + SchemaFileSuffix
}
2 changes: 1 addition & 1 deletion pkg/composableschemadsl/compiler/importer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestImporter(t *testing.T) {
{"nested local import", "nested-local"},
{"nested local import with transitive hop", "nested-local-with-hop"},
{"nested local two layers deep import", "nested-two-layer-local"},
{"diamond-shaped imports are fine", "diamond-shaped"},
{"diamond-shaped imports are fine", "diamond-shaped"},
}

for _, test := range importerTests {
Expand Down
7 changes: 3 additions & 4 deletions pkg/composableschemadsl/compiler/translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -718,11 +718,10 @@ func translateImport(tctx translationContext, importNode *dslNode, names *mapz.S
requestedDefinitions = append(requestedDefinitions, requested)
}


return importFile(importContext{
names: names,
pathSegments: pathSegments,
names: names,
pathSegments: pathSegments,
requestedDefinitions: requestedDefinitions,
sourceFolder: tctx.sourceFolder,
sourceFolder: tctx.sourceFolder,
})
}

0 comments on commit 27c5d38

Please sign in to comment.