@@ -13,12 +13,20 @@ import (
13
13
14
14
// represents the state of a single document
15
15
type DocumentState struct {
16
- Content string // the content of the document
17
- Uri uri.URI // the uri from the client
18
- Path string // the filepath as parsed from the uri
19
- Module * ast.Module // the corresponding ddp module
20
- NeedReparse atomic.Bool // whether the document needs to be reparsed
21
- parseMutex sync.Mutex // the mutex used for parsing
16
+ Content string // the content of the document
17
+ Uri uri.URI // the uri from the client
18
+ Path string // the filepath as parsed from the uri
19
+ Module * ast.Module // the corresponding ddp module
20
+ NeedReparse atomic.Bool // whether the document needs to be reparsed
21
+ LatestErrors []ddperror.Error // the errors from the last parsing
22
+ parseMutex sync.Mutex // the mutex used for parsing
23
+ }
24
+
25
+ func (d * DocumentState ) newErrorCollector () ddperror.Handler {
26
+ d .LatestErrors = make ([]ddperror.Error , 0 , 10 )
27
+ return func (err ddperror.Error ) {
28
+ d .LatestErrors = append (d .LatestErrors , err )
29
+ }
22
30
}
23
31
24
32
func (d * DocumentState ) reParseInContext (modules map [string ]* ast.Module , errorHandler ddperror.Handler ) (err error ) {
@@ -74,10 +82,10 @@ func (dm *DocumentManager) AddAndParse(vscURI, content string) error {
74
82
dm .documentStates [docURI ] = docState
75
83
dm .mu .Unlock ()
76
84
77
- return dm .ReParse (docURI , ddperror . EmptyHandler )
85
+ return dm .reParse (docURI , docState . newErrorCollector () )
78
86
}
79
87
80
- func (dm * DocumentManager ) ReParse (docUri uri.URI , errHndl ddperror.Handler ) error {
88
+ func (dm * DocumentManager ) reParse (docUri uri.URI , errHndl ddperror.Handler ) error {
81
89
dm .mu .RLock ()
82
90
defer dm .mu .RUnlock ()
83
91
@@ -107,7 +115,7 @@ func (dm *DocumentManager) Get(vscURI string) (*DocumentState, bool) {
107
115
// it was not being parsed, so we unlock the mutex
108
116
// which will be locked again by ReParse
109
117
doc .parseMutex .Unlock ()
110
- ok = dm .ReParse (doc .Uri , ddperror . EmptyHandler ) == nil
118
+ ok = dm .reParse (doc .Uri , doc . newErrorCollector () ) == nil
111
119
} else {
112
120
// if it is being currently reparsed we wait for it to finish
113
121
// by aquiring the mutex and then immediately unlock and return it
0 commit comments