@@ -24,19 +24,27 @@ return {
2424 filetypes = { ' vue' },
2525 root_markers = { ' package.json' },
2626 on_init = function (client )
27- client .handlers [' tsserver/request' ] = function (_ , result , context )
28- local ts_clients = vim .lsp .get_clients ({ bufnr = context .bufnr , name = ' ts_ls' })
29- local vtsls_clients = vim .lsp .get_clients ({ bufnr = context .bufnr , name = ' vtsls' })
30- local clients = {}
27+ local retries = 0
3128
32- vim .list_extend (clients , ts_clients )
33- vim .list_extend (clients , vtsls_clients )
29+ --- @param _ lsp.ResponseError
30+ --- @param result any
31+ --- @param context lsp.HandlerContext
32+ local function typescriptHandler (_ , result , context )
33+ local ts_client = vim .lsp .get_clients ({ bufnr = context .bufnr , name = ' ts_ls' })[1 ]
34+ or vim .lsp .get_clients ({ bufnr = context .bufnr , name = ' vtsls' })[1 ]
3435
35- if # clients == 0 then
36- vim .notify (' Could not find `ts_ls` or `vtsls` lsp client, required by `vue_ls`.' , vim .log .levels .ERROR )
36+ if not ts_client then
37+ -- there can sometimes be a short delay until `ts_ls`/`vtsls` are attached so we retry for a few times until it is ready
38+ if retries <= 10 then
39+ retries = retries + 1
40+ vim .defer_fn (function ()
41+ typescriptHandler (_ , result , context )
42+ end , 100 )
43+ else
44+ vim .notify (' Could not find `ts_ls` or `vtsls` lsp client, required by `vue_ls`.' , vim .log .levels .ERROR )
45+ end
3746 return
3847 end
39- local ts_client = clients [1 ]
4048
4149 local param = unpack (result )
4250 local id , command , payload = unpack (param )
@@ -53,5 +61,7 @@ return {
5361 client :notify (' tsserver/response' , response_data )
5462 end )
5563 end
64+
65+ client .handlers [' tsserver/request' ] = typescriptHandler
5666 end ,
5767}
0 commit comments