Skip to content

Commit 3fd1684

Browse files
committed
fix: reorg attaching MultiReadFS
1 parent d6cdcc4 commit 3fd1684

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

errgoengine.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,13 @@ type ErrgoEngine struct {
1717
}
1818

1919
func New() *ErrgoEngine {
20-
filesystems := make([]fs.ReadFileFS, 2)
21-
filesystems[0] = &RawFS{}
22-
2320
return &ErrgoEngine{
2421
SharedStore: NewEmptyStore(),
2522
ErrorTemplates: ErrorTemplates{},
2623
FS: &MultiReadFileFS{
27-
FSs: filesystems,
24+
FSs: []fs.ReadFileFS{
25+
&RawFS{},
26+
},
2827
},
2928
OutputGen: &OutputGenerator{},
3029
}
@@ -39,7 +38,7 @@ func (e *ErrgoEngine) Analyze(workingPath, msg string) (*CompiledErrorTemplate,
3938
// initial context data extraction
4039
contextData := NewContextData(e.SharedStore, workingPath)
4140
contextData.Analyzer = template.Language.AnalyzerFactory(contextData)
42-
e.FS.FSs[1] = template.Language.stubFs
41+
e.FS.Attach(template.Language.stubFs, 1)
4342

4443
groupNames := template.Pattern.SubexpNames()
4544
for _, submatches := range template.Pattern.FindAllStringSubmatch(msg, -1) {

fs.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,30 @@ type MultiReadFileFS struct {
1111
FSs []fs.ReadFileFS
1212
}
1313

14+
func (mfs *MultiReadFileFS) LastAttachedIdx() int {
15+
return len(mfs.FSs) - 1
16+
}
17+
18+
func (mfs *MultiReadFileFS) Attach(fs fs.ReadFileFS, idx int) {
19+
if idx < len(mfs.FSs) && idx >= 0 {
20+
if mfs.FSs[idx] == fs {
21+
return
22+
}
23+
24+
mfs.FSs[idx] = fs
25+
return
26+
}
27+
28+
// check first if the fs is already attached
29+
for _, f := range mfs.FSs {
30+
if f == fs {
31+
return
32+
}
33+
}
34+
35+
mfs.FSs = append(mfs.FSs, fs)
36+
}
37+
1438
func (mfs *MultiReadFileFS) Open(name string) (fs.File, error) {
1539
for _, fs := range mfs.FSs {
1640
if fs == nil {

0 commit comments

Comments
 (0)