]> Sergey Matveev's repositories - vim-lsp.git/commitdiff
Use the method calling convention for builtin functions consistently
authorYegappan Lakshmanan <yegappan@yahoo.com>
Tue, 15 Nov 2022 05:46:53 +0000 (21:46 -0800)
committerYegappan Lakshmanan <yegappan@yahoo.com>
Tue, 15 Nov 2022 05:46:53 +0000 (21:46 -0800)
12 files changed:
autoload/lsp/codeaction.vim
autoload/lsp/completion.vim
autoload/lsp/diag.vim
autoload/lsp/hover.vim
autoload/lsp/lsp.vim
autoload/lsp/lspserver.vim
autoload/lsp/markdown.vim
autoload/lsp/outline.vim
autoload/lsp/signature.vim
autoload/lsp/symbol.vim
autoload/lsp/textedit.vim
autoload/lsp/util.vim

index 397c44e835c7f1a52d4cb772c1794faa7408a691..213460be94290678f112257dadf89b8ffc0f31a5 100644 (file)
@@ -52,7 +52,7 @@ export def ApplyCodeAction(lspserver: dict<any>, actions: list<dict<any>>): void
 
   var text: list<string> = []
   var act: dict<any>
-  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<any>, actions: list<dict<any>>): 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
index f8bbc0010d557664496d48f12fdbcd295a0fa7d0..a830e660aa8cefa486114d6102ffbbf482e35927 100644 (file)
@@ -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<any>, 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
 
index 85870c974153cb92805f5574cbc1c1faae376b92..36056aabc5f8a2221e9d7b17a4e4462ea0400d1e 100644 (file)
@@ -34,7 +34,7 @@ def DiagsRefreshSigns(lspserver: dict<any>, bnr: number)
   var signs: list<dict<any>> = []
   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<any>, 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<any>)
   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<any>)
     # 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<any>, which: string): void
   var sortedDiags: list<number> = 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<any>, 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
index dbdc17e728d54a7648f5c2651ce52b46f2075b21..6374f424f22f77eff0ce4375d97d7fbd12d9633c 100644 (file)
@@ -69,8 +69,8 @@ export def HoverReply(lspserver: dict<any>, 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
index 9fc0c8dccd61f5f6f4e3a5bc3fce42197c9053d5..c26355a99da67d41384f2d88b52da66aeab90e5c 100644 (file)
@@ -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<dict<any>>)
       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
index 0c3d4c12e1277fb64684c726a0d5250a08c56fd6..20b753c3d0d246a8919f653c8cdc6af967e0c58f 100644 (file)
@@ -406,12 +406,12 @@ def InitServer(lspserver: dict<any>)
   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<any>, request: dict<any>, result: dict<any>, error: dict<any>)
-  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<any> = lspserver.createResponse(type(request.id) == v:t_string ? str2nr(request.id) : request.id)
+  var resp: dict<any> = 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<any>, 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<any>, 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<any>, 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<any>): dict<any>
   var choice: number = 1
   if reply.result->len() > 1
     var items: list<string> = ['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<any>, fname_arg: string, line1: number,
 
   # interface CodeActionParams
   var params: dict<any> = {}
-  var fname: string = fnamemodify(fname_arg, ':p')
+  var fname: string = fname_arg->fnamemodify(':p')
   var bnr: number = fname_arg->bufnr()
   var r: dict<dict<number>> = {
                  start: {line: line1 - 1, character: 0},
index 330a69456ac1c8af2f49289ea8c8aa828e0cf279..0c8f7d10fcd17e82f62fc8e9b8162cf48367fe06 100644 (file)
@@ -420,7 +420,7 @@ def CloseBlocks(document: dict<list<any>>, blocks: list<dict<any>>, 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',
index 26dcae1c8aa2db906b2e153eb354496d9bea2f0c..c6384e2e1e7c851c1572cf95b384296066a77c05 100644 (file)
@@ -125,7 +125,7 @@ export def UpdateOutlineWindow(fname: string,
   var lnumMap: list<dict<any>> = [{}, {}]
   var text: list<string> = []
   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()})
index d38d09ff06abd6a6a940b6548c1cc1e212d52edb..1d8f447efeaabc3c23cacb2bbc07a395427e6cc7 100644 (file)
@@ -75,11 +75,11 @@ export def SignatureHelp(lspserver: dict<any>, 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()
index 110170a04545bb4e40acac3433409d9584cff2a0..82a087f1255234373b4c62012a26b00f2ff60e9b 100644 (file)
@@ -298,7 +298,7 @@ def PeekSymbolLocation(lspserver: dict<any>, 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<number> = []
   var start_col: number
   var end_col: number
@@ -308,7 +308,7 @@ def PeekSymbolLocation(lspserver: dict<any>, 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!')
index 31bc3685af669746823a3c208783353199d7dd7d..061e8f97bd56748f456cf6b0631dde3a06d62090 100644 (file)
@@ -74,7 +74,7 @@ def Set_lines(lines: list<string>, A: list<number>, B: list<number>,
   #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)
index d98253617d115e01c5c6ab3d3f16fdcb4ffef2be..9b083c275df1b9f5bc6419cba3d817900879c344 100644 (file)
@@ -84,7 +84,7 @@ enddef
 
 # Convert a Vim filename to an LSP URI (file://<absolute_path>)
 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:'