From 148dba59b015b65968070815a20ec3de3a229e0a Mon Sep 17 00:00:00 2001 From: "shane.xb.qian" Date: Tue, 6 Jun 2023 11:59:20 +0800 Subject: [PATCH] fix: util.GetBufOneLine is a bit useless --- autoload/lsp/outline.vim | 2 +- autoload/lsp/symbol.vim | 4 ++-- autoload/lsp/textedit.vim | 2 +- autoload/lsp/util.vim | 17 ++--------------- 4 files changed, 6 insertions(+), 19 deletions(-) diff --git a/autoload/lsp/outline.vim b/autoload/lsp/outline.vim index ad0cc36..2979d20 100644 --- a/autoload/lsp/outline.vim +++ b/autoload/lsp/outline.vim @@ -194,7 +194,7 @@ def OutlineHighlightCurrentSymbol() # Highlight the selected symbol var col: number = - util.GetBufOneLine(bnr, symbolTable[mid].outlineLine)->match('\S') + 1 + bnr->getbufline(symbolTable[mid].outlineLine)->get(0, '')->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 136d99a..5914f92 100644 --- a/autoload/lsp/symbol.vim +++ b/autoload/lsp/symbol.vim @@ -349,7 +349,7 @@ def PeekLocations(lspserver: dict, locations: list>, bnr->bufload() var lnum = range.start.line + 1 - var text: string = util.GetBufOneLine(bnr, lnum) + var text: string = bnr->getbufline(lnum)->get(0, '') menuItems->add($'{lnum}: {text}') endfor @@ -389,7 +389,7 @@ export def ShowLocations(lspserver: dict, locations: list>, bnr = fname->bufadd() endif bnr->bufload() - var text: string = util.GetBufOneLine(bnr, range.start.line + 1)->trim("\t ", 1) + var text: string = bnr->getbufline(range.start.line + 1)->get(0, '')->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 374d907..00c0172 100644 --- a/autoload/lsp/textedit.vim +++ b/autoload/lsp/textedit.vim @@ -171,7 +171,7 @@ export def ApplyTextEdits(bnr: number, text_edits: list>): void # lines. var dellastline: bool = false if start_line == 0 && bnr->getbufinfo()[0].linecount == 1 && - util.GetBufOneLine(bnr, 1)->empty() + bnr->getbufline(1)->get(0, '')->empty() dellastline = true endif diff --git a/autoload/lsp/util.vim b/autoload/lsp/util.vim index 220d14c..708e8b8 100644 --- a/autoload/lsp/util.vim +++ b/autoload/lsp/util.vim @@ -169,7 +169,7 @@ export def GetLineByteFromPos(bnr: number, pos: dict): number # Need a loaded buffer to read the line and compute the offset bnr->bufload() - var ltext: string = GetBufOneLine(bnr, pos.line + 1) + var ltext: string = bnr->getbufline(pos.line + 1)->get(0, '') if ltext->empty() return col endif @@ -196,7 +196,7 @@ export def GetCharIdxWithoutCompChar(bnr: number, pos: dict): number # Need a loaded buffer to read the line and compute the offset bnr->bufload() - var ltext: string = GetBufOneLine(bnr, pos.line + 1) + var ltext: string = bnr->getbufline(pos.line + 1)->get(0, '') if ltext->empty() return col endif @@ -353,17 +353,4 @@ export def FindNearestRootDir(startDir: string, files: list): 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 - var l = bnr->getbufline(lnum) - if l->empty() - return '' - endif - return l[0] - endif -enddef - # vim: tabstop=8 shiftwidth=2 softtabstop=2 -- 2.48.1