Skip to content

Commit

Permalink
Merge pull request #21 from xushiwei/q
Browse files Browse the repository at this point in the history
ClassKind(fname string) (isProj, ok bool)
  • Loading branch information
xushiwei authored Aug 26, 2023
2 parents c9d34fd + a99e98c commit 9ae1df4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 25 deletions.
17 changes: 14 additions & 3 deletions gopmod/classfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package gopmod

import (
"errors"
"path"
"syscall"

"github.com/goplus/mod/modcache"
Expand All @@ -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"},
Expand All @@ -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
}
Expand All @@ -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)
}
Expand Down
12 changes: 0 additions & 12 deletions modfile/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 0 additions & 10 deletions modfile/rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9ae1df4

Please sign in to comment.