11-- these are helper functions for testing the nodejs LSP integration
22-- they stub out system interactions for verifying access to node and the LSP script
33
4- Stub = {}
4+ M = {}
55
6- Stub .default_server_path = " copilot/js/language-server.js"
7- Stub .custom_server_path = " custom/path/to/language-server.js"
6+ M .default_server_path = " copilot/js/language-server.js"
7+ M .custom_server_path = " custom/path/to/language-server.js"
88
99--- @param stdout string the stdout that will be returned by the stubbed vim.system
1010--- @param code integer the exit code that will be returned by the stubbed vim.system
1111--- @param fail boolean if true , vim.system will error when called
1212--- @param callback function the function to call while vim.system is stubbed
1313--- @return table | nil captured_args -- the arguments vim.system was called with
14- Stub .process = function (stdout , code , fail , callback )
14+ function M .process (stdout , code , fail , callback )
1515 local captured_args = nil
1616 local original_vim_system = vim .system
17+
18+ --- @diagnostic disable-next-line : duplicate-set-field
1719 vim .system = function (cmd )
1820 captured_args = cmd
1921 if fail then
@@ -23,57 +25,63 @@ Stub.process = function(stdout, code, fail, callback)
2325 wait = function ()
2426 return {
2527 stdout = stdout .. " \n " ,
26- code = code
28+ code = code ,
2729 }
28- end
30+ end ,
2931 }
3032 end
3133 -- wrap callback in pcall to ensure vim.system is restored if callback errors
3234 local ok , err = pcall (callback )
3335 vim .system = original_vim_system
34- if not ok then error (err ) end
36+ if not ok then
37+ error (err )
38+ end
3539 return captured_args
3640end
3741
38- Stub .valid_node_version = " 20.0.0"
39- Stub .invalid_node_version = " 10.0.0"
42+ M .valid_node_version = " 20.0.0"
43+ M .invalid_node_version = " 10.0.0"
4044
4145--- Convenience wrapper for Stub.process for a valid Node.js version (>= 20)
42- Stub .valid_node = function (callback )
43- return Stub .process (" v" .. Stub .valid_node_version , 0 , false , callback )
46+ function M .valid_node (callback )
47+ return M .process (" v" .. M .valid_node_version , 0 , false , callback )
4448end
4549
4650--- Convenience wrapper for Stub.process for an invalid Node.js version (< 20)
47- Stub .invalid_node = function (callback )
48- return Stub .process (" v" .. Stub .invalid_node_version , 0 , false , callback )
51+ function M .invalid_node (callback )
52+ return M .process (" v" .. M .invalid_node_version , 0 , false , callback )
4953end
5054
5155--- @param callback function the function to call while vim.api.nvim_get_runtime_file is stubbed
5256--- @return string | nil captured_path -- the path vim.api.nvim_get_runtime_file was called with
53- Stub .get_runtime_server_path = function (callback )
57+ function M .get_runtime_server_path (callback )
5458 local captured_path = nil
5559
5660 local original_get_file = vim .api .nvim_get_runtime_file
61+ --- @diagnostic disable-next-line : duplicate-set-field
5762 vim .api .nvim_get_runtime_file = function (path )
5863 captured_path = path
59- return { vim .fn .expand (Stub .default_server_path ) }
64+ return { vim .fn .expand (M .default_server_path ) }
6065 end
6166
6267 local original_filereadable = vim .fn .filereadable
68+ --- @diagnostic disable-next-line : duplicate-set-field
6369 vim .fn .filereadable = function ()
6470 return 1
6571 end
6672
6773 -- stub valid node version for callback so setup() succeeds
68- Stub .valid_node (function ()
74+ M .valid_node (function ()
6975 -- wrap callback in pcall to ensure vim.api.nvim_get_runtime_file is restored if callback errors
7076 local ok , err = pcall (callback )
7177 vim .api .nvim_get_runtime_file = original_get_file
7278 vim .fn .filereadable = original_filereadable
73- if not ok then error (err ) end
79+ if not ok then
80+ error (err )
81+ end
7482 end )
7583
7684 return captured_path
7785end
7886
79- return Stub
87+ return M
0 commit comments