Files
steampipe/pkg/interactive/autocomplete_suggestions.go
kaidaguerre 40804a3201 Execute RefreshConnections asyncronously and optimise for high connection count. Add connection_state table.
- Execute RefreshConnections asyncronously
- Add connection_state table to indicate the loading state of connections
- Optimise RefreshConnections by cloning connection schemas
- Add locking to ensure only a single instance of RefreshConnections runs
- Start executing queries without waiting for connections to load, add smart error handling to wait for required connection
- Optimise autocomplete for high connection count
- Autocomplete and inspect data available before all conections are refreshed
- Update file watcher to respond to CHMOD, so thaat it pickes up deletion of file contents

 Closes #3394
 Closes #3267
2023-05-10 09:05:08 +01:00

40 lines
982 B
Go

package interactive
import (
"github.com/c-bata/go-prompt"
"sort"
)
type autoCompleteSuggestions struct {
schemas []prompt.Suggest
unqualifiedTables []prompt.Suggest
unqualifiedQueries []prompt.Suggest
tablesBySchema map[string][]prompt.Suggest
queriesByMod map[string][]prompt.Suggest
mods []prompt.Suggest
}
func newAutocompleteSuggestions() *autoCompleteSuggestions {
return &autoCompleteSuggestions{
tablesBySchema: make(map[string][]prompt.Suggest),
queriesByMod: make(map[string][]prompt.Suggest),
}
}
func (s autoCompleteSuggestions) sort() {
sortSuggestions := func(s []prompt.Suggest) {
sort.Slice(s, func(i, j int) bool {
return s[i].Text < s[j].Text
})
}
sortSuggestions(s.schemas)
sortSuggestions(s.unqualifiedTables)
sortSuggestions(s.unqualifiedQueries)
for _, tables := range s.tablesBySchema {
sortSuggestions(tables)
}
for _, queries := range s.queriesByMod {
sortSuggestions(queries)
}
}