Skip to content

Commit 50ded4d

Browse files
committed
refactor: remove get and set from config for native access
If there are any manipulations that need to happen they can be in the setup() method
1 parent 827fd1c commit 50ded4d

File tree

5 files changed

+16
-55
lines changed

5 files changed

+16
-55
lines changed

lua/copilot/client.lua

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ local function get_handlers()
161161
}
162162

163163
-- optional handlers
164-
local logger_conf = config.get("logger") --[[@as copilot_config_logging]]
164+
local logger_conf = config.config.logger
165165
if logger_conf.trace_lsp ~= "off" then
166166
handlers = vim.tbl_extend("force", handlers, {
167167
["$/logTrace"] = logger.handle_lsp_trace,
@@ -233,7 +233,7 @@ local function prepare_client_config(overrides)
233233
},
234234
}
235235

236-
local config_workspace_folders = config.get("workspace_folders") --[[@as table<string>]]
236+
local config_workspace_folders = config.config.workspace_folders
237237

238238
for _, config_workspace_folder in ipairs(config_workspace_folders) do
239239
if config_workspace_folder ~= "" then
@@ -249,7 +249,7 @@ local function prepare_client_config(overrides)
249249
end
250250

251251
local editor_info = util.get_editor_info()
252-
local provider_url = config.get("auth_provider_url") --[[@as string|nil]]
252+
local provider_url = config.config.auth_provider_url
253253
local proxy_uri = vim.g.copilot_proxy
254254

255255
local settings = { ---@type copilot_settings
@@ -296,7 +296,7 @@ local function prepare_client_config(overrides)
296296
logger.trace("workspace configuration", configurations)
297297

298298
-- to activate tracing if we want it
299-
local logger_conf = config.get("logger") --[[@as copilot_config_logging]]
299+
local logger_conf = config.config.logger
300300
local trace_params = { value = logger_conf.trace_lsp } --[[@as copilot_nofify_set_trace_params]]
301301
api.notify_set_trace(client, trace_params)
302302

@@ -325,14 +325,13 @@ local function prepare_client_config(overrides)
325325
},
326326
settings = settings,
327327
workspace_folders = workspace_folders,
328-
trace = config.get("trace") or "off",
329328
}, overrides)
330329
end
331330

332331
function M.setup()
333-
M.should_attach = config.get("should_attach") --[[@as copilot_should_attach|nil]]
334-
local server_config = config.get("server") --[[@as copilot_config_server]]
335-
local node_command = config.get("copilot_node_command") --[[@as string|nil]]
332+
M.should_attach = config.config.should_attach
333+
local server_config = config.config.server
334+
local node_command = config.config.copilot_node_command
336335
M.server = vim.tbl_deep_extend("force", M.server, server_config)
337336

338337
if M.server.custom_server_filepath then
@@ -345,7 +344,7 @@ function M.setup()
345344
lsp_binary.setup(M.server.custom_server_filepath)
346345
end
347346

348-
M.config = prepare_client_config(config.get("server_opts_overrides"))
347+
M.config = prepare_client_config(config.config.server_opts_overrides)
349348

350349
if not M.config then
351350
is_disabled = true
@@ -399,7 +398,7 @@ function M.add_workspace_folder(folder_path)
399398
name = folder_path,
400399
}
401400

402-
local workspace_folders = config.get("workspace_folders") --[[@as table<string>]]
401+
local workspace_folders = config.config.workspace_folders
403402
if not workspace_folders then
404403
workspace_folders = {}
405404
end

lua/copilot/config.lua

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -94,47 +94,10 @@ function mod.setup(opts)
9494
return mod.config
9595
end
9696

97-
local config = vim.tbl_deep_extend("force", default_config, opts or {})
98-
99-
--- for backward compatibility
100-
if config.ft_disable then
101-
for _, disabled_ft in ipairs(config.ft_disable) do
102-
config.filetypes[disabled_ft] = false
103-
end
104-
105-
config.ft_disable = nil
106-
end
107-
108-
mod.config = config
109-
97+
mod.config = vim.tbl_deep_extend("force", default_config, opts or {})
11098
return mod.config
11199
end
112100

113-
---@param key? string
114-
function mod.get(key)
115-
if not mod.config then
116-
logger.error("not initialized")
117-
return
118-
end
119-
120-
if key then
121-
return mod.config[key]
122-
end
123-
124-
return mod.config
125-
end
126-
127-
---@param key string
128-
---@param value any
129-
function mod.set(key, value)
130-
if not mod.config then
131-
logger.error("not initialized")
132-
return
133-
end
134-
135-
mod.config[key] = value
136-
end
137-
138101
function mod.get_root_dir()
139102
if not mod.config then
140103
error("[Copilot] not initialized")

lua/copilot/panel.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ function mod.open(layout)
567567
end
568568

569569
function mod.setup()
570-
local opts = config.get("panel") --[[@as copilot_config_panel]]
570+
local opts = config.config.panel
571571
if not opts.enabled then
572572
return
573573
end
@@ -592,7 +592,7 @@ function mod.setup()
592592
end
593593

594594
function mod.teardown()
595-
local opts = config.get("panel") --[[@as copilot_config_panel]]
595+
local opts = config.config.panel
596596
if not opts.enabled then
597597
return
598598
end

lua/copilot/suggestion.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ local function create_autocmds()
700700
end
701701

702702
function mod.setup()
703-
local opts = config.get("suggestion") --[[@as copilot_config_suggestion]]
703+
local opts = config.config.suggestion
704704
if not opts.enabled then
705705
return
706706
end
@@ -721,7 +721,7 @@ function mod.setup()
721721
end
722722

723723
function mod.teardown()
724-
local opts = config.get("suggestion") --[[@as copilot_config_suggestion]]
724+
local opts = config.config.suggestion
725725
if not opts.enabled then
726726
return
727727
end

lua/copilot/util.lua

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ end
9090
---@return boolean should_attach
9191
---@return string? no_attach_reason
9292
function M.should_attach()
93-
local ft = config.get("filetypes") --[[@as table<string, boolean>]]
93+
local ft = config.config.filetypes
9494
local ft_disabled, ft_disabled_reason = is_ft_disabled(vim.bo.filetype, ft)
9595

9696
if ft_disabled then
@@ -169,8 +169,7 @@ end
169169

170170
---@return copilot_workspace_configurations
171171
function M.get_workspace_configurations()
172-
local conf = config.get() --[[@as copilot_config]]
173-
172+
local conf = config.config
174173
local filetypes = vim.deepcopy(conf.filetypes) --[[@as table<string, boolean>]]
175174

176175
if filetypes["*"] == nil then

0 commit comments

Comments
 (0)