mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
kindsys: Adapt to new flattened lineage syntax in Thema (#68034)
* Update all core kinds to flattened lineages
* Regen Go types, without any
* Regen Go types, s/interface{}/any/
* Update generated core typescript
* Update generate docs
* Fix defaults gen in veneer index jenny
* Flatten plugindef lineage
* Convert all plugin kinds to flattened form
* Switch back to interface{} for now
* Switch to fs.Sub in plugin DeclParser
* Mostly undesirable codegen changes, to be fixed
* Update mod and sum
* Update pfs tests to flattened lineages
* Update thema to latest, regen docs
This commit is contained in:
@@ -50,7 +50,13 @@ func (gen *genTSVeneerIndex) Generate(kinds ...kindsys.Kind) (*codejen.File, err
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%s: %w", def.Props().Common().Name, err)
|
||||
}
|
||||
renameSpecNode(def.Props().Common().Name, f)
|
||||
// The obvious approach would be calling renameSpecNode() here, same as in the ts resource jenny,
|
||||
// to rename the "spec" field to the name of the kind. But that was causing extra
|
||||
// default elements to generate that didn't actually exist. Instead,
|
||||
// findDeclNode() is aware of "spec" and does the change on the fly. Preserving this
|
||||
// as a reminder in case we want to switch back, though.
|
||||
// renameSpecNode(def.Props().Common().Name, f)
|
||||
|
||||
elems, err := gen.extractTSIndexVeneerElements(def, f)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%s: %w", def.Props().Common().Name, err)
|
||||
@@ -66,7 +72,7 @@ func (gen *genTSVeneerIndex) extractTSIndexVeneerElements(def kindsys.Kind, tf *
|
||||
comm := def.Props().Common()
|
||||
|
||||
// Check the root, then walk the tree
|
||||
rootv := lin.Latest().Underlying()
|
||||
rootv := lin.Latest().Underlying().LookupPath(schPath)
|
||||
|
||||
var raw, custom, rawD, customD ast.Idents
|
||||
|
||||
@@ -85,18 +91,14 @@ func (gen *genTSVeneerIndex) extractTSIndexVeneerElements(def kindsys.Kind, tf *
|
||||
if !(sels[0].IsDefinition() || sels[0].String() == "spec") {
|
||||
return false
|
||||
}
|
||||
// It might seem to make sense that we'd strip replaceout the leading # here for
|
||||
// It might seem to make sense that we'd strip out the leading # here for
|
||||
// definitions. However, cuetsy's tsast actually has the # still present in its
|
||||
// Ident types, stripping it replaceout on the fly when stringifying.
|
||||
// Ident types, stripping it out on the fly when stringifying.
|
||||
name = sels[0].String()
|
||||
}
|
||||
|
||||
if name == "spec" {
|
||||
name = comm.Name
|
||||
}
|
||||
|
||||
// Search the generated TS AST for the type and default def nodes
|
||||
pair := findDeclNode(name, tf)
|
||||
pair := findDeclNode(name, comm.Name, tf)
|
||||
if pair.T == nil {
|
||||
// No generated type for this item, skip it
|
||||
return false
|
||||
@@ -208,8 +210,13 @@ type tsVeneerAttr struct {
|
||||
target string
|
||||
}
|
||||
|
||||
func findDeclNode(name string, tf *ast.File) declPair {
|
||||
func findDeclNode(name, basename string, tf *ast.File) declPair {
|
||||
var p declPair
|
||||
|
||||
if name == basename {
|
||||
return declPair{}
|
||||
}
|
||||
|
||||
for _, def := range tf.Nodes {
|
||||
// Peer through export keywords
|
||||
if ex, is := def.(ast.ExportKeyword); is {
|
||||
@@ -221,10 +228,16 @@ func findDeclNode(name string, tf *ast.File) declPair {
|
||||
if x.Name.Name == name {
|
||||
p.T = &x.Name
|
||||
_, p.isEnum = x.Type.(ast.EnumType)
|
||||
if name == "spec" {
|
||||
p.T.Name = basename
|
||||
}
|
||||
}
|
||||
case ast.VarDecl:
|
||||
if x.Names.Idents[0].Name == "default"+name {
|
||||
p.D = &x.Names.Idents[0]
|
||||
if name == "spec" {
|
||||
p.D.Name = "default" + basename
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user