return {}
endif
- # LSP server is configured to be a provider for 'feature'
+ # LSP server is configured to be a provider for "feature"
for lspserver in possibleLSPs
if lspserver.features->has_key(feature) && lspserver.features[feature]
return lspserver
return {}
enddef
-# Returns the LSP server for the buffer 'bnr' and with ID 'id'. Returns an empty
+# Returns the LSP server for the buffer "bnr" and with ID "id". Returns an empty
# dict if the server is not found.
export def BufLspServerGetById(bnr: number, id: number): dict<any>
if !bufnrToServers->has_key(bnr)
return {}
enddef
-# Returns the LSP servers for the buffer 'bnr'. Returns an empty list if the
+# Returns the LSP servers for the buffer "bnr". Returns an empty list if the
# servers are not found.
export def BufLspServersGet(bnr: number): list<dict<any>>
if !bufnrToServers->has_key(bnr)
return bufnrToServers[bnr]
enddef
-# Returns the LSP server for the current buffer with the optionally 'feature'.
+# Returns the LSP server for the current buffer with the optionally "feature".
# Returns an empty dict if the server is not found.
export def CurbufGetServer(feature: string = null_string): dict<any>
return BufLspServerGet(bufnr(), feature)
return !lspserver->empty()
enddef
-# Returns the LSP server for the current buffer with the optinally 'feature' if
+# Returns the LSP server for the current buffer with the optinally "feature" if
# it is running and is ready.
# Returns an empty dict if the server is not found or is not ready.
export def CurbufGetServerChecked(feature: string = null_string): dict<any>
util.JumpToLspLocation(item, '')
enddef
-# Refresh the call hierarchy tree for the symbol at index 'idx'.
+# Refresh the call hierarchy tree for the symbol at index "idx".
def CallHierarchyTreeItemRefresh(idx: number)
var treeItem: dict<any> = w:LspCallHierItemMap[idx]
endif
if !treeItem->has_key('children')
- # First time retrieving the children for the item at index 'idx'
+ # First time retrieving the children for the item at index "idx"
var lspserver = buf.BufLspServerGet(w:LspBufnr)
if lspserver->empty() || !lspserver.running
return
# textDocument/codeAction can return either Command[] or CodeAction[].
# If it is a CodeAction, it can have either an edit, a command or both.
# Edits should be executed first.
- # Both Command and CodeAction interfaces has 'command' member
- # so we should check 'command' type - for Command it will be 'string'
+ # Both Command and CodeAction interfaces has "command" member
+ # so we should check "command" type - for Command it will be "string"
if selAction->has_key('edit')
|| (selAction->has_key('command') && selAction.command->type() == v:t_dict)
# selAction is a CodeAction instance, apply edit and command
'Buffer': 'B',
}
-# Returns true if omni-completion is enabled for filetype 'ftype'.
+# Returns true if omni-completion is enabled for filetype "ftype".
# Otherwise, returns false.
def LspOmniComplEnabled(ftype: string): bool
return ftypeOmniCtrlMap->get(ftype, false)
enddef
-# Enables or disables omni-completion for filetype 'fype'
+# Enables or disables omni-completion for filetype "fype"
export def OmniComplSet(ftype: string, enabled: bool)
ftypeOmniCtrlMap->extend({[ftype]: enabled})
enddef
return kindValue
enddef
-# Remove all the snippet placeholders from 'str' and return the value.
+# 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 = str_arg->substitute('\$[0-9]\+\|\${\%(\\.\|[^}]\)\+}', '', 'g')
endif
enddef
-# If the completion popup documentation window displays 'markdown' content,
-# then set the 'filetype' to 'lspgfm'.
+# If the completion popup documentation window displays "markdown" content,
+# then set the 'filetype' to "lspgfm".
def LspSetPopupFileType()
var item = v:event.completed_item
if !item->has_key('user_data') || item.user_data->empty()
})
enddef
-# Remove the diagnostics stored for buffer 'bnr'
+# Remove the diagnostics stored for buffer "bnr"
export def DiagRemoveFile(bnr: number)
if diagsMap->has_key(bnr)
diagsMap->remove(bnr)
endif
enddef
-# Refresh the placed diagnostics in buffer 'bnr'
+# Refresh the placed diagnostics in buffer "bnr"
# This inline signs, inline props, and virtual text diagnostics
def DiagsRefresh(bnr: number)
bnr->bufload()
# New LSP diagnostic messages received from the server for a file.
# Update the signs placed in the buffer for this file
export def ProcessNewDiags(bnr: number)
- if opt.lspOptions.autoPopulateDiags
- DiagsUpdateLocList(bnr)
- endif
+ DiagsUpdateLocList(bnr)
if opt.lspOptions.aleSupport
SendAleDiags(bnr, -1)
# Update the location list window for the current window with the diagnostic
# messages.
# Returns true if diagnostics is not empty and false if it is empty.
-def DiagsUpdateLocList(bnr: number): bool
+def DiagsUpdateLocList(bnr: number, calledByCmd: bool = false): bool
var fname: string = bnr->bufname()->fnamemodify(':p')
if fname->empty()
return false
endif
var LspQfId: number = bnr->getbufvar('LspQfId', 0)
+ if LspQfId->empty() && !opt.lspOptions.autoPopulateDiags && !calledByCmd
+ # If a location list for the diagnostics was not opened previously,
+ # and 'autoPopulateDiags' is set to false, then do nothing.
+ return false
+ endif
+
if !LspQfId->empty() && getloclist(0, {id: LspQfId}).id != LspQfId
+ # Previously used location list for the diagnostics is gone
LspQfId = 0
endif
# Display the diagnostic messages from the LSP server for the current buffer
# in a location list
export def ShowAllDiags(): void
- if !DiagsUpdateLocList(bufnr())
+ if !DiagsUpdateLocList(bufnr(), true)
util.WarnMsg($'No diagnostic messages found for {@%}')
return
endif
endif
enddef
-# Display the message of 'diag' in a popup window right below the position in
+# Display the message of "diag" in a popup window right below the position in
# the diagnostic message.
def ShowDiagInPopup(diag: dict<any>)
var dlnum = diag.range.start.line + 1
popup_create(msg, ppopts)
enddef
-# Display the 'diag' message in a popup or in the status message area
+# Display the "diag" message in a popup or in the status message area
def DisplayDiag(diag: dict<any>)
if opt.lspOptions.showDiagInPopup
# Display the diagnostic message in a popup window.
'$/progress',
'$/status/report',
'$/status/show',
- # PHP intelephense server sends the 'indexingStarted' and
- # 'indexingEnded' notifications which is not in the LSP specification.
+ # PHP intelephense server sends the "indexingStarted" and
+ # "indexingEnded" notifications which is not in the LSP specification.
'indexingStarted',
'indexingEnded',
# Java language server sends the 'language/status' notification which is
:setlocal nomodifiable
enddef
-# Create a new window containing the buffer 'bname' or if the window is
+# Create a new window containing the buffer "bname" or if the window is
# already present then jump to it.
def OpenScratchWindow(bname: string)
var wid = bufwinid(bname)
endif
enddef
-# Get LSP server running status for filetype 'ftype'
+# Get LSP server running status for filetype "ftype"
# Return true if running, or false if not found or not running
export def ServerRunning(ftype: string): bool
if ftypeServerMap->has_key(ftype)
enddef
# The LSP server is considered ready when the server capabilities are
-# received ('initialize' LSP reply message)
+# received ("initialize" LSP reply message)
export def ServerReady(): bool
var fname: string = @%
if fname->empty()
return 0
enddef
-# process the 'initialize' method reply from the LSP server
+# process the "initialize" method reply from the LSP server
# Result: InitializeResult
def ServerInitReply(lspserver: dict<any>, initResult: dict<any>): void
if initResult->empty()
endif
enddef
-# Request: 'initialize'
+# Request: "initialize"
# Param: InitializeParams
def InitServer(lspserver: dict<any>, bnr: number)
# interface 'InitializeParams'
return false
enddef
-# Display the file specified by LSP 'LocationLink' in a popup window and
-# highlight the range in 'location'.
+# Display the file specified by LSP "LocationLink" in a popup window and
+# highlight the range in "location".
def PeekSymbolLocation(lspserver: dict<any>, location: dict<any>)
var [uri, range] = util.LspLocationParse(location)
var fname = util.LspUriToFile(uri)
import './util.vim'
import './symbol.vim'
-# Parse the type hierarchy in 'typeHier' and displays a tree of type names
+# Parse the type hierarchy in "typeHier" and displays a tree of type names
# in the current buffer. This function is called recursively to display the
# super/sub type hierarchy.
#
util.JumpToLspLocation(typeUriMap[selIdx - 1], '')
enddef
-# Show the super or sub type hierarchy items 'types' as a tree in a popup window
+# Show the super or sub type hierarchy items "types" as a tree in a popup
+# window
export def ShowTypeHierarchy(lspserver: dict<any>, isSuper: bool, types: dict<any>)
if lspserver.typeHierPopup->winbufnr() != -1
return LspFileToUri(bnr->bufname())
enddef
-# Returns the byte number of the specified LSP position in buffer 'bnr'.
+# Returns the byte number of the specified LSP position in buffer "bnr".
# LSP's line and characters are 0-indexed.
# Vim's line and columns are 1-indexed.
# Returns a zero-indexed column.
}]}, 't')
enddef
-# Jump to the LSP 'location'. The 'location' contains the file name, line
+# Jump to the LSP "location". The "location" contains the file name, line
# number and character number. The user specified window command modifiers
-# (e.g. topleft) are in 'cmdmods'.
+# (e.g. topleft) are in "cmdmods".
export def JumpToLspLocation(location: dict<any>, cmdmods: string)
var [uri, range] = LspLocationParse(location)
var fname = LspUriToFile(uri)
GetCharIdxWithoutCompChar(bufnr(), range.start) + 1)
enddef
-# 'indexof' is to new to use it, use this instead.
+# indexof() function is not present in older Vim 9 versions. So use this
+# function.
export def Indexof(list: list<any>, CallbackFn: func(number, any): bool): number
var ix = 0
for val in list
enddef
# Find the nearest root directory containing a file or directory name from the
-# list of names in 'files' starting with the directory 'startDir'.
+# list of names in "files" starting with the directory "startDir".
# Based on a similar implementation in the vim-lsp plugin.
-# Searches upwards starting with the directory 'startDir'.
+# Searches upwards starting with the directory "startDir".
# If a file name ends with '/' or '\', then it is a directory name, otherwise
# it is a file name.
-# Returns '' if none of the file and directory names in 'files' can be found
+# Returns '' if none of the file and directory names in "files" can be found
# in one of the parent directories.
export def FindNearestRootDir(startDir: string, files: list<any>): string
var foundDirs: dict<bool> = {}
return b->len() - a->len()
})
- # choose the longest matching path (the nearest directory from 'startDir')
+ # choose the longest matching path (the nearest directory from "startDir")
return sortedList[0]
enddef
The |:LspDiagShow| command creates a new location list with the current list
of diagnostics for the current buffer. To automatically add the diagnostics
messages to the location list, you can set the 'autoPopulateDiags' option to
-true. By default this option is set to false.
+true. By default this option is set to false. When new diagnostics are
+received for a buffer, if a location list with the diagnostics is already
+present, then it is refreshed with the new diagnostics.
When using GUI Vim or in a terminal Vim with 'ballooneval' option set, when
the mouse is moved over the diagnostic sign displayed in the sign column, then
:%bw!
enddef
+# Diag location list should be automatically updated when the list of diags
+# changes.
+def g:Test_DiagLocListAutoUpdate()
+ :silent! edit XdiagLocListAutoUpdate.c
+ :sleep 200m
+ setloclist(0, [], 'f')
+ var lines: list<string> =<< trim END
+ int i:
+ int j;
+ END
+ setline(1, lines)
+ var bnr = bufnr()
+ g:WaitForServerFileLoad(1)
+ :redraw!
+
+ :LspDiagShow
+ assert_equal(1, line('$'))
+ wincmd w
+ setline(2, 'int j:')
+ redraw!
+ g:WaitForDiags(2)
+ wincmd w
+ assert_equal(2, line('$'))
+ wincmd w
+ deletebufline('', 1, '$')
+ redraw!
+ g:WaitForDiags(0)
+ wincmd w
+ assert_equal([''], getline(1, '$'))
+ :lclose
+
+ setloclist(0, [], 'f')
+ :%bw!
+enddef
+
# Test that the client have been able to configure the server to speak utf-32
def g:Test_UnicodeColumnCalc()
:silent! edit XUnicodeColumn.c
popup_clear()
:%bw!
-
-
enddef
# Test for :LspShowSignature