Skip to content

Commit

Permalink
Fixed reading doc sync kind from wrong place
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielViberg committed Sep 29, 2024
1 parent cc38690 commit 1e2d3fb
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 40 deletions.
2 changes: 1 addition & 1 deletion autoload/lsp/capabilities.vim
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ export def GetClientCaps(): dict<any>
augmentsSyntaxTokens: true
},
synchronization: {
dynamicRegistration: true,
dynamicRegistration: false,
didSave: true,
willSave: false,
WillSaveWaitUntil: false
Expand Down
75 changes: 36 additions & 39 deletions autoload/lsp/lspserver.vim
Original file line number Diff line number Diff line change
Expand Up @@ -614,51 +614,48 @@ def TextdocDidChange(lspserver: dict<any>, bnr: number, start: number,
# Notification: 'textDocument/didChange'
# Params: DidChangeTextDocumentParams

if lspserver.caps->has_key('textDocumentSync')
if lspserver.caps.textDocumentSync->type() == v:t_number

var changeset: list<dict<any>>
var params = {
textDocument: {
uri: util.LspBufnrToUri(bnr),
# Use Vim 'changedtick' as the LSP document version number
version: bnr->getbufvar('changedtick')
},
contentChanges: changeset
}
if lspserver.textDocumentSync->type() == v:t_number
var changeset: list<dict<any>>
var params = {
textDocument: {
uri: util.LspBufnrToUri(bnr),
# Use Vim 'changedtick' as the LSP document version number
version: bnr->getbufvar('changedtick')
},
contentChanges: changeset
}

if lspserver.caps.textDocumentSync == 1 ||
( start == 0 && end == 0 && added == 0 )
if lspserver.textDocumentSync == 1 ||
( start == 0 && end == 0 && added == 0 )
changeset = [{
text: bnr->getbufline(1, '$')->join("\n") .. "\n"
}]
endif

if lspserver.textDocumentSync == 2 &&
!(start == 0 && end == 0 && added == 0)
if changes->len() > 1
# As of now, only single line changes are incrementaly synced.
# This is because multi line changes seems to have edge cases in
# in how they should be interpeted. At least we'll see some
# performance gains
changeset = [{
text: bnr->getbufline(1, '$')->join("\n") .. "\n"
}]
else
for c in changes
var lines = getbufline(bnr, c.lnum, c.end - 1 + c.added)
var text = lines->len() > 0 ? lines->join("\n") .. "\n" : ''
changeset->add({range: { start: { line: c.lnum - 1, character: 0 },
end: { line: c.end - 1, character: 0 }},
text: text })
endfor
endif

if lspserver.caps.textDocumentSync == 2 &&
!(start == 0 && end == 0 && added == 0)
if changes->len() > 1
# As of now, only single line changes are incrementaly synced.
# This is because multi line changes seems to have edge cases in
# in how they should be interpeted. At least we'll see some
# performance gains
changeset = [{
text: bnr->getbufline(1, '$')->join("\n") .. "\n"
}]
else
for c in changes
var lines = getbufline(bnr, c.lnum, c.end - 1 + c.added)
var text = lines->len() > 0 ? lines->join("\n") .. "\n" : ''
changeset->add({range: { start: { line: c.lnum - 1, character: 0 },
end: { line: c.end - 1, character: 0 }},
text: text })
endfor
endif
endif
endif

params.contentChanges = changeset
if lspserver.caps.textDocumentSync != 0
lspserver.sendNotification('textDocument/didChange', params)
endif
params.contentChanges = changeset
if lspserver.textDocumentSync != 0
lspserver.sendNotification('textDocument/didChange', params)
endif
endif
enddef
Expand Down

0 comments on commit 1e2d3fb

Please sign in to comment.