From 8883bc082d28e6298d61e5d19c184bde2b8a7619 Mon Sep 17 00:00:00 2001 From: Yegappan Lakshmanan Date: Mon, 14 Nov 2022 21:46:53 -0800 Subject: [PATCH] Use the method calling convention for builtin functions consistently --- autoload/lsp/codeaction.vim | 8 ++++---- autoload/lsp/completion.vim | 14 +++++++------- autoload/lsp/diag.vim | 14 +++++++------- autoload/lsp/hover.vim | 4 ++-- autoload/lsp/lsp.vim | 6 +++--- autoload/lsp/lspserver.vim | 25 ++++++++++++++----------- autoload/lsp/markdown.vim | 2 +- autoload/lsp/outline.vim | 4 ++-- autoload/lsp/signature.vim | 6 +++--- autoload/lsp/symbol.vim | 4 ++-- autoload/lsp/textedit.vim | 2 +- autoload/lsp/util.vim | 2 +- 12 files changed, 47 insertions(+), 44 deletions(-) diff --git a/autoload/lsp/codeaction.vim b/autoload/lsp/codeaction.vim index 397c44e..213460b 100644 --- a/autoload/lsp/codeaction.vim +++ b/autoload/lsp/codeaction.vim @@ -52,7 +52,7 @@ export def ApplyCodeAction(lspserver: dict, actions: list>): void var text: list = [] var act: dict - for i in range(actions->len()) + for i in actions->len()->range() act = actions[i] var t: string = act.title->substitute('\r\n', '\\r\\n', 'g') t = t->substitute('\n', '\\n', 'g') @@ -88,10 +88,10 @@ export def ApplyCodeAction(lspserver: dict, actions: list>): void }, filter: (winid, key) => { if key == 'h' || key == 'l' - popup_close(winid, -1) - elseif str2nr(key) > 0 + winid->popup_close(-1) + elseif key->str2nr() > 0 # assume less than 10 entries are present - popup_close(winid, str2nr(key)) + winid->popup_close(key->str2nr()) else return popup_filter_menu(winid, key) endif diff --git a/autoload/lsp/completion.vim b/autoload/lsp/completion.vim index f8bbc00..a830e66 100644 --- a/autoload/lsp/completion.vim +++ b/autoload/lsp/completion.vim @@ -59,10 +59,10 @@ enddef # Remove all the snippet placeholders from 'str' and return the value. # Based on a similar function in the vim-lsp plugin. def MakeValidWord(str_arg: string): string - var str = substitute(str_arg, '\$[0-9]\+\|\${\%(\\.\|[^}]\)\+}', '', 'g') - str = substitute(str, '\\\(.\)', '\1', 'g') - var valid = matchstr(str, '^[^"'' (<{\[\t\r\n]\+') - if empty(valid) + var str = str_arg->substitute('\$[0-9]\+\|\${\%(\\.\|[^}]\)\+}', '', 'g') + str = str->substitute('\\\(.\)', '\1', 'g') + var valid = str->matchstr('^[^"'' (<{\[\t\r\n]\+') + if valid->empty() return str endif if valid =~# ':$' @@ -173,7 +173,7 @@ export def CompletionReply(lspserver: dict, cItems: any) start_col = start + 1 endif - complete(start_col, completeItems) + completeItems->complete(start_col) else lspserver.completeItems = completeItems lspserver.omniCompletePending = false @@ -339,7 +339,7 @@ def LspResolve() endif var item = v:event.completed_item - if item->has_key('user_data') && !empty(item.user_data) + if item->has_key('user_data') && !item.user_data->empty() lspserver.resolveCompletion(item.user_data) endif enddef @@ -348,7 +348,7 @@ enddef # then set the 'filetype' to 'lspgfm'. def LspSetFileType() var item = v:event.completed_item - if !item->has_key('user_data') || empty(item.user_data) + if !item->has_key('user_data') || item.user_data->empty() return endif diff --git a/autoload/lsp/diag.vim b/autoload/lsp/diag.vim index 85870c9..36056aa 100644 --- a/autoload/lsp/diag.vim +++ b/autoload/lsp/diag.vim @@ -34,7 +34,7 @@ def DiagsRefreshSigns(lspserver: dict, bnr: number) var signs: list> = [] for [lnum, diag] in lspserver.diagsMap[bnr]->items() signs->add({id: 0, buffer: bnr, group: 'LSPDiag', - lnum: str2nr(lnum), + lnum: lnum->str2nr(), name: DiagSevToSignName(diag.severity)}) endfor @@ -151,7 +151,7 @@ enddef # messages. # Returns true if diagnostics is not empty and false if it is empty. def DiagsUpdateLocList(lspserver: dict, bnr: number): bool - var fname: string = bufname(bnr)->fnamemodify(':p') + var fname: string = bnr->bufname()->fnamemodify(':p') if fname == '' return false endif @@ -210,8 +210,8 @@ enddef # the diagnostic message. def ShowDiagInPopup(diag: dict) var dlnum = diag.range.start.line + 1 - var ltext = getline(dlnum) - var dlcol = byteidx(ltext, diag.range.start.character + 1) + var ltext = dlnum->getline() + var dlcol = ltext->byteidx(diag.range.start.character + 1) var lastline = line('$') if dlnum > lastline @@ -266,7 +266,7 @@ export def ShowCurrentDiagInStatusLine(lspserver: dict) # 15 is a enough length not to cause line break var max_width = &columns - 15 var code = "" - if has_key(diag, 'code') + if diag->has_key('code') code = $'[{diag.code}] ' endif var msgNoLineBreak = code .. substitute(substitute(diag.message, "\n", " ", ""), "\\n", " ", "") @@ -310,7 +310,7 @@ export def LspDiagsJump(lspserver: dict, which: string): void var sortedDiags: list = GetSortedDiagLines(lspserver, bnr) if which == 'first' - cursor(sortedDiags[0], 1) + [sortedDiags[0], 1]->cursor() return endif @@ -319,7 +319,7 @@ export def LspDiagsJump(lspserver: dict, which: string): void for lnum in (which == 'next') ? sortedDiags : sortedDiags->reverse() if (which == 'next' && lnum > curlnum) || (which == 'prev' && lnum < curlnum) - cursor(lnum, 1) + [lnum, 1]->cursor() return endif endfor diff --git a/autoload/lsp/hover.vim b/autoload/lsp/hover.vim index dbdc17e..6374f42 100644 --- a/autoload/lsp/hover.vim +++ b/autoload/lsp/hover.vim @@ -69,8 +69,8 @@ export def HoverReply(lspserver: dict, hoverResult: any): void setlocal buftype=nofile setlocal bufhidden=delete bufnr()->deletebufline(1, '$') - append(0, hoverText) - cursor(1, 1) + hoverText->append(0) + [1, 1]->cursor() exe $'setlocal ft={hoverKind}' wincmd p else diff --git a/autoload/lsp/lsp.vim b/autoload/lsp/lsp.vim index 9fc0c8d..c26355a 100644 --- a/autoload/lsp/lsp.vim +++ b/autoload/lsp/lsp.vim @@ -344,7 +344,7 @@ enddef def AddBuffersToLsp(ftype: string) # Add all the buffers with the same file type as the current buffer for binfo in getbufinfo({bufloaded: 1}) - if getbufvar(binfo.bufnr, '&filetype') == ftype + if binfo.bufnr->getbufvar('&filetype') == ftype AddFile(binfo.bufnr) endif endfor @@ -363,7 +363,7 @@ export def RestartServer() # Remove all the buffers with the same file type as the current buffer var ftype: string = &filetype for binfo in getbufinfo() - if getbufvar(binfo.bufnr, '&filetype') == ftype + if binfo.bufnr->getbufvar('&filetype') == ftype RemoveFile(binfo.bufnr) endif endfor @@ -396,7 +396,7 @@ export def AddServer(serverList: list>) server['omnicompl'] = v:true endif - if !executable(server.path) + if !server.path->executable() if !opt.lspOptions.ignoreMissingServer util.ErrMsg($'Error: LSP server {server.path} is not found') endif diff --git a/autoload/lsp/lspserver.vim b/autoload/lsp/lspserver.vim index 0c3d4c1..20b753c 100644 --- a/autoload/lsp/lspserver.vim +++ b/autoload/lsp/lspserver.vim @@ -406,12 +406,12 @@ def InitServer(lspserver: dict) initparams.rootPath = curdir initparams.rootUri = util.LspFileToUri(curdir) initparams.workspaceFolders = [{ - name: fnamemodify(curdir, ':t'), + name: curdir->fnamemodify(':t'), uri: util.LspFileToUri(curdir) }] initparams.trace = 'off' initparams.capabilities = clientCaps - if !empty(lspserver.initializationOptions) + if !lspserver.initializationOptions->empty() initparams.initializationOptions = lspserver.initializationOptions endif @@ -519,12 +519,15 @@ enddef # send a response message to the server def SendResponse(lspserver: dict, request: dict, result: dict, error: dict) - if (type(request.id) == v:t_string && (trim(request.id) =~ '[^[:digit:]]\+' || trim(request.id) == '')) - || (type(request.id) != v:t_string && type(request.id) != v:t_number) + if (request.id->type() == v:t_string + && (request.id->trim() =~ '[^[:digit:]]\+' + || request.id->trim() == '')) + || (request.id->type() != v:t_string && request.id->type() != v:t_number) util.ErrMsg("Error: request.id of response to LSP server is not a correct number") return endif - var resp: dict = lspserver.createResponse(type(request.id) == v:t_string ? str2nr(request.id) : request.id) + var resp: dict = lspserver.createResponse( + request.id->type() == v:t_string ? request.id->str2nr() : request.id) if result->type() != v:t_none resp->extend({result: result}) else @@ -612,7 +615,7 @@ def AsyncRpcCb(lspserver: dict, method: string, RpcCb: func, chan: channel, endif if !reply->has_key('result') - util.ErrMsg($'Error(LSP): request {method} failed (no result or not yet somehow)') + util.ErrMsg($'Error(LSP): request {method} failed (no result)') return endif @@ -675,7 +678,7 @@ def TextdocDidOpen(lspserver: dict, bnr: number, ftype: string): void tdi.uri = util.LspBufnrToUri(bnr) tdi.languageId = ftype tdi.version = 1 - tdi.text = getbufline(bnr, 1, '$')->join("\n") .. "\n" + tdi.text = bnr->getbufline(1, '$')->join("\n") .. "\n" var params = {textDocument: tdi} lspserver.sendNotification('textDocument/didOpen', params) enddef @@ -740,7 +743,7 @@ def TextdocDidChange(lspserver: dict, bnr: number, start: number, # changeset->add({'range': range, 'text': lines}) # endfor - changeset->add({text: getbufline(bnr, 1, '$')->join("\n") .. "\n"}) + changeset->add({text: bnr->getbufline(1, '$')->join("\n") .. "\n"}) var params = {textDocument: vtdid, contentChanges: changeset} lspserver.sendNotification('textDocument/didChange', params) enddef @@ -1143,10 +1146,10 @@ def PrepareCallHierarchy(lspserver: dict): dict var choice: number = 1 if reply.result->len() > 1 var items: list = ['Select a Call Hierarchy Item:'] - for i in range(reply.result->len()) + for i in reply.result->len()->range() items->add(printf("%d. %s", i + 1, reply.result[i].name)) endfor - choice = inputlist(items) + choice = items->inputlist() if choice < 1 || choice > items->len() return {} endif @@ -1248,7 +1251,7 @@ def CodeAction(lspserver: dict, fname_arg: string, line1: number, # interface CodeActionParams var params: dict = {} - var fname: string = fnamemodify(fname_arg, ':p') + var fname: string = fname_arg->fnamemodify(':p') var bnr: number = fname_arg->bufnr() var r: dict> = { start: {line: line1 - 1, character: 0}, diff --git a/autoload/lsp/markdown.vim b/autoload/lsp/markdown.vim index 330a694..0c8f7d1 100644 --- a/autoload/lsp/markdown.vim +++ b/autoload/lsp/markdown.vim @@ -420,7 +420,7 @@ def CloseBlocks(document: dict>, blocks: list>, start: numbe endif last_block = blocks[0].type - for i in range(start) + for i in start->range() if blocks[i]->has_key("marker") if blocks[i].marker =~ '\S' line.props->add(GetMarkerProp('list_item', diff --git a/autoload/lsp/outline.vim b/autoload/lsp/outline.vim index 26dcae1..c6384e2 100644 --- a/autoload/lsp/outline.vim +++ b/autoload/lsp/outline.vim @@ -125,7 +125,7 @@ export def UpdateOutlineWindow(fname: string, var lnumMap: list> = [{}, {}] var text: list = [] AddSymbolText(fname->bufnr(), symbolTypeTable, '', text, lnumMap, false) - append('$', text) + text->append('$') w:lspSymbols = {filename: fname, lnumTable: lnumMap, symbolsByLine: symbolLineTable} :setlocal nomodifiable @@ -194,7 +194,7 @@ def OutlineHighlightCurrentSymbol() # Highlight the selected symbol var col: number = - match(getbufline(bnr, symbolTable[mid].outlineLine)[0], '\S') + 1 + bnr->getbufline(symbolTable[mid].outlineLine)[0]->match('\S') + 1 prop_add(symbolTable[mid].outlineLine, col, {bufnr: bnr, type: 'LspOutlineHighlight', length: symbolTable[mid].name->len()}) diff --git a/autoload/lsp/signature.vim b/autoload/lsp/signature.vim index d38d09f..1d8f447 100644 --- a/autoload/lsp/signature.vim +++ b/autoload/lsp/signature.vim @@ -75,11 +75,11 @@ export def SignatureHelp(lspserver: dict, sighelp: any): void if opt.lspOptions.echoSignature echon "\r\r" echon '' - echon strpart(text, 0, startcol) + echon text->strpart(0, startcol) echoh LineNr - echon strpart(text, startcol, hllen) + echon text->strpart(startcol, hllen) echoh None - echon strpart(text, startcol + hllen) + echon text->strpart(startcol + hllen) else # Close the previous signature popup and open a new one lspserver.signaturePopup->popup_close() diff --git a/autoload/lsp/symbol.vim b/autoload/lsp/symbol.vim index 110170a..82a087f 100644 --- a/autoload/lsp/symbol.vim +++ b/autoload/lsp/symbol.vim @@ -298,7 +298,7 @@ def PeekSymbolLocation(lspserver: dict, fname: string, # Highlight the symbol name and center the line in the popup var pwid = lspserver.peekSymbolPopup - var pwbuf = winbufnr(pwid) + var pwbuf = pwid->winbufnr() var pos: list = [] var start_col: number var end_col: number @@ -308,7 +308,7 @@ def PeekSymbolLocation(lspserver: dict, fname: string, pos->extend([start_col, end_col - start_col]) matchaddpos('Search', [pos], 10, 101, {window: pwid}) var cmds =<< trim eval END - cursor({location.range.start.line + 1}, 1) + [{location.range.start.line + 1}, 1]->cursor() normal! z. END win_execute(pwid, cmds, 'silent!') diff --git a/autoload/lsp/textedit.vim b/autoload/lsp/textedit.vim index 31bc368..061e8f9 100644 --- a/autoload/lsp/textedit.vim +++ b/autoload/lsp/textedit.vim @@ -74,7 +74,7 @@ def Set_lines(lines: list, A: list, B: list, #echomsg "lines(1) = " .. string(lines) # replace the previous lines with the new lines - for i in range(new_lines_len) + for i in new_lines_len->range() lines[i_0 + i] = new_lines[i] endfor #echomsg "lines(2) = " .. string(lines) diff --git a/autoload/lsp/util.vim b/autoload/lsp/util.vim index d982536..9b083c2 100644 --- a/autoload/lsp/util.vim +++ b/autoload/lsp/util.vim @@ -84,7 +84,7 @@ enddef # Convert a Vim filename to an LSP URI (file://) def ConvertFilenameToUri(fname: string): string - var uri: string = fnamemodify(fname, ':p') + var uri: string = fname->fnamemodify(':p') var on_windows: bool = false if uri =~? '^\a:' -- 2.48.1