]> Sergey Matveev's repositories - vim-lsp.git/commitdiff
getbufoneline() is supported only starting from Vim 9.0.0916
authorYegappan Lakshmanan <yegappan@yahoo.com>
Thu, 1 Jun 2023 05:03:45 +0000 (22:03 -0700)
committerYegappan Lakshmanan <yegappan@yahoo.com>
Thu, 1 Jun 2023 05:03:45 +0000 (22:03 -0700)
autoload/lsp/outline.vim
autoload/lsp/symbol.vim
autoload/lsp/textedit.vim
autoload/lsp/util.vim
test/clangd_tests.vim

index 4665131904ae47223d679cc7a11f327c03db5e02..88d6a43bac56948a292354bb27880c568327ce89 100644 (file)
@@ -194,7 +194,7 @@ def OutlineHighlightCurrentSymbol()
 
   # 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()})
index 38725e1cd569dfff4bf7d064943b9bdd68a52ad3..0cf0edbba3a8f3001973b28853a5009c0b543210 100644 (file)
@@ -350,7 +350,7 @@ def PeekLocations(lspserver: dict<any>, locations: list<dict<any>>,
     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 @@ export def ShowLocations(lspserver: dict<any>, locations: list<dict<any>>,
     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,
index 02859dec25712ab1d507df2c812697ebcb163347..92cd74286979fe930b4f9ebe50ccf42a98a3d582 100644 (file)
@@ -173,7 +173,7 @@ export def ApplyTextEdits(bnr: number, text_edits: list<dict<any>>): void
   # lines.
   var dellastline: bool = false
   if start_line == 0 && bnr->getbufinfo()[0].linecount == 1 &&
-                                               bnr->getbufoneline(1) == ''
+                                       util.GetBufOneLine(bnr, 1) == ''
     dellastline = true
   endif
 
index a02f6556b176663974363f95893ca0482937dc79..2000ba233797d603fcda7b54ba89418dc80fa237 100644 (file)
@@ -290,4 +290,13 @@ export def FindNearestRootDir(startDir: string, files: list<any>): string
   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
index 7c29d3a2c233a9a2155738ed42396715c3d528fb..6177618c26eaded73dcc955113fde5fb80aa10a2 100644 (file)
@@ -464,14 +464,14 @@ def g:Test_LspDiag_Multi()
   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