diff --git a/gopmod/classfile.go b/gopmod/classfile.go index 502d461..a91d8a9 100644 --- a/gopmod/classfile.go +++ b/gopmod/classfile.go @@ -18,6 +18,7 @@ package gopmod import ( "errors" + "path" "syscall" "github.com/goplus/mod/modcache" @@ -32,7 +33,7 @@ type Project = modfile.Project var ( SpxProject = &Project{ - Ext: ".gmx", + Ext: ".spx", Class: "Game", Works: []*Class{{Ext: ".spx", Class: "Sprite"}}, PkgPaths: []string{"github.com/goplus/spx", "math"}, @@ -45,9 +46,18 @@ var ( // ----------------------------------------------------------------------------- -func (p *Module) ClassKind(ext string) (isWork, isProj bool) { +func (p *Module) ClassKind(fname string) (isProj, ok bool) { + ext := path.Ext(fname) if c, ok := p.projects[ext]; ok { - isWork, isProj = c.Kind(ext) + for _, w := range c.Works { + if w.Ext == ext { + if ext != c.Ext || fname != "main"+ext { + return false, true + } + break + } + } + return true, true } return } @@ -68,6 +78,7 @@ func (p *Module) ImportClasses(importClass ...func(c *Project)) (err error) { impcls = importClass[0] } p.importClass(SpxProject, impcls) + p.projects[".gmx"] = SpxProject // old style if c := p.Project; c != nil { p.importClass(c, impcls) } diff --git a/modfile/rule.go b/modfile/rule.go index 2f34997..464faa3 100644 --- a/modfile/rule.go +++ b/modfile/rule.go @@ -80,18 +80,6 @@ type Class struct { Syntax *Line } -func (p *Project) Kind(ext string) (isWork, isProj bool) { - for _, w := range p.Works { - if w.Ext == ext { - isWork = true - } - } - if p.Ext == ext { - isProj = true - } - return -} - // A VersionInterval represents a range of versions with upper and lower bounds. // Intervals are closed: both bounds are included. When Low is equal to High, // the interval may refer to a single version ('v1.2.3') or an interval diff --git a/modfile/rule_test.go b/modfile/rule_test.go index 20c3bad..91b6727 100644 --- a/modfile/rule_test.go +++ b/modfile/rule_test.go @@ -91,16 +91,6 @@ func TestMustQuote(t *testing.T) { // ----------------------------------------------------------------------------- -func TestKind(t *testing.T) { - proj := &Project{Works: []*Class{{Ext: ".spx"}}, Ext: ".spx"} - isWork, isProj := proj.Kind(".spx") - if !isWork || !isProj { - t.Fatal("proj.Kind:", isWork, isProj) - } -} - -// ----------------------------------------------------------------------------- - var addGopTests = []struct { desc string in string