-
Notifications
You must be signed in to change notification settings - Fork 307
make contentChanges smaller in DidChangeTextDocumentParams #241
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 9 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
943e272
small diffs
mattn a076247
cosmetic changes
mattn d37e11e
cosmetic change
mattn 34d677a
should not be list
mattn d400e67
Fixes vint errors
mattn 7fd75b2
Fixes vint errors
mattn 1acd906
Remove content when buffer is closed
mattn b68a067
Check buffer exists
mattn b636095
Fix typo
mattn 72da9c1
Check textDocumentSync
mattn 5daa6b1
Use BufWipeout
mattn a8fb643
Hold file content per servers
mattn 4c79ed9
Add LICENSE-THIRD-PARTY
mattn aeb8f08
Remove debug code
mattn 6e41045
Comment for file_content
mattn 34d2022
Note that vim-lsp support incremental changes
mattn 6e1a499
use supports
prabirshrestha File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
" This is copied from https://github.com/natebosch/vim-lsc/blob/master/autoload/lsc/diff.vim | ||
mattn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
" | ||
" Computes a simplistic diff between [old] and [new]. | ||
" | ||
" Returns a dict with keys `range`, `rangeLength`, and `text` matching the LSP | ||
" definition of `TextDocumentContentChangeEvent`. | ||
" | ||
" Finds a single change between the common prefix, and common postfix. | ||
function! lsp#utils#diff#compute(old, new) abort | ||
mattn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let [l:start_line, l:start_char] = s:FirstDifference(a:old, a:new) | ||
let [l:end_line, l:end_char] = | ||
\ s:LastDifference(a:old[l:start_line :], a:new[l:start_line :], l:start_char) | ||
|
||
let l:text = s:ExtractText(a:new, l:start_line, l:start_char, l:end_line, l:end_char) | ||
let l:length = s:Length(a:old, l:start_line, l:start_char, l:end_line, l:end_char) | ||
|
||
let l:adj_end_line = len(a:old) + l:end_line | ||
let l:adj_end_char = l:end_line == 0 ? 0 : strlen(a:old[l:end_line]) + l:end_char + 1 | ||
|
||
let l:result = { 'range': {'start': {'line': l:start_line, 'character': l:start_char}, | ||
\ 'end': {'line': l:adj_end_line, 'character': l:adj_end_char}}, | ||
\ 'text': l:text, | ||
\ 'rangeLength': l:length, | ||
\} | ||
|
||
return l:result | ||
endfunction | ||
|
||
" Finds the line and character of the first different character between two | ||
" list of Strings. | ||
function! s:FirstDifference(old, new) abort | ||
let l:line_count = min([len(a:old), len(a:new)]) | ||
let l:i = 0 | ||
while l:i < l:line_count | ||
if a:old[l:i] !=# a:new[l:i] | break | endif | ||
let l:i += 1 | ||
endwhile | ||
if i >= l:line_count | ||
return [l:line_count - 1, strlen(a:old[l:line_count - 1])] | ||
endif | ||
let l:old_line = a:old[l:i] | ||
let l:new_line = a:new[l:i] | ||
let l:length = min([strlen(l:old_line), strlen(l:new_line)]) | ||
let l:j = 0 | ||
while l:j < l:length | ||
if l:old_line[l:j : l:j] !=# l:new_line[l:j : l:j] | break | endif | ||
let l:j += 1 | ||
endwhile | ||
return [l:i, l:j] | ||
endfunction | ||
|
||
function! s:LastDifference(old, new, start_char) abort | ||
let l:line_count = min([len(a:old), len(a:new)]) | ||
if l:line_count == 0 | return [0, 0] | endif | ||
let l:i = -1 | ||
while l:i >= -1 * l:line_count | ||
if a:old[l:i] !=# a:new[l:i] | break | endif | ||
let l:i -= 1 | ||
endwhile | ||
if l:i <= -1 * l:line_count | ||
let l:i = -1 * l:line_count | ||
let l:old_line = a:old[l:i][a:start_char :] | ||
let l:new_line = a:new[l:i][a:start_char :] | ||
else | ||
let l:old_line = a:old[l:i] | ||
let l:new_line = a:new[l:i] | ||
endif | ||
let l:length = min([strlen(l:old_line), strlen(l:new_line)]) | ||
let l:j = -1 | ||
while l:j >= -1 * l:length | ||
if l:old_line[l:j : l:j] !=# l:new_line[l:j : l:j] | break | endif | ||
let l:j -= 1 | ||
endwhile | ||
return [l:i, l:j] | ||
endfunction | ||
|
||
function! s:ExtractText(lines, start_line, start_char, end_line, end_char) abort | ||
if a:start_line == len(a:lines) + a:end_line | ||
if a:end_line == 0 | return '' | endif | ||
let l:result = a:lines[a:start_line][a:start_char : a:end_char] | ||
" json_encode treats empty string computed this was as 'null' | ||
if strlen(l:result) == 0 | let l:result = '' | endif | ||
return l:result | ||
endif | ||
let l:result = a:lines[a:start_line][a:start_char :]."\n" | ||
let l:adj_end_line = len(a:lines) + a:end_line | ||
for l:line in a:lines[a:start_line + 1:a:end_line - 1] | ||
let l:result .= l:line."\n" | ||
endfor | ||
if a:end_line != 0 | ||
let l:result .= a:lines[a:end_line][:a:end_char] | ||
endif | ||
return l:result | ||
endfunction | ||
|
||
function! s:Length(lines, start_line, start_char, end_line, end_char) | ||
\ abort | ||
let l:adj_end_line = len(a:lines) + a:end_line | ||
if l:adj_end_line >= len(a:lines) | ||
let l:adj_end_char = a:end_char - 1 | ||
else | ||
let l:adj_end_char = strlen(a:lines[l:adj_end_line]) + a:end_char | ||
endif | ||
if a:start_line == l:adj_end_line | ||
return l:adj_end_char - a:start_char + 1 | ||
endif | ||
let l:result = strlen(a:lines[a:start_line]) - a:start_char + 1 | ||
let l:line = a:start_line + 1 | ||
while l:line < l:adj_end_line | ||
let l:result += strlen(a:lines[l:line]) + 1 | ||
let l:line += 1 | ||
endwhile | ||
let l:result += l:adj_end_char + 1 | ||
return l:result | ||
endfunction |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.