-
Notifications
You must be signed in to change notification settings - Fork 8
/
filesystem_metadata.go
109 lines (82 loc) · 2.15 KB
/
filesystem_metadata.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package filesystem
import (
"path/filepath"
"github.com/Azure/azapi-lsp/internal/uri"
)
func (fs *fsystem) markDocumentAsOpen(dh DocumentHandler) error {
if !fs.documentMetadataExists(dh) {
return &UnknownDocumentErr{dh}
}
fs.docMetaMu.Lock()
defer fs.docMetaMu.Unlock()
fs.docMeta[dh.URI()].setOpen(true)
return nil
}
func (fs *fsystem) HasOpenFiles(dirPath string) (bool, error) {
files, err := fs.ReadDir(dirPath)
if err != nil {
return false, err
}
fs.docMetaMu.RLock()
defer fs.docMetaMu.RUnlock()
for _, fi := range files {
u := uri.FromPath(filepath.Join(dirPath, fi.Name()))
dm, ok := fs.docMeta[u]
if ok && dm.IsOpen() {
return true, nil
}
}
return false, nil
}
func (fs *fsystem) createDocumentMetadata(dh DocumentHandler, langId string, text []byte) error {
if fs.documentMetadataExists(dh) {
return &MetadataAlreadyExistsErr{dh}
}
fs.docMetaMu.Lock()
defer fs.docMetaMu.Unlock()
fs.docMeta[dh.URI()] = NewDocumentMetadata(dh, langId, text)
return nil
}
func (fs *fsystem) removeDocumentMetadata(dh DocumentHandler) error {
if !fs.documentMetadataExists(dh) {
return nil
}
fs.docMetaMu.Lock()
defer fs.docMetaMu.Unlock()
delete(fs.docMeta, dh.URI())
return nil
}
func (fs *fsystem) documentMetadataExists(dh DocumentHandler) bool {
fs.docMetaMu.RLock()
defer fs.docMetaMu.RUnlock()
_, ok := fs.docMeta[dh.URI()]
return ok
}
func (fs *fsystem) isDocumentOpen(dh DocumentHandler) (bool, error) {
fs.docMetaMu.RLock()
defer fs.docMetaMu.RUnlock()
dm, ok := fs.docMeta[dh.URI()]
if !ok {
return false, &UnknownDocumentErr{dh}
}
return dm.isOpen, nil
}
func (fs *fsystem) updateDocumentMetadataLines(dh VersionedDocumentHandler, b []byte) error {
if !fs.documentMetadataExists(dh) {
return &UnknownDocumentErr{dh}
}
fs.docMetaMu.Lock()
defer fs.docMetaMu.Unlock()
fs.docMeta[dh.URI()].updateLines(b)
fs.docMeta[dh.URI()].setVersion(dh.Version())
return nil
}
func (fs *fsystem) getDocumentMetadata(dh DocumentHandler) (*documentMetadata, error) {
fs.docMetaMu.RLock()
defer fs.docMetaMu.RUnlock()
dm, ok := fs.docMeta[dh.URI()]
if !ok {
return nil, &UnknownDocumentErr{dh}
}
return dm, nil
}