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')
},
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
# 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 =~# ':$'
start_col = start + 1
endif
- complete(start_col, completeItems)
+ completeItems->complete(start_col)
else
lspserver.completeItems = completeItems
lspserver.omniCompletePending = false
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
# 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
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
# 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
# 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
# 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", " ", "")
var sortedDiags: list<number> = GetSortedDiagLines(lspserver, bnr)
if which == 'first'
- cursor(sortedDiags[0], 1)
+ [sortedDiags[0], 1]->cursor()
return
endif
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
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
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
# 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
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
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
# 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
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
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
# 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
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
# 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},
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',
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
# 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()})
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()
# 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
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!')
#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)
# 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:'