]> Sergey Matveev's repositories - vim-lsp.git/commitdiff
Add support for the LspSetup user autocmd to add language servers and to set options...
authorYegappan Lakshmanan <yegappan@yahoo.com>
Wed, 14 Feb 2024 06:47:56 +0000 (22:47 -0800)
committerYegappan Lakshmanan <yegappan@yahoo.com>
Wed, 14 Feb 2024 06:47:56 +0000 (22:47 -0800)
README.md
doc/lsp.txt
plugin/lsp.vim

index b489cafcb8a0ba84cbc86e4c11d28ceb14ea2b68..011bfe26fb5324b12fa08bf856831dc0dd2707d4 100644 (file)
--- a/README.md
+++ b/README.md
@@ -157,10 +157,10 @@ call LspOptionsSet(#{
        \ })
 ```
 
-If you used [vim-plug](https://github.com/junegunn/vim-plug) to install the LSP plugin, then you need to use the VimEnter autocmd to initialize the LSP server and to set the LSP server options.  For example:
+If you used [vim-plug](https://github.com/junegunn/vim-plug) to install the LSP plugin, then you need to use the LspSetup User autocmd to initialize the LSP server and to set the LSP server options.  For example:
 ```viml
 let lspOpts = #{autoHighlightDiags: v:true}
-autocmd VimEnter * call LspOptionsSet(lspOpts)
+autocmd User LspSetup call LspOptionsSet(lspOpts)
 
 let lspServers = [#{
        \         name: 'clang',
@@ -168,7 +168,7 @@ let lspServers = [#{
        \         path: '/usr/local/bin/clangd',
        \         args: ['--background-index']
        \ }]
-autocmd VimEnter * call LspAddServer(lspServers)
+autocmd User LspSetup call LspAddServer(lspServers)
 ```
 
 ## Supported Commands
index 7db10965a201809e557c01aba05281f7ac41dd19..3c1e3fc9aba83881ea6901b63c8189b80af8d463 100644 (file)
@@ -3,7 +3,7 @@
 
 Author: Yegappan Lakshmanan  (yegappan AT yahoo DOT com)
 For Vim version 9.0 and above
-Last change: Feb 7, 2024
+Last change: Feb 13, 2024
 
 ==============================================================================
 CONTENTS                                                     *lsp-contents*
@@ -412,13 +412,13 @@ The language servers are added using the LspAddServer() function. This
 function accepts a list of language servers with the above information.
 
 If you used [vim-plug](https://github.com/junegunn/vim-plug) to install the
-LSP plugin, then you need to use the VimEnter autocmd to initialize the
+LSP plugin, then you need to use the LspSetup User autocmd to initialize the
 language server and to set the language server options.  For example: >
 
     vim9script
 
     var lspOpts = {autoHighlightDiags: true}
-    autocmd VimEnter * LspOptionsSet(lspOpts)
+    autocmd User LspSetup LspOptionsSet(lspOpts)
 
     var lspServers = [
                     {
@@ -428,7 +428,7 @@ language server and to set the language server options.  For example: >
                        args: ['--background-index']
                      }
                   ]
-    autocmd VimEnter * LspAddServer(lspServers)
+    autocmd User LspSetup LspAddServer(lspServers)
 <
                                                *lsp-options* *LspOptionsSet()*
                                                *g:LspOptionsSet()*
@@ -1581,6 +1581,13 @@ In the call hierarchy tree window, the following commands are supported:
 ==============================================================================
 11. Autocommands                               *lsp-autocmds*
 
+                                               *LspSetup*
+LspSetup                       A |User| autocommand fired when the LSP plugin
+                               is loaded.  Can be used to add language
+                               servers using the |LspAddServer()| function
+                               and to set plugin options using the
+                               |LspOptionsSet()| function.
+
                                                *LspAttached*
 LspAttached                    A |User| autocommand fired when the LSP client
                                attaches to a buffer. Can be used to configure
index 49d667710609d60ddb853e0610e007852c28812b..9125b6eb65f5306d625eb1863b43a83058d30153 100644 (file)
@@ -3,10 +3,13 @@ if !has('vim9script') ||  v:version < 900
   finish
 endif
 
-vim9script
+vim9script noclear
 
 # Language Server Protocol (LSP) plugin for vim
 
+if get(g:, 'loaded_lsp', false)
+  finish
+endif
 g:loaded_lsp = true
 
 import '../autoload/lsp/options.vim'
@@ -150,4 +153,9 @@ if has('gui_running')
   endif
 endif
 
+# Invoke autocmd to register LSP servers and to set LSP options
+if exists('#User#LspSetup')
+  :doautocmd <nomodeline> User LspSetup
+endif
+
 # vim: shiftwidth=2 softtabstop=2