27
27
28
28
--- creates a resolver that searches for a local executable and caches results by bufnr
29
29
--- @param prefix string | nil
30
- M .make_generic_resolver = function (prefix )
30
+ M .generic = function (prefix )
31
31
--- @param params NullLsParams
32
32
--- @return string | nil
33
33
return cache .by_bufnr (function (params )
@@ -41,42 +41,44 @@ M.make_generic_resolver = function(prefix)
41
41
end )
42
42
end
43
43
44
- local node_modules_resolver = M .make_generic_resolver (u .path .join (" node_modules" , " .bin" ))
45
- --- resolver that searches for a local node_modules executable and falls back to a global executable
46
- M .from_node_modules = function (params )
47
- return node_modules_resolver (params ) or params .command
44
+ --- creates a resolver that searches for a local node_modules executable and falls back to a global executable
45
+ M .from_node_modules = function ()
46
+ local node_modules_resolver = M .generic (u .path .join (" node_modules" , " .bin" ))
47
+ return function (params )
48
+ return node_modules_resolver (params ) or params .command
49
+ end
48
50
end
49
51
50
- --- resolver that searches for a local yarn pnp executable and falls back to a global executable
51
- --- @param params NullLsParams
52
- --- @return string | string[] | nil
53
- M .from_yarn_pnp = cache .by_bufnr (function (params )
54
- local ok , yarn_command = pcall (function ()
55
- local root = params .root
56
- if not root then
57
- error (" unable to resolve root directory" )
58
- end
52
+ --- creates a resolver that searches for a local yarn pnp executable and falls back to a global executable
53
+ M .from_yarn_pnp = function ()
54
+ return cache .by_bufnr (function (params )
55
+ local ok , yarn_command = pcall (function ()
56
+ local root = params .root
57
+ if not root then
58
+ error (" unable to resolve root directory" )
59
+ end
59
60
60
- -- older yarn versions use `.pnp.js`, so look for both new and old names
61
- local pnp_executable , pnp_dir = search_ancestors_for_executable (params .bufname , root , " .pnp.cjs" )
62
- if not (pnp_executable and pnp_dir ) then
63
- pnp_executable , pnp_dir = search_ancestors_for_executable (params .bufname , root , " .pnp.js" )
64
- end
65
- if not (pnp_executable and pnp_dir ) then
66
- error (" failed to find yarn executable" )
67
- end
61
+ -- older yarn versions use `.pnp.js`, so look for both new and old names
62
+ local pnp_executable , pnp_dir = search_ancestors_for_executable (params .bufname , root , " .pnp.cjs" )
63
+ if not (pnp_executable and pnp_dir ) then
64
+ pnp_executable , pnp_dir = search_ancestors_for_executable (params .bufname , root , " .pnp.js" )
65
+ end
66
+ if not (pnp_executable and pnp_dir ) then
67
+ error (" failed to find yarn executable" )
68
+ end
68
69
69
- local yarn_bin_cmd =
70
- string.format (" cd %s && yarn bin %s" , vim .fn .shellescape (pnp_dir ), vim .fn .shellescape (params .command ))
71
- local yarn_bin = vim .fn .system (yarn_bin_cmd ):gsub (" %s+" , " " )
72
- if vim .v .shell_error ~= 0 then
73
- error (" failed to get yarn bin" )
74
- end
70
+ local yarn_bin_cmd =
71
+ string.format (" cd %s && yarn bin %s" , vim .fn .shellescape (pnp_dir ), vim .fn .shellescape (params .command ))
72
+ local yarn_bin = vim .fn .system (yarn_bin_cmd ):gsub (" %s+" , " " )
73
+ if vim .v .shell_error ~= 0 then
74
+ error (" failed to get yarn bin" )
75
+ end
75
76
76
- return { " node" , " --require" , pnp_executable , yarn_bin }
77
- end )
77
+ return { " node" , " --require" , pnp_executable , yarn_bin }
78
+ end )
78
79
79
- return ok and yarn_command or params .command
80
- end )
80
+ return ok and yarn_command or params .command
81
+ end )
82
+ end
81
83
82
84
return M
0 commit comments