From 47790c42a48d366b44ca5a48a04e0a4c66e29ce5 Mon Sep 17 00:00:00 2001 From: Nate Bosch Date: Sun, 14 May 2017 15:05:30 -0700 Subject: [PATCH] Add line text to references quickfix items If the file is open in a buffer, use the bufnr and getbufline in the quickfix item. If the file is not yet open use the filename and readfile in the item. This is a little inefficient if we repeatedly read the same file up to varying lines, but hopefully disk caching will reduce the impact. --- autoload/lsc/reference.vim | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/autoload/lsc/reference.vim b/autoload/lsc/reference.vim index c0318847..1ac4c812 100644 --- a/autoload/lsc/reference.vim +++ b/autoload/lsc/reference.vim @@ -54,16 +54,26 @@ endfunction " 'range': {'start': {'line', 'character'}, 'end': {'line', 'character'}} " " QuickFix Item: (as used) -" 'filename': file path +" 'filename': file path if file is not open +" 'bufnr': buffer number if the file is open in a buffer " 'lnum': line number " 'col': column number +" 'text': The content of the referenced line " " LSP line and column are zero-based, vim is one-based. function! s:quickFixItem(location) abort - return {'filename': lsc#util#documentPath(a:location.uri), - \ 'lnum': a:location.range.start.line + 1, - \ 'col': a:location.range.start.character + 1 - \} + let item = {'lnum': a:location.range.start.line + 1, + \ 'col': a:location.range.start.character + 1} + let file_path = lsc#util#documentPath(a:location.uri) + let bufnr = bufnr(file_path) + if bufnr == -1 + let item.filename = file_path + let item.text = readfile(file_path, '', item.lnum)[item.lnum - 1] + else + let item.bufnr = bufnr + let item.text = getbufline(bufnr, item.lnum)[0] + endif + return item endfunction if !exists('s:initialized')