cmd/012 no longer installs the cache as sheet.Remote before loading; EnableJEV sets it on the model's workbook, and on the workbooks it opens later. Tests set it on their sheet. The sheet.Remote global is gone.
- commit
- 4cdc7667799e817d1715b49d5f738d9d3a29e6da
- parent
- a064c75db0a2ff35ccdba178f47608c8d21aca3d
- author
- Dami <dami.etoile@gmail.com>
| M | cmd/ | 6 | +++--- |
| M | internal/ | 3 | +-- |
| M | internal/ | 5 | ----- |
| M | internal/ | 1 | - |
| M | internal/ | 5 | +++-- |
| M | internal/ | 6 | ------ |
| M | internal/ | 3 | +++ |
| M | internal/ | 3 | --- |
@@ -34,8 +34,9 @@ func run(args []string) error {
3434 }3535 defer stopTelemetry()3636 // JEV functions run when an API key is set, in the environment or a37- // .env file next to the sheet or in the current directory. The cache38- // goes in before loading so the file's JEV cells queue their questions.37+ // .env file next to the sheet or in the current directory. EnableJEV38+ // gives the workbook the cache, which has its JEV cells queue their39+ // questions.3940 var jevClient jev.Client4041 var jevCache *jev.Cache4142 dirs := []string{"."}@@ -48,7 +49,6 @@ func run(args []string) error {
4849 return fmt.Errorf("JEV: %w", err)4950 }5051 jevClient, jevCache = c, jev.NewCache()51- sheet.Remote = jevCache5252 }5353 5454 s, name := sheet.New(), ""@@ -133,8 +133,7 @@ func TestAsk(t *testing.T) {
133133 // the SDK's, which match the service.134134 func TestLimitsMatchSDK(t *testing.T) {135135 s := sheet.New()136- sheet.Remote = NewCache()137- defer func() { sheet.Remote = nil }()136+ s.SetRemote(NewCache())138137 labels := func(n int) string {139138 out := make([]string, n)140139 for i := range out {@@ -36,11 +36,6 @@ type RemoteSource interface {
3636 Lookup(RemoteCall) (RemoteAnswer, bool)3737 }3838 39-// Remote is the source new workbooks start with.40-//41-// Deprecated: set each workbook's source with SetRemote.42-var Remote RemoteSource43-4439 // SetRemote sets what answers the workbook's JEV functions: nil when no4540 // API key is configured, and the functions then evaluate to ErrNoRemote.4641 // It recomputes them, so a loaded file's questions are asked.@@ -72,7 +72,6 @@ func emptyBook() *Workbook {
7272 nameUsers: map[string]map[loc]struct{}{},7373 crossUsers: map[loc]struct{}{},7474 crossKeys: map[string]int{},75- remote: Remote,7675 }7776 }7877 @@ -32,10 +32,11 @@ type jevAnswerMsg struct {
3232 answer sheet.RemoteAnswer3333 }3434 35-// EnableJEV turns on JEV functions. The cache must already be installed36-// as sheet.Remote so loading a file queues its questions.35+// EnableJEV turns on JEV functions: the cache answers them, for this36+// workbook and those opened later, and the client asks what it lacks.3737 func (m *Model) EnableJEV(client jev.Client, cache *jev.Cache) {3838 m.jev = &jevRunner{client: client, cache: cache}39+ m.sheet.Book().SetRemote(cache)3940 }4041 4142 func init() {@@ -36,9 +36,6 @@ func jevModel(t *testing.T) (*Model, *fakeJEV) {
3636 t.Helper()3737 fake := &fakeJEV{noul: 0.9}3838 cache := jev.NewCache()39- prev := sheet.Remote40- sheet.Remote = cache41- t.Cleanup(func() { sheet.Remote = prev })4239 m := tallModel()4340 m.EnableJEV(fake, cache)4441 return m, fake@@ -99,9 +96,6 @@ func TestJEVPendingAndBusy(t *testing.T) {
9996 }10097 10198 func TestJEVWithoutKeyExplains(t *testing.T) {102- prev := sheet.Remote103- sheet.Remote = nil104- t.Cleanup(func() { sheet.Remote = prev })10599 m := tallModel()106100 press(t, m, `=JEV.TEST("x", "Q")`, "<enter>", "<up>")107101 if !strings.Contains(line(m, contextLine), "TYPESAFE_API_KEY") {@@ -254,6 +254,9 @@ func (m *Model) fail(msg string) {
254254 // state and the JEV connection.255255 func (m *Model) reset(s *sheet.Sheet, filename string) {256256 *m = Model{sheet: s, filename: filename, width: m.width, height: m.height, th: m.th, term: m.term, jev: m.jev, lastChart: -1}257+ if m.jev != nil {258+ s.Book().SetRemote(m.jev.cache)259+ }257260 }258261 259262 func isDigits(s string) bool {@@ -253,8 +253,6 @@ func BenchmarkJEV(b *testing.B) {
253253 b.Run(fmt.Sprint(n), func(b *testing.B) {254254 for b.Loop() {255255 cache := jev.NewCache()256- prev := sheet.Remote257- sheet.Remote = cache258256 s := sheet.New()259257 for i := range n {260258 s.Load(sheet.Addr{Row: i}, fmt.Sprintf("row %d", i), sheet.Format{}, sheet.Style{})@@ -269,7 +267,6 @@ func BenchmarkJEV(b *testing.B) {
269267 b.Fatalf("%d in flight, %d queued", in, q)270268 }271269 b.ReportMetric(float64(time.Since(start).Microseconds())/float64(n), "us/answer")272- sheet.Remote = prev273270 }274271 })275272 }