Skip to content

Commit eaaf586

Browse files
committed
refactor: centralize type definitions in dedicated types.lua module
Change-Id: Idfbb1d15fac498475ddc517f85f86838cb19322c Signed-off-by: Thomas Kosiewski <[email protected]>
1 parent 24c1f43 commit eaaf586

File tree

4 files changed

+94
-63
lines changed

4 files changed

+94
-63
lines changed

lua/claudecode/config.lua

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,7 @@
66

77
local M = {}
88

9-
-- Types (authoritative for configuration shape):
10-
---@class ClaudeCode.DiffOptions
11-
---@field auto_close_on_accept boolean
12-
---@field show_diff_stats boolean
13-
---@field vertical_split boolean
14-
---@field open_in_current_tab boolean
15-
---@field keep_terminal_focus boolean
16-
17-
---@class ClaudeCode.ModelOption
18-
---@field name string
19-
---@field value string
20-
21-
---@alias ClaudeCode.LogLevel "trace"|"debug"|"info"|"warn"|"error"
22-
23-
---@class ClaudeCode.Config
24-
---@field port_range {min: integer, max: integer}
25-
---@field auto_start boolean
26-
---@field terminal_cmd string|nil
27-
---@field env table<string, string>
28-
---@field log_level ClaudeCode.LogLevel
29-
---@field track_selection boolean
30-
---@field visual_demotion_delay_ms number
31-
---@field connection_wait_delay number
32-
---@field connection_timeout number
33-
---@field queue_timeout number
34-
---@field diff_opts ClaudeCode.DiffOptions
35-
---@field models ClaudeCode.ModelOption[]
36-
---@field disable_broadcast_debouncing? boolean
37-
---@field enable_broadcast_debouncing_in_tests? boolean
38-
---@field terminal TerminalConfig|nil
9+
---@type ClaudeCodeConfig
3910
M.defaults = {
4011
port_range = { min = 10000, max = 65535 },
4112
auto_start = true,
@@ -138,7 +109,7 @@ end
138109

139110
---Applies user configuration on top of default settings and validates the result.
140111
---@param user_config table|nil The user-provided configuration table.
141-
---@return ClaudeCode.Config config The final, validated configuration table.
112+
---@return ClaudeCodeConfig config The final, validated configuration table.
142113
function M.apply(user_config)
143114
local config = vim.deepcopy(M.defaults)
144115

lua/claudecode/init.lua

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,35 +9,8 @@ local M = {}
99

1010
local logger = require("claudecode.logger")
1111

12-
-- Types
13-
14-
---@class ClaudeCode.Version
15-
---@field major integer
16-
---@field minor integer
17-
---@field patch integer
18-
---@field prerelease? string
19-
---@field string fun(self: ClaudeCode.Version):string
20-
21-
-- Narrow facade of the server module used by this file
22-
---@class ClaudeCode.ServerFacade
23-
---@field start fun(config: ClaudeCode.Config, auth_token: string|nil): boolean, number|string
24-
---@field stop fun(): boolean, string|nil
25-
---@field broadcast fun(method: string, params: table|nil): boolean
26-
---@field get_status fun(): { running: boolean, port: integer|nil, client_count: integer, clients?: table }
27-
28-
-- State type for this module
29-
---@class ClaudeCode.State
30-
---@field config ClaudeCode.Config
31-
---@field server ClaudeCode.ServerFacade|nil
32-
---@field port integer|nil
33-
---@field auth_token string|nil
34-
---@field initialized boolean
35-
---@field mention_queue table[]
36-
---@field mention_timer table|nil
37-
---@field connection_timer table|nil
38-
3912
--- Current plugin version
40-
---@type ClaudeCode.Version
13+
---@type ClaudeCodeVersion
4114
M.version = {
4215
major = 0,
4316
minor = 2,
@@ -53,7 +26,7 @@ M.version = {
5326
}
5427

5528
-- Module state
56-
---@type ClaudeCode.State
29+
---@type ClaudeCodeState
5730
M.state = {
5831
config = require("claudecode.config").defaults,
5932
server = nil,
@@ -314,7 +287,7 @@ function M.send_at_mention(file_path, start_line, end_line, context)
314287
end
315288

316289
---Set up the plugin with user configuration
317-
---@param opts ClaudeCode.Config|nil Optional configuration table to override defaults.
290+
---@param opts ClaudeCodeConfig|nil Optional configuration table to override defaults.
318291
---@return table module The plugin module
319292
function M.setup(opts)
320293
opts = opts or {}

lua/claudecode/logger.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ local level_values = {
2222
local current_log_level_value = M.levels.INFO
2323

2424
---Setup the logger module
25-
---@param plugin_config ClaudeCode.Config The configuration table (e.g., from claudecode.init.state.config).
25+
---@param plugin_config ClaudeCodeConfig The configuration table (e.g., from claudecode.init.state.config).
2626
function M.setup(plugin_config)
2727
local conf = plugin_config
2828

@@ -119,7 +119,7 @@ function M.info(component, ...)
119119
end
120120

121121
---Check if a specific log level is enabled
122-
---@param level_name ClaudeCode.LogLevel The level name ("error", "warn", "info", "debug", "trace")
122+
---@param level_name ClaudeCodeLogLevel The level name ("error", "warn", "info", "debug", "trace")
123123
---@return boolean enabled Whether the level is enabled
124124
function M.is_level_enabled(level_name)
125125
local level_value = level_values[level_name]

lua/claudecode/types.lua

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
---@brief [[
2+
--- Centralized type definitions for ClaudeCode.nvim public API.
3+
--- This module contains all user-facing types and configuration structures.
4+
---@brief ]]
5+
---@module 'claudecode.types'
6+
7+
-- Version information type
8+
---@class ClaudeCodeVersion
9+
---@field major integer
10+
---@field minor integer
11+
---@field patch integer
12+
---@field prerelease? string
13+
---@field string fun(self: ClaudeCodeVersion): string
14+
15+
-- Diff behavior configuration
16+
---@class ClaudeCodeDiffOptions
17+
---@field auto_close_on_accept boolean
18+
---@field show_diff_stats boolean
19+
---@field vertical_split boolean
20+
---@field open_in_current_tab boolean
21+
---@field keep_terminal_focus boolean
22+
23+
-- Model selection option
24+
---@class ClaudeCodeModelOption
25+
---@field name string
26+
---@field value string
27+
28+
-- Log level type alias
29+
---@alias ClaudeCodeLogLevel "trace"|"debug"|"info"|"warn"|"error"
30+
31+
-- @ mention queued for Claude Code
32+
---@class ClaudeCodeMention
33+
---@field file_path string The absolute file path to mention
34+
---@field start_line number? Optional start line (0-indexed for Claude compatibility)
35+
---@field end_line number? Optional end line (0-indexed for Claude compatibility)
36+
---@field timestamp number Creation timestamp from vim.loop.now() for expiry tracking
37+
38+
-- Port range configuration
39+
---@class ClaudeCodePortRange
40+
---@field min integer
41+
---@field max integer
42+
43+
-- Server status information
44+
---@class ClaudeCodeServerStatus
45+
---@field running boolean
46+
---@field port integer?
47+
---@field client_count integer
48+
---@field clients? table<string, any>
49+
50+
-- Main configuration structure
51+
---@class ClaudeCodeConfig
52+
---@field port_range ClaudeCodePortRange
53+
---@field auto_start boolean
54+
---@field terminal_cmd string|nil
55+
---@field env table<string, string>
56+
---@field log_level ClaudeCodeLogLevel
57+
---@field track_selection boolean
58+
---@field visual_demotion_delay_ms number
59+
---@field connection_wait_delay number
60+
---@field connection_timeout number
61+
---@field queue_timeout number
62+
---@field diff_opts ClaudeCodeDiffOptions
63+
---@field models ClaudeCodeModelOption[]
64+
---@field disable_broadcast_debouncing? boolean
65+
---@field enable_broadcast_debouncing_in_tests? boolean
66+
---@field terminal TerminalConfig|nil
67+
68+
-- Server interface for main module
69+
---@class ClaudeCodeServerFacade
70+
---@field start fun(config: ClaudeCodeConfig, auth_token: string|nil): (success: boolean, port_or_error: number|string)
71+
---@field stop fun(): (success: boolean, error_message: string?)
72+
---@field broadcast fun(method: string, params: table?): boolean
73+
---@field get_status fun(): ClaudeCodeServerStatus
74+
75+
-- Main module state
76+
---@class ClaudeCodeState
77+
---@field config ClaudeCodeConfig
78+
---@field server ClaudeCodeServerFacade|nil
79+
---@field port integer|nil
80+
---@field auth_token string|nil
81+
---@field initialized boolean
82+
---@field mention_queue ClaudeCodeMention[]
83+
---@field mention_timer uv.uv_timer_t? -- (compatible with vim.loop timer)
84+
---@field connection_timer uv.uv_timer_t? -- (compatible with vim.loop timer)
85+
86+
-- This module only defines types, no runtime functionality
87+
return {}

0 commit comments

Comments
 (0)