Girish Palya [Wed, 29 Nov 2023 12:17:55 +0000 (13:17 +0100)]
Propagate triggerCharacters to omni-completion
Fixed 2 bugs:
- add triggerCharacters to lsp list for omniComplete option
- process triggerCharacters based keywords in omnifunc()
M autoload/lsp/completion.vim
M autoload/lsp/lspserver.vim
Enno [Mon, 20 Nov 2023 08:24:31 +0000 (09:24 +0100)]
update default options
the documentation no longer reflected autoload/lsp/options.vim (lines 9-162):
export var lspOptions: dict<any> = {
# Enable ale diagnostics support.
# If true, diagnostics will be sent to ale, which will be responsible for
# showing them.
aleSupport: false,
# In insert mode, complete the current symbol automatically
# Otherwise, use omni-completion
autoComplete: true,
# In normal mode, highlight the current symbol automatically
autoHighlight: false,
# Automatically highlight diagnostics messages from LSP server
autoHighlightDiags: true,
# Automatically populate the location list with new diagnostics
autoPopulateDiags: false,
# icase | fuzzy | case match for language servers that replies with a full
# list of completion items
completionMatcher: 'case',
# Due to a bug in the earlier versions of Vim, cannot use the
# COMPLETIONMATCHER_CASE constant here for initialization.
completionMatcherValue: 1,
# Show the symbol documentation in the preview window instead of in a popup
hoverInPreview: false,
# Don't print message when a configured language server is missing.
ignoreMissingServer: false,
# Focus on the location list window after ":LspDiag show"
keepFocusInDiags: true,
# Focus on the location list window after LspShowReferences
keepFocusInReferences: true,
# If true, apply the LSP server supplied text edits after a completion.
# If a snippet plugin is going to apply the text edits, then set this to
# false to avoid applying the text edits twice.
completionTextEdit: true,
# Alignment of virtual diagnostic text, when showDiagWithVirtualText is true
# Allowed values: 'above' | 'below' | 'after' (default is 'above')
diagVirtualTextAlign: 'above',
# Suppress adding a new line on completion selection with <CR>
noNewlineInCompletion: false,
# Omni-completion support. To keep backward compatibility, this option is
# set to null by default instead of false.
omniComplete: null,
# Open outline window on right side
outlineOnRight: false,
# Outline window size
outlineWinSize: 20,
# Show diagnostic text in a balloon when the mouse is over the diagnostic
showDiagInBalloon: true,
# Make diagnostics show in a popup instead of echoing
showDiagInPopup: true,
# Suppress diagnostic hover from appearing when the mouse is over the line
# Show a diagnostic message on a status line
showDiagOnStatusLine: false,
# Show a diagnostic messages using signs
showDiagWithSign: true,
# Show a diagnostic messages with virtual text
showDiagWithVirtualText: false,
# enable inlay hints
showInlayHints: false,
# In insert mode, show the current symbol signature automatically
showSignature: true,
# enable snippet completion support
snippetSupport: false,
# enable SirVer/ultisnips completion support
ultisnipsSupport: false,
# add to autocomplition list current buffer words
useBufferCompletion: false,
# Use a floating menu to show the code action menu instead of asking for
# input
usePopupInCodeAction: false,
# ShowReferences in a quickfix list instead of a location list`
useQuickfixForLocations: false,
# enable hrsh7th/vim-vsnip completion support
vsnipSupport: false,
# Limit the time autocompletion searches for words in current buffer (in
# milliseconds)
bufferCompletionTimeout: 100,
# Enable support for custom completion kinds
customCompletionKinds: false,
# A dictionary with all completion kinds that you want to customize
completionKinds: {}
}
# set the LSP plugin options from the user provided option values
export def OptionsSet(opts: dict<any>)
lspOptions->extend(opts)
if !has('patch-9.0.0178')
lspOptions.showInlayHints = false
endif
if !has('patch-9.0.1157')
lspOptions.showDiagWithVirtualText = false
endif
# For faster comparison, convert the 'completionMatcher' option value from a
# string to a number.
if lspOptions.completionMatcher == 'icase'
lspOptions.completionMatcherValue = COMPLETIONMATCHER_ICASE
elseif lspOptions.completionMatcher == 'fuzzy'
lspOptions.completionMatcherValue = COMPLETIONMATCHER_FUZZY
else
lspOptions.completionMatcherValue = COMPLETIONMATCHER_CASE
endif
# Apply the changed options
if exists('#LspCmds#User#LspOptionsChanged')
:doautocmd <nomodeline> LspCmds User LspOptionsChanged
endif
enddef
Magnus Groß [Thu, 12 Oct 2023 23:08:06 +0000 (01:08 +0200)]
Avoid moving the cursor when applying textedits
In 33c9dc37bd354391579f669a142699801b13d571 we removed a workaround that
resets the cursor to the previous location after applying an
workspaceEdit, because it interfered with auto-imports.
Turns out the workaround was there for a reason: When we apply general
textedits (e.g. when we rename a variable), then we are always moving
the cursor by accident, because internally (to apply a textedit) we
delete the entire text range and then append the new range.
Obviously this loses the cursor position, hence the reason for the
original manual cursor reset workaround.
Instead of reintroducing that workaround, we now avoid moving the cursor
altogether: We accomplish this by no longer deleting the entire range
and inserting it again. Instead we just remove lines that actually need
to be deleted, add lines that actually need to be added and then handle
the rest with a normal setbufline() call.
This will cause the cursor to never lose the correct position, because
we never remove the entire region where the cursor is located in.
We have to be careful with off-by-one errors, therefore this also adds
an extra test for the scenario where we have to delete some lines. The
two other scenarios already had comprehensive tests (adding lines, and
keeping the amount of lines).
Magnus Groß [Mon, 4 Sep 2023 18:16:43 +0000 (20:16 +0200)]
Fix additionalTextEdits being ignored
Regression was introduced in 6f4fdc7bcc3a1ba041c6196b85b506bd0c207cf0.
The logic was still fine if the LSP server delayed the
additionalTextEdits field, but if we already got it, we ended up
ignoring it.
Fix this by checking for additionalTextEdits outside the delayed-resolve
condition.
Magnus Groß [Mon, 4 Sep 2023 15:50:12 +0000 (17:50 +0200)]
Do not reset cursor after workspaceEdit
The workspace edit may add or delete lines, so resetting it to the last
linenumber and column will very likely not match the last logical line
before the workspaceEdit operation.
For example an action might add an auto-import statement at the top of
the file, effectively adding one line in-between. If we now reset the
cursor, we will end up one logical line before the one where we actually
started at.
This behaviour is automatically fixed if we just don't reset the cursor
at all.
Magnus Groß [Sun, 3 Sep 2023 22:57:59 +0000 (00:57 +0200)]
Add support for CompletionItem commands
When we resolve a completion item with a "completionItem/resolve"
request, the LSP server returns a CompletionItem object [0], which may
contain an optional "command" field. This field describes a command that
must be called **after** inserting the completion.
For example the haskell-language-server may respond with the following
command after autocompleting an unimported function (arguments are left
out for brevity):
Then when we send the matching "workspace/executeCommand" request, the
server will respond with a "workspace/applyEdit" request, that
autoimports the function.
Technically the specification dictates that servers should prefer to set
"additionalTextEdits" for that usecase, but there is still some use for
doing it this way, e.g. haskell-language-server also wants to display an
info message to the user, which doesn't happen with
"additionalTextEdits".
In any case it is important to support the "command" field, as it may
also contain actions unrelated to "additionalTextEdits".
Girish Palya [Thu, 10 Aug 2023 17:26:34 +0000 (19:26 +0200)]
omnifunc documentation popup not throw error
When using Omni completion with other sources of completion items
that do not have 'user_data' dictionary, documentation popup should
not throw error.
I am using my own completion plugin with g:LspOmniFunc and I need
LSP to grab lazy-doc from lsp server. But it should not throw
error when user_data does not contain dictionary.
Add a function to find out if LSP server has replied with completion
matches. This is needed in case of using external completion engines
that expect asynchronous callback. LSP client simply acts as a source
of completion items through omnifunc (g:LspOmniFunc). Before calling
the omnifunc the second time g:LspOmniCompletePending can be checked
to see if LSP server is ready to provide completion items.
Update the client capabilities. Pass buffer number to autocmd handler functions. Send pending file changes to the language server before updating inlay hints and highlights
Magnus Groß [Tue, 11 Jul 2023 16:56:19 +0000 (18:56 +0200)]
Never show diagnostics when they are disabled
A regression was introduced in 6e4ba228eaa0770470060d8d47a360bd05a04ee5
that causes diagnostics to be displayed on buffer reload, even when the
user disabled them.
Fix this by moving the option check directly to DiagsRefresh.
Add the ":LspDiag" command and add sub-commands for the various Lsp
diagnostic functionality. Update the test scripts to use the new set of
commands. Add support for dynamically changing the value of the
diagnostic options. Remove the ":LspDiagHighlightEnable" and the
":LspDiagHighlightDisable" commands (these are replaced by the ":LspDiag
highlight" command)
Yegappan Lakshmanan [Thu, 29 Jun 2023 04:44:00 +0000 (21:44 -0700)]
Add an option (showDiagWithSign) to enable/disable placing signs on lines with diagnostics. Add separate virtual text highlight groups for each type of diagnostic