@@ -13,18 +13,24 @@ local M = {
13
13
--- @return nil | string node_version_error
14
14
function M .get_node_version ()
15
15
if not M .node_version then
16
- local cmd = { M .node_command , " --version" }
17
- local cmd_output_table = vim .fn .executable (M .node_command ) == 1 and vim .fn .systemlist (cmd , nil , 0 ) or { " " }
18
- local cmd_output = cmd_output_table [# cmd_output_table ]
19
- local cmd_exit_code = vim .v .shell_error
16
+ local version_cmd = vim .split (M .node_command , " " )
17
+ table.insert (version_cmd , " --version" )
18
+
20
19
local node_version_major = 0
21
20
local node_version = " "
22
-
23
- if cmd_output then
24
- node_version = string.match (cmd_output , " ^v(%S+)" ) or node_version
25
- node_version_major = tonumber (string.match (node_version , " ^(%d+)%." )) or node_version_major
26
- else
27
- cmd_output = " [no output]"
21
+ local cmd_exit_code = - 1
22
+ local cmd_output = " [no output]"
23
+ local ok , process = pcall (vim .system , version_cmd )
24
+
25
+ if ok and process then
26
+ local result = process :wait ()
27
+ cmd_output = result .stdout or cmd_output
28
+ cmd_exit_code = result .code
29
+
30
+ if cmd_output and cmd_output ~= " [no output]" then
31
+ node_version = string.match (cmd_output , " ^v(%S+)" ) or node_version
32
+ node_version_major = tonumber (string.match (node_version , " ^(%d+)%." )) or node_version_major
33
+ end
28
34
end
29
35
30
36
if node_version_major == 0 then
@@ -63,17 +69,6 @@ function M.validate_node_version()
63
69
return true
64
70
end
65
71
66
- function M .node_exists ()
67
- local node_exists = vim .fn .executable (M .node_command ) == 1
68
-
69
- if not node_exists then
70
- logger .error (" node.js is not installed or not in PATH" )
71
- return false
72
- end
73
-
74
- return true
75
- end
76
-
77
72
--- @param server_path ? string
78
73
--- @return boolean
79
74
function M .init_agent_path (server_path )
101
96
102
97
--- @return table
103
98
function M .get_execute_command ()
104
- return {
105
- M .node_command ,
106
- M .server_path or M .get_server_path (),
107
- " --stdio" ,
108
- }
99
+ local cmd = vim .split (M .node_command , " " )
100
+ table.insert (cmd , M .server_path or M .get_server_path ())
101
+ table.insert (cmd , " --stdio" )
102
+ return cmd
109
103
end
110
104
111
105
--- @param node_command ? string
114
108
function M .setup (node_command , custom_server_path )
115
109
M .node_command = node_command or " node"
116
110
117
- if not M .node_exists () or not M . validate_node_version () or not M .init_agent_path (custom_server_path ) then
111
+ if not M .validate_node_version () or not M .init_agent_path (custom_server_path ) then
118
112
return false
119
113
end
120
114
0 commit comments