1// Copyright 2019 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5package cache
6
7import (
8 "cuelang.org/go/internal/lsp/fscache"
9 "cuelang.org/go/internal/mod/modpkgload"
10 "cuelang.org/go/internal/mod/modrequirements"
11 "cuelang.org/go/mod/modconfig"
12)
13
14// New creates a new Cache.
15func New() (*Cache, error) {
16 modcfg := &modconfig.Config{
17 ClientType: "cuelsp",
18 }
19 reg, err := modconfig.NewRegistry(modcfg)
20 if err != nil {
21 return nil, err
22 }
23 return NewWithRegistry(reg), nil
24}
25
26// NewWithRegistry creates a new cache, using the specified registry.
27func NewWithRegistry(reg Registry) *Cache {
28 if reg == nil {
29 panic("nil registry")
30 }
31 return &Cache{
32 fs: fscache.NewCUECachedFS(),
33 registry: reg,
34 }
35}
36
37// A Cache holds content that is shared across multiple cuelsp
38// client/editor connections.
39type Cache struct {
40 fs *fscache.CUECacheFS
41 registry Registry
42}
43
44type Registry interface {
45 modrequirements.Registry
46 modpkgload.Registry
47}