Skip to content

Commit 6703eda

Browse files
authored
Improve performance placing signs and virtual text (#1455)
Since the functions don't change the linecount, call getbufinfo(...).linecount once rather than many times.
1 parent 7d59166 commit 6703eda

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

autoload/lsp/internal/diagnostics/signs.vim

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ if !hlexists('LspHintText')
2525
highlight link LspHintText Normal
2626
endif
2727

28+
" imports
29+
let s:Buffer = vital#lsp#import('VS.Vim.Buffer')
30+
2831
function! lsp#internal#diagnostics#signs#_enable() abort
2932
" don't even bother registering if the feature is disabled
3033
if !lsp#utils#_has_signs() | return | endif
@@ -127,15 +130,13 @@ function! s:set_signs(params) abort
127130
endfunction
128131

129132
function! s:place_signs(server, diagnostics_response, bufnr) abort
133+
let l:linecount = s:Buffer.get_line_count(a:bufnr)
130134
for l:item in lsp#utils#iteratable(a:diagnostics_response['params']['diagnostics'])
131135
let l:line = lsp#utils#position#lsp_line_to_vim(a:bufnr, l:item['range']['start'])
132136

133137
" Some language servers report an unexpected EOF one line past the end
134-
" key 'linecount' may be missing.
135-
if has_key(getbufinfo(a:bufnr)[0], 'linecount')
136-
if l:line == getbufinfo(a:bufnr)[0].linecount + 1
137-
let l:line = l:line - 1
138-
endif
138+
if l:line == l:linecount + 1
139+
let l:line = l:line - 1
139140
endif
140141

141142
if has_key(l:item, 'severity') && !empty(l:item['severity'])

autoload/lsp/internal/diagnostics/virtual_text.vim

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ if !hlexists('LspHintVirtualText')
4040
endif
4141
endif
4242

43+
" imports
44+
let s:Buffer = vital#lsp#import('VS.Vim.Buffer')
45+
4346
function! lsp#internal#diagnostics#virtual_text#_enable() abort
4447
" don't even bother registering if the feature is disabled
4548
if !lsp#utils#_has_nvim_virtual_text() && !lsp#utils#_has_vim_virtual_text() | return | endif
@@ -156,13 +159,14 @@ function! s:set_virtual_text(params) abort
156159
endfunction
157160

158161
function! s:place_virtual_text(server, diagnostics_response, bufnr) abort
162+
let l:linecount = s:Buffer.get_line_count(a:bufnr)
159163
for l:item in lsp#utils#iteratable(a:diagnostics_response['params']['diagnostics'])
160164
let l:line = lsp#utils#position#lsp_line_to_vim(a:bufnr, l:item['range']['start'])
161165
let l:name = get(s:severity_sign_names_mapping, get(l:item, 'severity', 3), 'LspError')
162166
let l:text = g:lsp_diagnostics_virtual_text_prefix . l:item['message']
163167

164168
" Some language servers report an unexpected EOF one line past the end
165-
if l:line == getbufinfo(a:bufnr)[0].linecount + 1
169+
if l:line == l:linecount + 1
166170
let l:line = l:line - 1
167171
endif
168172

@@ -174,7 +178,7 @@ function! s:place_virtual_text(server, diagnostics_response, bufnr) abort
174178
else
175179
" it's an error to add virtual text on lines that don't exist
176180
" anymore due to async processing, just skip such diagnostics
177-
if l:line <= getbufinfo(a:bufnr)[0].linecount
181+
if l:line <= l:linecount
178182
let l:type = 'vim_lsp_' . l:name . '_virtual_text'
179183
call prop_remove({'all': v:true, 'type': l:type, 'bufnr': a:bufnr}, l:line)
180184
call prop_add(

0 commit comments

Comments
 (0)