Skip to content

Commit 5c2c156

Browse files
committed
Fixed progress bar race condition
1 parent 18e31ef commit 5c2c156

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

Diff for: handler/progress.go

+9-7
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,10 @@ func (p *ProgressProxyHandler) handleProxy(id string, proxy *progressProxy) {
8585
}
8686

8787
case progressProxyCreated:
88-
p.mux.Unlock()
8988
err := p.conn.Notify(ctx, "$/progress", lsp.ProgressParams{
9089
Token: id,
9190
Value: lsp.Raw(proxy.beginReq),
9291
})
93-
p.mux.Lock()
9492

9593
proxy.beginReq = nil
9694
if err != nil {
@@ -101,11 +99,9 @@ func (p *ProgressProxyHandler) handleProxy(id string, proxy *progressProxy) {
10199

102100
case progressProxyBegin:
103101
if proxy.requiredStatus == progressProxyReport {
104-
p.mux.Unlock()
105102
err := p.conn.Notify(ctx, "$/progress", &lsp.ProgressParams{
106103
Token: id,
107104
Value: lsp.Raw(proxy.reportReq)})
108-
p.mux.Lock()
109105

110106
proxy.reportReq = nil
111107
if err != nil {
@@ -115,12 +111,10 @@ func (p *ProgressProxyHandler) handleProxy(id string, proxy *progressProxy) {
115111
}
116112

117113
} else if proxy.requiredStatus == progressProxyEnd {
118-
p.mux.Unlock()
119114
err := p.conn.Notify(ctx, "$/progress", &lsp.ProgressParams{
120115
Token: id,
121116
Value: lsp.Raw(proxy.endReq),
122117
})
123-
p.mux.Lock()
124118

125119
proxy.endReq = nil
126120
if err != nil {
@@ -157,6 +151,12 @@ func (p *ProgressProxyHandler) Begin(id string, req *lsp.WorkDoneProgressBegin)
157151
if !ok {
158152
return
159153
}
154+
if proxy.requiredStatus == progressProxyReport {
155+
return
156+
}
157+
if proxy.requiredStatus == progressProxyEnd {
158+
return
159+
}
160160

161161
proxy.beginReq = req
162162
proxy.requiredStatus = progressProxyBegin
@@ -171,7 +171,9 @@ func (p *ProgressProxyHandler) Report(id string, req *lsp.WorkDoneProgressReport
171171
if !ok {
172172
return
173173
}
174-
174+
if proxy.requiredStatus == progressProxyEnd {
175+
return
176+
}
175177
proxy.reportReq = req
176178
proxy.requiredStatus = progressProxyReport
177179
p.actionRequiredCond.Broadcast()

0 commit comments

Comments
 (0)