@@ -25,22 +25,17 @@ M.version = '0.1.0' -- x-release-please-version
25
25
--- @return string ? Return the result of the command
26
26
local function run_command (cmd )
27
27
local result = vim .fn .system (cmd )
28
- return vim .v .shell_error == 0 and result :gsub (" %s+$" , " " ) or nil
28
+ return vim .v .shell_error == 0 and result :gsub (' %s+$' , ' ' ) or nil
29
29
end
30
30
31
-
32
31
-- Helper function to show a notification
33
32
--- @param msg string Show a message
34
33
--- @param level number | " info" | " warn" | " error" | " trace" Notification level
35
34
local function n (msg , level )
36
- if msg == nil then
37
- msg = M .name .. " : No message provided"
38
- end
39
- if level == nil then
40
- level = " trace"
41
- end
35
+ if msg == nil then msg = M .name .. ' : No message provided' end
36
+ if level == nil then level = ' trace' end
42
37
43
- vim .notify (M .name .. " : " .. msg , level )
38
+ vim .notify (M .name .. ' : ' .. msg , level )
44
39
end
45
40
46
41
--- @class NvmDefaultOptions
52
47
--- @type NvmDefaultOptions
53
48
M .defaults = {
54
49
add_to_path = vim .g .nvm_default_add_to_path or true ,
55
- nvm_path = vim .fn .expand (os.getenv ( " NVM_DIR" ) or " ~/.nvm" ),
56
- notify_level = vim .g .nvm_default_notify_level or " info" ,
50
+ nvm_path = vim .fn .expand (os.getenv ' NVM_DIR' or ' ~/.nvm' ),
51
+ notify_level = vim .g .nvm_default_notify_level or ' info' ,
57
52
}
58
53
59
54
-- Fetch the NVM default version or fallback to node version
60
55
--- @param opts ? NvmDefaultOptions Plugin options
61
56
function M .setup (opts )
62
- local options = vim .tbl_deep_extend (" force" , M .defaults , opts or {})
57
+ local options = vim .tbl_deep_extend (' force' , M .defaults , opts or {})
63
58
64
59
local nvm_path = options .nvm_path
65
- local node_version =
66
- run_command ( string.format (" . %s/nvm.sh && nvm version default" , nvm_path )) or
67
- run_command (string.format (" . %s/nvm.sh && nvm version node" , nvm_path ))
60
+ local node_version = run_command (
61
+ string.format (' . %s/nvm.sh && nvm version default' , nvm_path )
62
+ ) or run_command (string.format (' . %s/nvm.sh && nvm version node' , nvm_path ))
68
63
69
- if node_version and node_version :match ( " ^v " ) then
64
+ if node_version and node_version :match ' ^v ' then
70
65
-- Set vim.g.node_host_prog and vim.g.copilot_node_command
71
- local current_nvm_version_path = string.format (" %s/versions/node/%s" , nvm_path , node_version )
72
- local current_nvm_node_bin_path = string.format (" %s/bin" , current_nvm_version_path )
73
- local current_nvm_node_bin = string.format (" %s/node" , current_nvm_node_bin_path )
74
- local neovim_node_host_bin_path = string.format (" %s/neovim-node-host" , current_nvm_node_bin_path )
66
+ local current_nvm_version_path =
67
+ string.format (' %s/versions/node/%s' , nvm_path , node_version )
68
+ local current_nvm_node_bin_path =
69
+ string.format (' %s/bin' , current_nvm_version_path )
70
+ local current_nvm_node_bin =
71
+ string.format (' %s/node' , current_nvm_node_bin_path )
72
+ local neovim_node_host_bin_path =
73
+ string.format (' %s/neovim-node-host' , current_nvm_node_bin_path )
75
74
76
75
-- Collect missing files and directories errors for error output
77
76
local missing = {}
78
77
79
78
-- If node_dir isn't there, stop and show error
80
79
if not vim .fn .isdirectory (current_nvm_version_path ) then
81
- table.insert (missing , " Node.js directory: " .. current_nvm_version_path )
80
+ table.insert (missing , ' Node.js directory: ' .. current_nvm_version_path )
82
81
end
83
82
84
83
-- If node_bin isn't there, stop and show error
85
84
if not vim .fn .filereadable (current_nvm_node_bin ) then
86
- table.insert (missing , " Node.js binary: " .. current_nvm_node_bin )
85
+ table.insert (missing , ' Node.js binary: ' .. current_nvm_node_bin )
87
86
end
88
87
89
88
if not vim .fn .filereadable (neovim_node_host_bin_path ) then
90
- table.insert (missing , " Neovim host binary: " .. neovim_node_host_bin_path )
89
+ table.insert (missing , ' Neovim host binary: ' .. neovim_node_host_bin_path )
91
90
end
92
91
93
92
if # missing > 0 then
94
- n (" Missing required files:\n - " .. table.concat (missing , " \n - " ), " error" )
93
+ n (' Missing required files:\n - ' .. table.concat (missing , ' \n - ' ), ' error' )
95
94
return
96
95
end
97
96
98
97
-- Add to PATH if requested. Can be turned off by setting if it messes with
99
98
-- other tools.
100
99
if options .add_to_path then
101
- vim .env .PATH = current_nvm_node_bin_path .. " : " .. vim .env .PATH
100
+ vim .env .PATH = current_nvm_node_bin_path .. ' : ' .. vim .env .PATH
102
101
end
103
102
104
103
vim .g .node_host_prog = neovim_node_host_bin_path
105
104
vim .g .copilot_node_command = current_nvm_node_bin
106
105
else
107
- n (" Unable to determine the Node.js version from nvm." , " error" )
106
+ n (' Unable to determine the Node.js version from nvm.' , ' error' )
108
107
end
109
108
end
110
109
0 commit comments