Skip to content

Commit 7785d0e

Browse files
committed
refactor: remove worthless comments that describe obvious code
- Remove comments that just describe what code does rather than why - Keep valuable LuaDoc annotations and explanatory comments - Remove obvious descriptive comments like "Create directory", "Write to file", etc. - Preserve comments that explain business logic, error handling rationale, or complex algorithms - All tests continue passing (181 successes) Change-Id: Ia019bc6889b7ef969afd49e699d09b3ffaafd8e4 Signed-off-by: Thomas Kosiewski <[email protected]>
1 parent 03c159f commit 7785d0e

File tree

9 files changed

+8
-84
lines changed

9 files changed

+8
-84
lines changed

lua/claudecode/config.lua

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ M.defaults = {
1717
},
1818
}
1919

20-
--- Validates the provided configuration table.
21-
-- Ensures that all configuration options are of the correct type and within valid ranges.
22-
-- @param config table The configuration table to validate.
20+
--- @param config table The configuration table to validate.
2321
-- @return boolean true if the configuration is valid.
2422
-- @error string if any configuration option is invalid.
2523
function M.validate(config)
@@ -64,10 +62,7 @@ function M.validate(config)
6462
return true
6563
end
6664

67-
--- Applies user configuration on top of default settings and validates the result.
68-
-- Merges the user-provided configuration with the default configuration,
69-
-- then validates the merged configuration.
70-
-- @param user_config table|nil The user-provided configuration table.
65+
--- @param user_config table|nil The user-provided configuration table.
7166
-- @return table The final, validated configuration table.
7267
function M.apply(user_config)
7368
local config = vim.deepcopy(M.defaults)

lua/claudecode/diff.lua

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,6 @@ function M._create_diff_view_from_window(target_window, old_file_path, new_buffe
641641
vim.api.nvim_buf_set_option(empty_buffer, "modifiable", false)
642642
vim.api.nvim_buf_set_option(empty_buffer, "readonly", true)
643643

644-
-- Set the empty buffer in the target window
645644
vim.api.nvim_win_set_buf(target_window, empty_buffer)
646645
original_buffer = empty_buffer
647646
else
@@ -872,7 +871,6 @@ function M._setup_blocking_diff(params, resolution_callback)
872871
vim.api.nvim_buf_set_name(new_buffer, new_unique_name)
873872
vim.api.nvim_buf_set_lines(new_buffer, 0, -1, false, vim.split(params.new_file_contents, "\n"))
874873

875-
-- Set buffer options for the new content buffer
876874
vim.api.nvim_buf_set_option(new_buffer, "buftype", "acwrite") -- Allows saving but stays as scratch-like
877875
vim.api.nvim_buf_set_option(new_buffer, "modifiable", true)
878876

lua/claudecode/integrations.lua

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ function M._get_neotree_selection()
105105
end_pos = cursor_pos
106106
end
107107
end
108-
-- No valid visual marks found
109108

110109
if end_pos < start_pos then
111110
start_pos, end_pos = end_pos, start_pos
@@ -120,12 +119,9 @@ function M._get_neotree_selection()
120119
if node.type and node.type ~= "message" then
121120
table.insert(selected_nodes, node)
122121
end
123-
-- Message nodes not included in selection
124122
end
125-
-- No node found at this line
126123
end
127124

128-
-- Extract file paths from selected nodes with enhanced validation
129125

130126
for i, node in ipairs(selected_nodes) do
131127
-- Enhanced validation: check for file type and valid path
@@ -141,13 +137,9 @@ function M._get_neotree_selection()
141137
if #files > 0 then
142138
return files, nil
143139
end
144-
-- No files found in visual selection
145140
end
146-
-- Not in correct neo-tree window
147141
end
148-
-- Not in visual mode
149142

150-
-- Method 2: Try neo-tree's built-in selection methods
151143

152144
if state.tree then
153145
local selection = nil
@@ -170,13 +162,9 @@ function M._get_neotree_selection()
170162
if #files > 0 then
171163
return files, nil
172164
end
173-
-- No files found in selection
174165
end
175-
-- No selection available
176166
end
177-
-- No tree available
178167

179-
-- Fall back to current node under cursor
180168

181169
if state.tree then
182170
local node = state.tree:get_node()
@@ -187,11 +175,8 @@ function M._get_neotree_selection()
187175
elseif node.type == "directory" and node.path then
188176
return { node.path }, nil
189177
end
190-
-- Invalid node type or path
191178
end
192-
-- No cursor node found
193179
end
194-
-- No tree state available
195180

196181
return {}, "No file found under cursor"
197182
end

lua/claudecode/lockfile.lua

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ function M.create(port)
1818
return false, "Invalid port number"
1919
end
2020

21-
-- Ensure lock directory exists
2221
local ok, err = pcall(function()
2322
return vim.fn.mkdir(M.lock_dir, "p")
2423
end)
@@ -27,10 +26,8 @@ function M.create(port)
2726
return false, "Failed to create lock directory: " .. (err or "unknown error")
2827
end
2928

30-
-- Generate lock file path
3129
local lock_path = M.lock_dir .. "/" .. port .. ".lock"
3230

33-
-- Get workspace folders
3431
local workspace_folders = M.get_workspace_folders()
3532

3633
-- Prepare lock file content
@@ -41,7 +38,6 @@ function M.create(port)
4138
transport = "ws",
4239
}
4340

44-
-- Convert to JSON with error handling
4541
local json
4642
local ok_json, json_err = pcall(function()
4743
json = vim.json.encode(lock_content)
@@ -52,7 +48,6 @@ function M.create(port)
5248
return false, "Failed to encode lock file content: " .. (json_err or "unknown error")
5349
end
5450

55-
-- Write to file
5651
local file = io.open(lock_path, "w")
5752
if not file then
5853
return false, "Failed to create lock file: " .. lock_path
@@ -64,7 +59,6 @@ function M.create(port)
6459
end)
6560

6661
if not write_ok then
67-
-- Try to close file if still open
6862
pcall(function()
6963
file:close()
7064
end)
@@ -85,12 +79,10 @@ function M.remove(port)
8579

8680
local lock_path = M.lock_dir .. "/" .. port .. ".lock"
8781

88-
-- Check if file exists
8982
if vim.fn.filereadable(lock_path) == 0 then
9083
return false, "Lock file does not exist: " .. lock_path
9184
end
9285

93-
-- Remove the file with error handling
9486
local ok, err = pcall(function()
9587
return os.remove(lock_path)
9688
end)
@@ -111,7 +103,6 @@ function M.update(port)
111103
return false, "Invalid port number"
112104
end
113105

114-
-- First remove existing lock file if it exists
115106
local exists = vim.fn.filereadable(M.lock_dir .. "/" .. port .. ".lock") == 1
116107
if exists then
117108
local remove_ok, remove_err = M.remove(port)
@@ -120,7 +111,6 @@ function M.update(port)
120111
end
121112
end
122113

123-
-- Then create a new one
124114
return M.create(port)
125115
end
126116

lua/claudecode/logger.lua

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ local level_values = {
2020

2121
local current_log_level_value = M.levels.INFO
2222

23-
--- Initializes the logger with the provided configuration.
24-
-- @param plugin_config table The configuration table (e.g., from claudecode.init.state.config).
23+
--- @param plugin_config table The configuration table (e.g., from claudecode.init.state.config).
2524
function M.setup(plugin_config)
2625
local conf = plugin_config
2726

@@ -83,8 +82,7 @@ local function log(level, component, message_parts)
8382
end
8483
end
8584

86-
--- Logs a message at the ERROR level.
87-
-- @param component string|nil Optional component/module name.
85+
--- @param component string|nil Optional component/module name.
8886
-- @param ... any Varargs representing parts of the message.
8987
function M.error(component, ...)
9088
if type(component) ~= "string" then
@@ -94,8 +92,7 @@ function M.error(component, ...)
9492
end
9593
end
9694

97-
--- Logs a message at the WARN level.
98-
-- @param component string|nil Optional component/module name.
95+
--- @param component string|nil Optional component/module name.
9996
-- @param ... any Varargs representing parts of the message.
10097
function M.warn(component, ...)
10198
if type(component) ~= "string" then
@@ -105,8 +102,7 @@ function M.warn(component, ...)
105102
end
106103
end
107104

108-
--- Logs a message at the INFO level.
109-
-- @param component string|nil Optional component/module name.
105+
--- @param component string|nil Optional component/module name.
110106
-- @param ... any Varargs representing parts of the message.
111107
function M.info(component, ...)
112108
if type(component) ~= "string" then
@@ -116,8 +112,7 @@ function M.info(component, ...)
116112
end
117113
end
118114

119-
--- Logs a message at the DEBUG level.
120-
-- @param component string|nil Optional component/module name.
115+
--- @param component string|nil Optional component/module name.
121116
-- @param ... any Varargs representing parts of the message.
122117
function M.debug(component, ...)
123118
if type(component) ~= "string" then
@@ -127,8 +122,7 @@ function M.debug(component, ...)
127122
end
128123
end
129124

130-
--- Logs a message at the TRACE level.
131-
-- @param component string|nil Optional component/module name.
125+
--- @param component string|nil Optional component/module name.
132126
-- @param ... any Varargs representing parts of the message.
133127
function M.trace(component, ...)
134128
if type(component) ~= "string" then

lua/claudecode/server/frame.lua

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ M.OPCODE = {
2626
---@return WebSocketFrame|nil frame The parsed frame, or nil if incomplete/invalid
2727
---@return number bytes_consumed Number of bytes consumed from input
2828
function M.parse_frame(data)
29-
-- Input validation
3029
if type(data) ~= "string" then
3130
return nil, 0
3231
end
@@ -46,14 +45,12 @@ function M.parse_frame(data)
4645

4746
pos = pos + 2
4847

49-
-- Parse first byte
5048
local fin = math.floor(byte1 / 128) == 1
5149
local rsv1 = math.floor((byte1 % 128) / 64) == 1
5250
local rsv2 = math.floor((byte1 % 64) / 32) == 1
5351
local rsv3 = math.floor((byte1 % 32) / 16) == 1
5452
local opcode = byte1 % 16
5553

56-
-- Parse second byte
5754
local masked = math.floor(byte2 / 128) == 1
5855
local payload_len = byte2 % 128
5956

lua/claudecode/server/tcp.lua

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ function M.find_available_port(min_port, max_port)
2222
return nil -- Or handle error appropriately
2323
end
2424

25-
-- Create a list of ports in the range
2625
local ports = {}
2726
for i = min_port, max_port do
2827
table.insert(ports, i)
@@ -51,13 +50,11 @@ end
5150
---@return TCPServer|nil server The server object, or nil on error
5251
---@return string|nil error Error message if failed
5352
function M.create_server(config, callbacks)
54-
-- Find available port
5553
local port = M.find_available_port(config.port_range.min, config.port_range.max)
5654
if not port then
5755
return nil, "No available ports in range " .. config.port_range.min .. "-" .. config.port_range.max
5856
end
5957

60-
-- Create TCP server
6158
local tcp_server = vim.loop.new_tcp()
6259
if not tcp_server then
6360
return nil, "Failed to create TCP server"
@@ -74,7 +71,6 @@ function M.create_server(config, callbacks)
7471
on_error = callbacks.on_error or function() end,
7572
}
7673

77-
-- Bind to port
7874
local bind_success, bind_err = tcp_server:bind("127.0.0.1", port)
7975
if not bind_success then
8076
tcp_server:close()

lua/claudecode/terminal.lua

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ local managed_fallback_terminal_winid = nil
3333
local managed_fallback_terminal_jobid = nil
3434
local native_term_tip_shown = false
3535

36-
-- Determines the command to run in the terminal.
3736
-- Uses the `terminal_cmd` from the module's configuration, or defaults to "claude".
38-
-- @local
3937
-- @return string The command to execute.
4038
local function get_claude_command()
4139
local cmd_from_config = term_module_config.terminal_cmd
@@ -91,7 +89,6 @@ function M.setup(user_term_config, p_terminal_cmd)
9189
end
9290

9391
--- Determines the effective terminal provider based on configuration and availability.
94-
-- @local
9592
-- @return string "snacks" or "native"
9693
local function get_effective_terminal_provider()
9794
if term_module_config.provider == "snacks" then
@@ -117,8 +114,6 @@ local function get_effective_terminal_provider()
117114
end
118115
end
119116

120-
--- Cleans up state variables for the fallback terminal.
121-
-- @local
122117
local function cleanup_fallback_terminal_state()
123118
managed_fallback_terminal_bufnr = nil
124119
managed_fallback_terminal_winid = nil
@@ -127,7 +122,6 @@ end
127122

128123
--- Checks if the managed fallback terminal is currently valid (window and buffer exist).
129124
-- Cleans up state if invalid.
130-
-- @local
131125
-- @return boolean True if valid, false otherwise.
132126
local function is_fallback_terminal_valid()
133127
-- First check if we have a valid buffer
@@ -158,7 +152,6 @@ local function is_fallback_terminal_valid()
158152
end
159153

160154
--- Opens a new terminal using native Neovim functions.
161-
-- @local
162155
-- @param cmd_string string The command string to run.
163156
-- @param env_table table Environment variables for the command.
164157
-- @param effective_term_config table Configuration for split_side and split_width_percentage.
@@ -252,7 +245,6 @@ local function open_fallback_terminal(cmd_string, env_table, effective_term_conf
252245
end
253246

254247
--- Closes the managed fallback terminal if it's open and valid.
255-
-- @local
256248
local function close_fallback_terminal()
257249
if is_fallback_terminal_valid() then
258250
-- Closing the window should trigger on_exit of the job if the process is still running,
@@ -265,7 +257,6 @@ local function close_fallback_terminal()
265257
end
266258

267259
--- Focuses the managed fallback terminal if it's open and valid.
268-
-- @local
269260
local function focus_fallback_terminal()
270261
if is_fallback_terminal_valid() then
271262
vim.api.nvim_set_current_win(managed_fallback_terminal_winid)
@@ -275,7 +266,6 @@ end
275266

276267
--- Builds the effective terminal configuration by merging module defaults with runtime overrides.
277268
-- Used by the native fallback.
278-
-- @local
279269
-- @param opts_override table (optional) Overrides for terminal appearance (split_side, split_width_percentage).
280270
-- @return table The effective terminal configuration.
281271
local function build_effective_term_config(opts_override)
@@ -304,7 +294,6 @@ end
304294
--- Builds the options table for Snacks.terminal.
305295
-- This function merges the module's current terminal configuration
306296
-- with any runtime overrides provided specifically for an open/toggle action.
307-
-- @local
308297
-- @param effective_term_config_for_snacks table Pre-calculated effective config for split_side, width.
309298
-- @param env_table table Environment variables for the command.
310299
-- @return table The options table for Snacks.
@@ -329,7 +318,6 @@ local function build_snacks_opts(effective_term_config_for_snacks, env_table)
329318
end
330319

331320
--- Gets the base claude command string and necessary environment variables.
332-
-- @local
333321
-- @return string|nil cmd_string The command string, or nil on failure.
334322
-- @return table|nil env_table The environment variables table, or nil on failure.
335323
local function get_claude_command_and_env()
@@ -355,7 +343,6 @@ local function get_claude_command_and_env()
355343
end
356344

357345
--- Find any existing Claude Code terminal buffer by checking terminal job command
358-
-- @local
359346
-- @return number|nil Buffer number if found, nil otherwise
360347
local function find_existing_claude_terminal()
361348
local buffers = vim.api.nvim_list_bufs()

lua/claudecode/tools/init.lua

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -172,23 +172,5 @@ function M.handle_invoke(client, params) -- client needed for blocking tools
172172
return { result = handler_return_val1 }
173173
end
174174

175-
-- Removed M.open_file function, its logic is now in lua/claudecode/tools/impl/open_file.lua
176-
177-
-- Removed M.get_diagnostics function, its logic is now in lua/claudecode/tools/impl/get_diagnostics.lua
178-
179-
-- Removed M.get_open_editors function, its logic is now in lua/claudecode/tools/impl/get_open_editors.lua
180-
181-
-- Removed M.get_workspace_folders function, its logic is now in lua/claudecode/tools/impl/get_workspace_folders.lua
182-
183-
-- Removed M.get_current_selection function, its logic is now in lua/claudecode/tools/impl/get_current_selection.lua
184-
-- Removed M.get_latest_selection function as it was redundant with get_current_selection's new implementation
185-
186-
-- Removed M.check_document_dirty function, its logic is now in lua/claudecode/tools/impl/check_document_dirty.lua
187-
188-
-- Removed M.save_document function, its logic is now in lua/claudecode/tools/impl/save_document.lua
189-
190-
-- Removed M.open_diff function, its logic is now in lua/claudecode/tools/impl/open_diff.lua
191-
192-
-- Removed M.close_buffer_by_name function, its logic is now in lua/claudecode/tools/impl/close_buffer_by_name.lua
193175

194176
return M

0 commit comments

Comments
 (0)