-
-
Notifications
You must be signed in to change notification settings - Fork 231
/
sourcemapcache.go
52 lines (44 loc) · 1.07 KB
/
sourcemapcache.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package proxy
import (
"sync"
"github.com/a-h/templ/parser/v2"
)
// NewSourceMapCache creates a cache of .templ file URIs to the source map.
func NewSourceMapCache() *SourceMapCache {
return &SourceMapCache{
m: new(sync.Mutex),
uriToSourceMap: make(map[string]*parser.SourceMap),
}
}
// SourceMapCache is a cache of .templ file URIs to the source map.
type SourceMapCache struct {
m *sync.Mutex
uriToSourceMap map[string]*parser.SourceMap
}
func (fc *SourceMapCache) Set(uri string, m *parser.SourceMap) {
fc.m.Lock()
defer fc.m.Unlock()
fc.uriToSourceMap[uri] = m
}
func (fc *SourceMapCache) Get(uri string) (m *parser.SourceMap, ok bool) {
fc.m.Lock()
defer fc.m.Unlock()
m, ok = fc.uriToSourceMap[uri]
return
}
func (fc *SourceMapCache) Delete(uri string) {
fc.m.Lock()
defer fc.m.Unlock()
delete(fc.uriToSourceMap, uri)
}
func (fc *SourceMapCache) URIs() (uris []string) {
fc.m.Lock()
defer fc.m.Unlock()
uris = make([]string, len(fc.uriToSourceMap))
var i int
for k := range fc.uriToSourceMap {
uris[i] = k
i++
}
return uris
}