autoload/lsp/outline.vim | 2 +- autoload/lsp/symbol.vim | 4 ++-- autoload/lsp/textedit.vim | 2 +- autoload/lsp/util.vim | 9 +++++++++ test/clangd_tests.vim | 4 ++-- diff --git a/autoload/lsp/outline.vim b/autoload/lsp/outline.vim index 4665131904ae47223d679cc7a11f327c03db5e02..88d6a43bac56948a292354bb27880c568327ce89 100644 --- a/autoload/lsp/outline.vim +++ b/autoload/lsp/outline.vim @@ -194,7 +194,7 @@ endif # Highlight the selected symbol var col: number = - bnr->getbufoneline(symbolTable[mid].outlineLine)->match('\S') + 1 + util.GetBufOneLine(bnr, symbolTable[mid].outlineLine)->match('\S') + 1 prop_add(symbolTable[mid].outlineLine, col, {bufnr: bnr, type: 'LspOutlineHighlight', length: symbolTable[mid].name->len()}) diff --git a/autoload/lsp/symbol.vim b/autoload/lsp/symbol.vim index 38725e1cd569dfff4bf7d064943b9bdd68a52ad3..0cf0edbba3a8f3001973b28853a5009c0b543210 100644 --- a/autoload/lsp/symbol.vim +++ b/autoload/lsp/symbol.vim @@ -350,7 +350,7 @@ bnr->bufload() endif var lnum = range.start.line + 1 - var text: string = bnr->getbufoneline(lnum) + var text: string = util.GetBufOneLine(bnr, lnum) menuItems->add($'{lnum}: {text}') endfor @@ -392,7 +392,7 @@ endif if !bnr->bufloaded() bnr->bufload() endif - var text: string = bnr->getbufoneline(range.start.line + 1)->trim("\t ", 1) + var text: string = util.GetBufOneLine(bnr, range.start.line + 1)->trim("\t ", 1) qflist->add({filename: fname, lnum: range.start.line + 1, col: util.GetLineByteFromPos(bnr, range.start) + 1, diff --git a/autoload/lsp/textedit.vim b/autoload/lsp/textedit.vim index 02859dec25712ab1d507df2c812697ebcb163347..92cd74286979fe930b4f9ebe50ccf42a98a3d582 100644 --- a/autoload/lsp/textedit.vim +++ b/autoload/lsp/textedit.vim @@ -173,7 +173,7 @@ # extra empty line at the end. Delete the empty line after appending the # lines. var dellastline: bool = false if start_line == 0 && bnr->getbufinfo()[0].linecount == 1 && - bnr->getbufoneline(1) == '' + util.GetBufOneLine(bnr, 1) == '' dellastline = true endif diff --git a/autoload/lsp/util.vim b/autoload/lsp/util.vim index a02f6556b176663974363f95893ca0482937dc79..2000ba233797d603fcda7b54ba89418dc80fa237 100644 --- a/autoload/lsp/util.vim +++ b/autoload/lsp/util.vim @@ -290,4 +290,13 @@ # choose the longest matching path (the nearest directory from 'startDir') return sortedList[0] enddef +export def GetBufOneLine(bnr: number, lnum: number): string + if exists_compiled('*getbufoneline') + # getbufoneline() was introduced in patch 9.0.0916 + return bnr->getbufoneline(lnum) + else + return bnr->getbufline(lnum)[0] + endif +enddef + # vim: tabstop=8 shiftwidth=2 softtabstop=2 diff --git a/test/clangd_tests.vim b/test/clangd_tests.vim index 7c29d3a2c233a9a2155738ed42396715c3d528fb..6177618c26eaded73dcc955113fde5fb80aa10a2 100644 --- a/test/clangd_tests.vim +++ b/test/clangd_tests.vim @@ -464,14 +464,14 @@ :LspDiagHere assert_equal([1, 5], [line('.'), col('.')]) var ids = popup_list() assert_equal(1, ids->len()) - assert_match('Incompatible pointer to integer', getbufoneline(ids[0]->winbufnr(), 1, '$')) + assert_match('Incompatible pointer to integer', getbufoneline(ids[0]->winbufnr(), 1)) popup_clear() cursor(1, 6) :LspDiagHere assert_equal([1, 9], [line('.'), col('.')]) ids = popup_list() assert_equal(1, ids->len()) - assert_match('Initializer element is not', getbufoneline(ids[0]->winbufnr(), 1, '$')) + assert_match('Initializer element is not', getbufoneline(ids[0]->winbufnr(), 1)) popup_clear() # Line without diagnostics