|
1 | 1 | local M = {}
|
2 | 2 |
|
3 |
| -M.config = require('http_client.config') |
4 |
| - |
| 3 | +M.config = require("http_client.config") |
5 | 4 |
|
6 | 5 | local function setup_docs()
|
7 |
| - if vim.fn.has("nvim-0.7") == 1 then |
8 |
| - vim.api.nvim_create_autocmd("BufWinEnter", { |
9 |
| - group = vim.api.nvim_create_augroup("http_client_docs", {}), |
10 |
| - pattern = "*/http_client/doc/*.txt", |
11 |
| - callback = function() |
12 |
| - vim.cmd("silent! helptags " .. vim.fn.expand("%:p:h")) |
13 |
| - end, |
14 |
| - }) |
15 |
| - end |
| 6 | + if vim.fn.has("nvim-0.7") == 1 then |
| 7 | + vim.api.nvim_create_autocmd("BufWinEnter", { |
| 8 | + group = vim.api.nvim_create_augroup("http_client_docs", {}), |
| 9 | + pattern = "*/http_client/doc/*.txt", |
| 10 | + callback = function() |
| 11 | + vim.cmd("silent! helptags " .. vim.fn.expand("%:p:h")) |
| 12 | + end, |
| 13 | + }) |
| 14 | + end |
16 | 15 | end
|
17 | 16 |
|
18 | 17 | local function set_keybindings()
|
19 |
| - local opts = { noremap = true, silent = true } |
20 |
| - |
21 |
| - vim.api.nvim_create_autocmd("FileType", { |
22 |
| - pattern = "http", |
23 |
| - callback = function() |
24 |
| - vim.keymap.set('n', M.config.get('keybindings').select_env_file, ':HttpEnvFile<CR>', opts) |
25 |
| - vim.keymap.set('n', M.config.get('keybindings').set_env, ':HttpEnv<CR>', { noremap = true, buffer = true }) |
26 |
| - vim.keymap.set('n', M.config.get('keybindings').run_request, ':HttpRun<CR>', opts) |
27 |
| - vim.keymap.set('n', M.config.get('keybindings').stop_request, ':HttpStop<CR>', opts) |
28 |
| - vim.keymap.set('n', M.config.get('keybindings').dry_run, ':HttpDryRun<CR>', opts) |
29 |
| - vim.keymap.set('n', M.config.get('keybindings').toggle_verbose, ':HttpVerbose<CR>', opts) |
30 |
| - vim.keymap.set('n', M.config.get('keybindings').copy_curl, ':HttpCopyCurl<CR>', opts) |
31 |
| - end |
32 |
| - }) |
| 18 | + if M.config.get("create_keybindings") then |
| 19 | + local opts = { noremap = true, silent = true } |
| 20 | + vim.api.nvim_create_autocmd("FileType", { |
| 21 | + pattern = "http", |
| 22 | + callback = function() |
| 23 | + vim.keymap.set("n", M.config.get("keybindings").select_env_file, ":HttpEnvFile<CR>", opts) |
| 24 | + vim.keymap.set( |
| 25 | + "n", |
| 26 | + M.config.get("keybindings").set_env, |
| 27 | + ":HttpEnv<CR>", |
| 28 | + { noremap = true, buffer = true } |
| 29 | + ) |
| 30 | + vim.keymap.set("n", M.config.get("keybindings").run_request, ":HttpRun<CR>", opts) |
| 31 | + vim.keymap.set("n", M.config.get("keybindings").stop_request, ":HttpStop<CR>", opts) |
| 32 | + vim.keymap.set("n", M.config.get("keybindings").dry_run, ":HttpDryRun<CR>", opts) |
| 33 | + vim.keymap.set("n", M.config.get("keybindings").toggle_verbose, ":HttpVerbose<CR>", opts) |
| 34 | + vim.keymap.set("n", M.config.get("keybindings").copy_curl, ":HttpCopyCurl<CR>", opts) |
| 35 | + end, |
| 36 | + }) |
| 37 | + end |
33 | 38 | end
|
34 | 39 |
|
35 | 40 | M.setup = function(opts)
|
36 |
| - M.config.setup(opts) |
37 |
| - |
38 |
| - -- Load all necessary modules |
39 |
| - M.environment = require('http_client.core.environment') |
40 |
| - M.file_utils = require('http_client.utils.file_utils') |
41 |
| - M.http_client = require('http_client.core.http_client') |
42 |
| - M.parser = require('http_client.core.parser') |
43 |
| - M.ui = require('http_client.ui.display') |
44 |
| - M.dry_run = require('http_client.ui.dry_run') |
45 |
| - M.v = require('http_client.utils.verbose') |
46 |
| - M.commands = require('http_client.commands') |
47 |
| - |
48 |
| - |
49 |
| - -- Set up commands |
50 |
| - vim.api.nvim_create_user_command('HttpEnvFile', function() |
51 |
| - M.commands.select_env.select_env_file(M.config.get()) |
52 |
| - end, { |
53 |
| - desc = 'Select an environment file for HTTP requests.' |
54 |
| - }) |
55 |
| - |
56 |
| - vim.api.nvim_create_user_command('HttpEnv', function() |
57 |
| - M.commands.select_env.select_env() |
58 |
| - end, { |
59 |
| - desc = 'Select an environment for HTTP request (requires one argument).', |
60 |
| - }) |
61 |
| - |
62 |
| - vim.api.nvim_create_user_command('HttpRun', function() |
63 |
| - M.commands.request.run_request() |
64 |
| - end, { |
65 |
| - desc = 'Run the HTTP request under cursor. Use ! to enable verbose mode.', |
66 |
| - }) |
67 |
| - |
68 |
| - vim.api.nvim_create_user_command('HttpRunAll', function() |
69 |
| - M.commands.request.run_all() |
70 |
| - end, { |
71 |
| - desc = 'Run all HTTP requests in the current file.' |
72 |
| - }) |
73 |
| - |
74 |
| - vim.api.nvim_create_user_command('HttpStop', function() |
75 |
| - M.commands.request.stop_request() |
76 |
| - end, { |
77 |
| - desc = 'Stop the currently running HTTP request.' |
78 |
| - }) |
79 |
| - |
80 |
| - |
81 |
| - |
82 |
| - vim.api.nvim_create_user_command('HttpVerbose', function() |
83 |
| - local current_state = M.v.get_verbose_mode() |
84 |
| - M.v.set_verbose_mode(not current_state) |
85 |
| - print(string.format("HTTP Client verbose mode %s", not current_state and "enabled" or "disabled")) |
86 |
| - end, { |
87 |
| - desc = 'Toggle verbose mode for HTTP request.' |
88 |
| - }) |
89 |
| - |
90 |
| - vim.api.nvim_create_user_command('HttpDryRun', function() |
91 |
| - M.dry_run.display_dry_run(M) |
92 |
| - end, { |
93 |
| - desc = 'Perform a dry run of the HTTP request without sending it.' |
94 |
| - }) |
95 |
| - |
96 |
| - vim.api.nvim_create_user_command('HttpCopyCurl', function() |
97 |
| - M.commands.utils.copy_curl() |
98 |
| - end, { |
99 |
| - desc = 'Copy curl command for the HTTP request under cursor.' |
100 |
| - }) |
101 |
| - |
102 |
| - |
103 |
| - |
104 |
| - setup_docs() |
105 |
| - set_keybindings() |
106 |
| - |
107 |
| - |
108 |
| - M.health = require('http_client.health') |
109 |
| - -- Register health check |
110 |
| - local health = vim.health or M.health |
111 |
| - if health.register then |
112 |
| - -- Register the health check with the new API |
113 |
| - health.register("http_client", M.health.check) |
114 |
| - else |
115 |
| - -- Fallback for older Neovim versions |
116 |
| - vim.api.nvim_create_autocmd("VimEnter", { |
117 |
| - callback = function() |
118 |
| - M.health.check() |
119 |
| - end, |
120 |
| - }) |
121 |
| - end |
| 41 | + M.config.setup(opts) |
| 42 | + |
| 43 | + -- Load all necessary modules |
| 44 | + M.environment = require("http_client.core.environment") |
| 45 | + M.file_utils = require("http_client.utils.file_utils") |
| 46 | + M.http_client = require("http_client.core.http_client") |
| 47 | + M.parser = require("http_client.core.parser") |
| 48 | + M.ui = require("http_client.ui.display") |
| 49 | + M.dry_run = require("http_client.ui.dry_run") |
| 50 | + M.v = require("http_client.utils.verbose") |
| 51 | + M.commands = require("http_client.commands") |
| 52 | + |
| 53 | + -- Set up commands |
| 54 | + vim.api.nvim_create_user_command("HttpEnvFile", function() |
| 55 | + M.commands.select_env.select_env_file(M.config.get()) |
| 56 | + end, { |
| 57 | + desc = "Select an environment file for HTTP requests.", |
| 58 | + }) |
| 59 | + |
| 60 | + vim.api.nvim_create_user_command("HttpEnv", function() |
| 61 | + M.commands.select_env.select_env() |
| 62 | + end, { |
| 63 | + desc = "Select an environment for HTTP request (requires one argument).", |
| 64 | + }) |
| 65 | + |
| 66 | + vim.api.nvim_create_user_command("HttpRun", function() |
| 67 | + M.commands.request.run_request() |
| 68 | + end, { |
| 69 | + desc = "Run the HTTP request under cursor. Use ! to enable verbose mode.", |
| 70 | + }) |
| 71 | + |
| 72 | + vim.api.nvim_create_user_command("HttpRunAll", function() |
| 73 | + M.commands.request.run_all() |
| 74 | + end, { |
| 75 | + desc = "Run all HTTP requests in the current file.", |
| 76 | + }) |
| 77 | + |
| 78 | + vim.api.nvim_create_user_command("HttpStop", function() |
| 79 | + M.commands.request.stop_request() |
| 80 | + end, { |
| 81 | + desc = "Stop the currently running HTTP request.", |
| 82 | + }) |
| 83 | + |
| 84 | + vim.api.nvim_create_user_command("HttpVerbose", function() |
| 85 | + local current_state = M.v.get_verbose_mode() |
| 86 | + M.v.set_verbose_mode(not current_state) |
| 87 | + print(string.format("HTTP Client verbose mode %s", not current_state and "enabled" or "disabled")) |
| 88 | + end, { |
| 89 | + desc = "Toggle verbose mode for HTTP request.", |
| 90 | + }) |
| 91 | + |
| 92 | + vim.api.nvim_create_user_command("HttpDryRun", function() |
| 93 | + M.dry_run.display_dry_run(M) |
| 94 | + end, { |
| 95 | + desc = "Perform a dry run of the HTTP request without sending it.", |
| 96 | + }) |
| 97 | + |
| 98 | + vim.api.nvim_create_user_command("HttpCopyCurl", function() |
| 99 | + M.commands.utils.copy_curl() |
| 100 | + end, { |
| 101 | + desc = "Copy curl command for the HTTP request under cursor.", |
| 102 | + }) |
| 103 | + |
| 104 | + setup_docs() |
| 105 | + set_keybindings() |
| 106 | + |
| 107 | + M.health = require("http_client.health") |
| 108 | + -- Register health check |
| 109 | + local health = vim.health or M.health |
| 110 | + if health.register then |
| 111 | + -- Register the health check with the new API |
| 112 | + health.register("http_client", M.health.check) |
| 113 | + else |
| 114 | + -- Fallback for older Neovim versions |
| 115 | + vim.api.nvim_create_autocmd("VimEnter", { |
| 116 | + callback = function() |
| 117 | + M.health.check() |
| 118 | + end, |
| 119 | + }) |
| 120 | + end |
122 | 121 | end
|
123 | 122 |
|
124 | 123 | return M
|
125 |
| - |
0 commit comments