Ensure correct ordering of notifications

This commit is contained in:
Zachary Yedidia 2020-08-16 12:35:08 -04:00
parent 98b3ed0eec
commit 01f55a6c79
3 changed files with 13 additions and 8 deletions

View file

@ -161,7 +161,7 @@ func (b *SharedBuffer) lspDidChange(start, end Loc, text string) {
}
if b.HasLSP() {
b.Server.DidChange(b.AbsPath, &b.version, []lspt.TextDocumentContentChangeEvent{change})
b.Server.DidChange(b.AbsPath, b.version, []lspt.TextDocumentContentChangeEvent{change})
}
}
@ -428,7 +428,7 @@ func (b *Buffer) lspInit() {
if len(bytes) == 0 {
bytes = []byte{'\n'}
}
b.Server.DidOpen(b.AbsPath, ft, string(bytes), &b.version)
b.Server.DidOpen(b.AbsPath, ft, string(bytes), b.version)
}
}
}

View file

@ -5,11 +5,11 @@ import (
"go.lsp.dev/uri"
)
func (s *Server) DidOpen(filename, language, text string, version *uint64) {
func (s *Server) DidOpen(filename, language, text string, version uint64) {
doc := lsp.TextDocumentItem{
URI: uri.File(filename),
LanguageID: lsp.LanguageIdentifier(language),
Version: float64(*version), // not sure why this is a float on go.lsp.dev
Version: float64(version), // not sure why this is a float on go.lsp.dev
Text: text,
}
@ -31,12 +31,12 @@ func (s *Server) DidSave(filename string) {
go s.sendNotification(lsp.MethodTextDocumentDidSave, params)
}
func (s *Server) DidChange(filename string, version *uint64, changes []lsp.TextDocumentContentChangeEvent) {
func (s *Server) DidChange(filename string, version uint64, changes []lsp.TextDocumentContentChangeEvent) {
doc := lsp.VersionedTextDocumentIdentifier{
TextDocumentIdentifier: lsp.TextDocumentIdentifier{
URI: uri.File(filename),
},
Version: version,
Version: &version,
}
params := lsp.DidChangeTextDocumentParams{

View file

@ -266,8 +266,8 @@ func (s *Server) sendNotification(method string, params interface{}) error {
}
s.lock.Lock()
defer s.lock.Unlock()
return s.sendMessage(m)
go s.sendMessageUnlock(m)
return nil
}
func (s *Server) sendRequest(method string, params interface{}) ([]byte, error) {
@ -315,3 +315,8 @@ func (s *Server) sendMessage(m interface{}) error {
_, err = s.stdin.Write(msg)
return err
}
func (s *Server) sendMessageUnlock(m interface{}) error {
defer s.lock.Unlock()
return s.sendMessage(m)
}