mirror of
https://github.com/golang/go
synced 2024-11-18 10:54:40 -07:00
internal/lsp/fake: don't lock while calling formatting
While trying to be pragmatic, I simply locked the fake.Editor while calling textDocument/formatting. This did indeed manifest later on as a deadlock, so instead we release the lock but fail if the buffer version changes while awaiting the formatting call. Change-Id: I0ca24a502f3118e76de306a016449bbe665e70e4 Reviewed-on: https://go-review.googlesource.com/c/tools/+/228230 Run-TryBot: Robert Findley <rfindley@google.com> Reviewed-by: Rebecca Stambler <rstambler@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
3bb7580c69
commit
6a72e3782c
@ -537,16 +537,20 @@ func (e *Editor) FormatBuffer(ctx context.Context, path string) error {
|
||||
if e.server == nil {
|
||||
return nil
|
||||
}
|
||||
// Because textDocument/formatting has no versions, we must block while
|
||||
// performing formatting.
|
||||
e.mu.Lock()
|
||||
defer e.mu.Unlock()
|
||||
version := e.buffers[path].version
|
||||
e.mu.Unlock()
|
||||
params := &protocol.DocumentFormattingParams{}
|
||||
params.TextDocument.URI = e.ws.URI(path)
|
||||
resp, err := e.server.Formatting(ctx, params)
|
||||
if err != nil {
|
||||
return fmt.Errorf("textDocument/formatting: %v", err)
|
||||
}
|
||||
e.mu.Lock()
|
||||
defer e.mu.Unlock()
|
||||
if versionAfter := e.buffers[path].version; versionAfter != version {
|
||||
return fmt.Errorf("before receipt of formatting edits, buffer version changed from %d to %d", version, versionAfter)
|
||||
}
|
||||
edits := convertEdits(resp)
|
||||
return e.editBufferLocked(ctx, path, edits)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user