# filetype to LSP server map
var ftypeServerMap: dict<dict<any>> = {}
-# filetype to omnicompl map
-var omnicomplFtypeMap: dict<bool> = {}
+# per-filetype omni-completion enabled/disabled table
+var ftypeOmniCtrlMap: dict<bool> = {}
# Buffer number to LSP server map
var bufnrToServer: dict<dict<any>> = {}
ftypeServerMap->extend({[ftype]: lspserver})
enddef
-# Return bool of omnicompl for a specific filetype.
-# Return false if not found.
-def s:lspBoolOmnicompl(ftype: string): bool
- return omnicomplFtypeMap->get(ftype, v:false)
+# Returns true if omni-completion is enabled for filetype 'ftype'.
+# Otherwise, returns false.
+def s:lspOmniComplEnabled(ftype: string): bool
+ return ftypeOmniCtrlMap->get(ftype, v:false)
enddef
-# Reg bool of omnicompl for a filetype.
-def s:lspRegOmnicompl(ftype: string, omnicompl: bool)
- omnicomplFtypeMap->extend({[ftype]: omnicompl})
+# Enables or disables omni-completion for filetype 'fype'
+def s:lspOmniComplSet(ftype: string, enabled: bool)
+ ftypeOmniCtrlMap->extend({[ftype]: enabled})
enddef
def lsp#enableServerTrace()
# <Enter> in insert mode stops completion and inserts a <Enter>
inoremap <expr> <buffer> <CR> pumvisible() ? "\<C-Y>\<CR>" : "\<CR>"
else
- if s:lspBoolOmnicompl(ftype)
+ if s:lspOmniComplEnabled(ftype)
setbufvar(bnr, '&omnifunc', 'lsp#omniFunc')
endif
endif
continue
endif
if !server->has_key('omnicompl')
- # Default true if didnot reg
+ # Enable omni-completion by default
server['omnicompl'] = v:true
endif
return
endif
if server.omnicompl->type() != v:t_bool
- ErrMsg('Error: Setting of omnicompl ' .. server.omnicompl .. ' is not a Bool')
+ ErrMsg('Error: Setting of omnicompl ' .. server.omnicompl .. ' is not a Boolean')
return
endif
if server.filetype->type() == v:t_string
s:lspAddServer(server.filetype, lspserver)
- s:lspRegOmnicompl(server.filetype, server.omnicompl)
+ s:lspOmniComplSet(server.filetype, server.omnicompl)
elseif server.filetype->type() == v:t_list
for ftype in server.filetype
s:lspAddServer(ftype, lspserver)
- s:lspRegOmnicompl(server.filetype, server.omnicompl)
+ s:lspOmniComplSet(ftype, server.omnicompl)
endfor
else
ErrMsg('Error: Unsupported file type information "' ..
Author: Yegappan Lakshmanan (yegappan AT yahoo DOT com)
For Vim version 8.2.2342 and above
-Last change: Jan 31, 2021
+Last change: Feb 24, 2021
==============================================================================
*lsp-license*
any arguments).
args a list of command-line arguments passed to the LSP
server. Each argument is a separate List item.
+ omnicompl a boolean value that enables (true) or disables
+ (false) omni-completion for this file type.
The LSP servers are added using the lsp#addServer() function. This function
accepts a list of LSP servers with the above information.
server. To complete a symbol in insert mode manually, you can press CTRL-X
CTRL-O to invoke completion using the items suggested by the LSP server.
-And also indeed e.g: >
+You can also enable or disable omni-completion based on a file type by setting
+the 'omnicompl' item to 'false' when registering a lsp server for the
+filetype. If this item is not specified, then omni-completion is enabled by
+default. The following example disables omni-completion for python: >
let lspServers = [
- \ {
- \ 'filetype': ['javascript', 'typescript'],
- \ 'omnicompl': v:true,
- \ 'path': '/usr/local/bin/typescript-language-server',
- \ 'args': ['--stdio']
- \ },
\ {
\ 'filetype': 'python',
\ 'omnicompl': v:false,
\ }
\ ]
<
-adding "omnicompl" into configuration to set for specific ft, default is true.
-
==============================================================================
vim:tw=78:ts=8:noet:ft=help:norl: