/
document.go
73 lines (59 loc) · 1.27 KB
/
document.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
package filesystem
import (
"bytes"
"path/filepath"
"github.com/glennsarti/blog-wasm-vscode/lsp/internal/source"
"github.com/glennsarti/blog-wasm-vscode/lsp/internal/uri"
"github.com/spf13/afero"
)
type document struct {
meta *documentMetadata
fs afero.Fs
}
func (d *document) Text() ([]byte, error) {
return afero.ReadFile(d.fs, d.meta.dh.FullPath())
}
func (d *document) FullPath() string {
return d.meta.dh.FullPath()
}
func (d *document) Dir() string {
return filepath.Dir(d.meta.dh.FullPath())
}
func (d *document) Filename() string {
return filepath.Base(d.meta.dh.FullPath())
}
func (d *document) URI() string {
return uri.FromPath(d.meta.dh.FullPath())
}
func (d *document) Lines() source.Lines {
return d.meta.Lines()
}
func (d *document) Version() int {
return d.meta.Version()
}
func (d *document) LanguageID() string {
return d.meta.langId
}
func (d *document) IsOpen() bool {
return d.meta.IsOpen()
}
func (d *document) Equal(doc *document) bool {
if d.URI() != doc.URI() {
return false
}
if d.IsOpen() != doc.IsOpen() {
return false
}
if d.Version() != doc.Version() {
return false
}
leftB, err := d.Text()
if err != nil {
return false
}
rightB, err := doc.Text()
if err != nil {
return false
}
return bytes.Equal(leftB, rightB)
}