Skip to content

Commit

Permalink
feat(nav): fix! new dual sampling adapter, use for file/folders (#373)
Browse files Browse the repository at this point in the history
  • Loading branch information
plastikfan committed Nov 29, 2023
1 parent 9220a98 commit de47fcc
Show file tree
Hide file tree
Showing 10 changed files with 235 additions and 126 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"cSpell.words": [
"Aphex",
"argh",
"Assisable",
"avfs",
Expand Down
31 changes: 20 additions & 11 deletions xfs/nav/navigation-agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,10 @@ func (a *navigationAgent) traverse(params *agentTraverseParams) (*TraverseItem,
var current *TraverseItem

if a.samplingFilterActive {
inspection, found := a.cache[params.parent.key()]
inspection, found := a.cache[path]
current = lo.TernaryF(found,
func() *TraverseItem {
inspection.current.previewing = false
return inspection.current
},
func() *TraverseItem {
Expand All @@ -166,17 +167,20 @@ func (a *navigationAgent) traverse(params *agentTraverseParams) (*TraverseItem,
}
}

// fmt.Printf("===> πŸ’”πŸ’”πŸ’” agent.traverse - item: '%v' (admit: '%v', previewing: '%v')\n",

Check failure on line 170 in xfs/nav/navigation-agent.go

View workflow job for this annotation

GitHub Actions / lint

commentedOutCode: may want to remove commented-out code (gocritic)
// current.Path, current.admit, current.previewing,
// )

// AMBIENT-TECHNO

Check failure on line 174 in xfs/nav/navigation-agent.go

View workflow job for this annotation

GitHub Actions / lint

commentedOutCode: may want to remove commented-out code (gocritic)
// if strings.HasSuffix(current.Path, "AMBIENT-TECHNO") {
// fmt.Printf("===> πŸ“πŸ“πŸ“ folder.inspect [admit: %v] '%v'...\n",
// current.admit, current.Path,
// )
// }

if skipItem, err := params.impl.traverse(&traverseParams{
current: &TraverseItem{
Path: path,
Info: info,
Entry: entry,
Error: e,
Children: []fs.DirEntry{},
Parent: params.parent,
},
// πŸ’₯πŸ’₯πŸ’₯ current: current,
frame: params.frame,
current: current,
frame: params.frame,
}); skipItem == dontSkipTraverseItem {
if err != nil {
if errors.Is(err, fs.SkipDir) {
Expand Down Expand Up @@ -210,3 +214,8 @@ func (a *navigationAgent) traverse(params *agentTraverseParams) (*TraverseItem,

return dontSkipTraverseItem, nil
}

func (a *navigationAgent) keep(stash *inspection) {
a.cache[stash.current.key()] = stash
stash.current.filtered()
}
4 changes: 4 additions & 0 deletions xfs/nav/navigator-abstract.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,7 @@ func (n *navigator) ascend(navi *NavigationInfo) {
func (n *navigator) finish() error {
return n.log.Get().Sync()
}

func (n *navigator) keep(stash *inspection) {
n.agent.keep(stash)
}
1 change: 0 additions & 1 deletion xfs/nav/navigator-files.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ func (n *filesNavigator) top(frame *navigationFrame, root string) (*TraverseResu

func (n *filesNavigator) preview(params *traverseParams) *inspection {
stash := n.inspect(params)
n.agent.cache[params.current.key()] = stash

return stash
}
Expand Down
21 changes: 20 additions & 1 deletion xfs/nav/navigator-folders.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package nav

import (
"fmt"
"io/fs"
"strings"

"github.com/samber/lo"
)
Expand All @@ -27,8 +29,11 @@ func (n *foldersNavigator) top(frame *navigationFrame, root string) (*TraverseRe
}

func (n *foldersNavigator) preview(params *traverseParams) *inspection {
fmt.Printf("===> πŸ€πŸ€πŸ€ folders.preview - item: '%v'\n",
params.current.Path,
)

stash := n.inspect(params)
n.agent.cache[params.current.key()] = stash

return stash
}
Expand All @@ -47,6 +52,13 @@ func (n *foldersNavigator) inspect(params *traverseParams) *inspection {
stash.entries = stash.contents.Folders
stash.contents.sort(stash.entries)

// AMBIENT-TECHNO
if strings.HasSuffix(params.current.Path, "AMBIENT-TECHNO") {
fmt.Printf("===> πŸ‡πŸ‡πŸ‡ folder.inspect [admit: %v] '%v'...\n",
params.current.admit, params.current.Path,
)
}

if n.o.Store.Subscription == SubscribeFoldersWithFiles {
var files []fs.DirEntry

Expand Down Expand Up @@ -94,6 +106,13 @@ func (n *foldersNavigator) traverse(params *traverseParams) (*TraverseItem, erro
params.navi = navi
n.descend(navi)

// AMBIENT-TECHNO
if strings.HasSuffix(navi.Item.Path, "AMBIENT-TECHNO") {
fmt.Printf("===> πŸ‘πŸ‘πŸ‘ folder.traverse [admit: %v] '%v'...\n",
navi.Item.admit, navi.Item.Path,
)
}

// >>> fmt.Printf("\nπŸ₯πŸ₯πŸ₯ FOLDER-NAV: inspecting item: '%v'\n", params.current.Path)
stash := n.inspect(params)
entries := stash.entries
Expand Down
6 changes: 0 additions & 6 deletions xfs/nav/navigator-universal.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ func (n *universalNavigator) top(frame *navigationFrame, root string) (*Traverse
}

func (n *universalNavigator) preview(params *traverseParams) *inspection {
params.current.previewing = true
stash := n.inspect(params)
n.agent.cache[params.current.key()] = stash

return stash
}
Expand Down Expand Up @@ -85,10 +83,6 @@ func (n *universalNavigator) traverse(params *traverseParams) (*TraverseItem, er
}
}

if n.samplingFilterActive && navi.Item.admit {
return navi.Item, nil
}

if le := params.frame.proxy(params.current, nil); le != nil {
return nil, le
}
Expand Down
34 changes: 31 additions & 3 deletions xfs/nav/sampling-adapters.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"github.com/samber/lo"
)

const samplingFiles = true

func createSamplingAdapters() samplingAdaptersCollection {
universal := samplingAdapters{
slice: func(contents *DirectoryContents, noOf *SampleNoOf, fn sliceEntriesFunc) {
Expand All @@ -30,7 +32,20 @@ func createSamplingAdapters() samplingAdaptersCollection {
filterWithIt: func(contents *DirectoryContents, iterator *directoryEntryWhileIt) {
// πŸ’₯ contents.Files = iterator.sample(contents.Files)
// πŸ’₯ contents.Folders = iterator.sample(contents.Folders)
iterator.samples(contents)
// iterator.samplesL(contents)

// intended new universal functionality to match monomorphic form:
// for _, i := range contents.Folders {
// fmt.Printf("===> universal filterWithIt(before) 🍰🍰🍰 folder '%v'\n",
// i.Name(),
// )
// }
contents.Files, contents.Folders = iterator.samples(contents)
// for _, i := range contents.Folders {

Check failure on line 44 in xfs/nav/sampling-adapters.go

View workflow job for this annotation

GitHub Actions / lint

commentedOutCode: may want to remove commented-out code (gocritic)
// fmt.Printf("===> universal filterWithIt(after) 🍩🍩🍩 folder '%v'\n",
// i.Name(),
// )
// }
},
isFull: func(fi *FilteredInfo, noOf *SampleNoOf) bool {
if fi.Counts.Files == noOf.Files {
Expand All @@ -49,7 +64,18 @@ func createSamplingAdapters() samplingAdaptersCollection {
contents.Folders = fn(contents.Folders, int(noOf.Folders))
},
filterWithIt: func(contents *DirectoryContents, iterator *directoryEntryWhileIt) {
contents.Folders = iterator.sample(contents.Folders)
// iterator.samples(contents)
// for _, i := range contents.Folders {
// fmt.Printf("===> filterWithIt(before) 🍰🍰🍰 folder '%v'\n",
// i.Name(),
// )
// }
contents.Folders = iterator.sample(contents.Folders, !samplingFiles)
// for _, i := range contents.Folders {
// fmt.Printf("===> filterWithIt(after) 🍩🍩🍩 folder '%v'\n",
// i.Name(),
// )
// }
},
isFull: func(fi *FilteredInfo, noOf *SampleNoOf) bool {
return fi.Counts.Folders == noOf.Folders
Expand All @@ -61,7 +87,9 @@ func createSamplingAdapters() samplingAdaptersCollection {
contents.Files = fn(contents.Files, int(noOf.Files))
},
filterWithIt: func(contents *DirectoryContents, iterator *directoryEntryWhileIt) {
contents.Files = iterator.sample(contents.Files)
// iterator.samples(contents)
contents.Files = iterator.sample(contents.Files, samplingFiles)
// contents.Files = iterator.sample(contents.Files, true)
},
isFull: func(fi *FilteredInfo, noOf *SampleNoOf) bool {
return fi.Counts.Files == noOf.Files
Expand Down
Loading

0 comments on commit de47fcc

Please sign in to comment.