To register a LSP server, add the following lines to your .vimrc file (use only the LSP servers that you need from the below list). If you used [vim-plug](https://github.com/junegunn/vim-plug) to install the LSP plugin, the steps are described later in this section.
```
+ function! TypeScriptCustomNotificationHandler(lspserver, reply) abort
+ echom printf("TypeScript Version = %s", reply.params.version)
+ endfunction
let lspServers = [
\ #{
\ filetype: ['c', 'cpp'],
\ filetype: ['javascript', 'typescript'],
\ path: '/usr/local/bin/typescript-language-server',
\ args: ['--stdio']
+ \ customNotificationHandlers: {
+ \ '$/typescriptVersion': function('TypeScriptCustomNotificationHandler')
+ \ }
\ },
\ #{
\ filetype: 'sh',
path|complete path to the LSP server executable (without any arguments).
args|a list of command-line arguments passed to the LSP server. Each argument is a separate List item.
initializationOptions|User provided initialization options. May be of any type. For example the *intelephense* PHP language server accept several options here with the License Key among others.
+customNotificationHandlers|A dictionary of notifications and functions that can be specified to add support for custom language server notifications.
The LSP servers are added using the LspAddServer() function. This function accepts a list of LSP servers with the above information.
endif
enddef
-# silently ignore an unsupported notification message
-def IgnoreNotif(lspserver: dict<any>, reply: dict<any>)
-enddef
-
# process notification messages from the LSP server
export def ProcessNotif(lspserver: dict<any>, reply: dict<any>): void
var lsp_notif_handlers: dict<func> =
'window/showMessage': ProcessShowMsgNotif,
'window/logMessage': ProcessLogMsgNotif,
'textDocument/publishDiagnostics': ProcessDiagNotif,
- '$/progress': IgnoreNotif,
'$/logTrace': ProcessLogTraceNotif,
- '$/status/report': IgnoreNotif,
- '$/status/show': IgnoreNotif,
'telemetry/event': ProcessUnsupportedNotifOnce,
+ }
+
+ var lsp_ignored_notif_handlers: list<string> =
+ [
+ '$/progress',
+ '$/status/report',
+ '$/status/show',
# Java language server sends the 'language/status' notification which is
# not in the LSP specification
- 'language/status': IgnoreNotif,
+ 'language/status',
# Typescript language server sends the '$/typescriptVersion' notification
# which is not in the LSP specification
- '$/typescriptVersion': IgnoreNotif
- }
+ '$/typescriptVersion'
+ ]
if lsp_notif_handlers->has_key(reply.method)
lsp_notif_handlers[reply.method](lspserver, reply)
- else
+ elseif lspserver.customNotificationHandlers->has_key(reply.method)
+ lspserver.customNotificationHandlers[reply.method](lspserver, reply)
+ elseif lsp_ignored_notif_handlers->index(reply.method) == -1
util.ErrMsg($'Error: Unsupported notification received from LSP server {reply->string()}')
endif
enddef
initializationOptions = server.initializationOptions
endif
+ var customNotificationHandlers: dict<func> = {}
+ if server->has_key('customNotificationHandlers')
+ customNotificationHandlers = server.customNotificationHandlers
+ endif
+
if server.omnicompl->type() != v:t_bool
util.ErrMsg($'Error: Setting of omnicompl {server.omnicompl} is not a Boolean')
return
var lspserver: dict<any> = lserver.NewLspServer(server.path,
args,
server.syncInit,
- initializationOptions)
+ initializationOptions,
+ customNotificationHandlers)
var ftypes = server.filetype
if ftypes->type() == v:t_string
return symbol.TagFunc(lspserver, taglocations, pat)
enddef
-export def NewLspServer(path: string, args: list<string>, isSync: bool, initializationOptions: any): dict<any>
+export def NewLspServer(path: string, args: list<string>, isSync: bool, initializationOptions: any, customNotificationHandlers: dict<func>): dict<any>
var lspserver: dict<any> = {
path: path,
args: args,
syncInit: isSync,
initializationOptions: initializationOptions,
+ customNotificationHandlers: customNotificationHandlers,
running: false,
ready: false,
job: v:none,
or useful for initialization. Those can be provided in
this dictionary and if present will be transmitted to
the lsp server.
+ customNotificationHandlers
+ (Optional) some lsp servers (e.g.
+ typescript-language-server) will send additional
+ notifications which you might want to silence or handle.
+ The provided notification handlers will be called with a
+ reference to the 'lspserver' and the 'reply'.
omnicompl (Optional) a boolean value that enables (true)
or disables (false) omni-completion for this file
types. By default this is set to 'v:true'.