Skip to content

Commit

Permalink
Object 146
Browse files Browse the repository at this point in the history
  • Loading branch information
luozhiya committed Jan 15, 2025
1 parent 34c6d01 commit 39d180c
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 6 deletions.
15 changes: 12 additions & 3 deletions lua/fittencode/chat/controller.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@ function Controller:new(opts)
basic_chat_template_id = opts.basic_chat_template_id,
conversation_types_provider = opts.conversation_types_provider,
observers = {},
augroups = {},
}, Controller)
return obj
end

function Controller:init_singleton()
self.selection_changed_autocmd = vim.api.nvim_create_autocmd('User', {
pattern = 'fittencode.SelectionChanged',
function Controller:init_integration()
self.augroups.event = vim.api.nvim_create_augroup('Fittencode.Chat.Controller.Event', { clear = true })
vim.api.nvim_create_autocmd('User', {
pattern = 'Fittencode.SelectionChanged',
group = self.augroups.event,
once = false,
callback = function(args)
self:update_view()
Expand All @@ -33,6 +36,12 @@ function Controller:init_singleton()
self:register_observer(self.status)
end

function Controller:destory()
for _, id in pairs(self.augroups) do
vim.api.nvim_del_augroup(id)
end
end

function Controller:register_observer(observer)
table.insert(self.observers, observer)
end
Expand Down
2 changes: 1 addition & 1 deletion lua/fittencode/chat/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ local function setup()
conversation_types_provider = conversation_types_provider,
basic_chat_template_id = basic_chat_template_id
})
controller:init_singleton()
controller:init_integration()
view:register_message_receiver(function(message)
controller:receive_view_message(message)
end)
Expand Down
10 changes: 9 additions & 1 deletion lua/fittencode/inline/controller.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function Controller:new(opts)
return obj
end

function Controller:init_singleton()
function Controller:init_integration()
self.status = Status:new()
self:register_observer(self.status)
self.generate_one_stage = Fn.debounce(Client.generate_one_stage, Config.delay_completion.delaytime)
Expand All @@ -45,6 +45,14 @@ function Controller:init_singleton()
self:enable(Config.inline_completion.enable)
end

function Controller:destory()
self:enable(false)
for _, id in pairs(self.augroups) do
vim.api.nvim_del_augroup(id)
end
self.augroups = {}
end

function Controller:register_observer(observer)
table.insert(self.observers, observer)
end
Expand Down
2 changes: 1 addition & 1 deletion lua/fittencode/inline/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ local controller = nil

local function setup()
controller = Controller:new()
controller:init_singleton()
controller:init_integration()
end

local function get_status()
Expand Down
1 change: 1 addition & 0 deletions lua/fittencode/types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@
---@class FittenCode.Chat.Controller
---@field view FittenCode.Chat.View
---@field model FittenCode.Chat.Model
---@field augroups table
---@field basic_chat_template_id string
---@field conversation_types_provider FittenCode.Chat.ConversationTypeProvider
---@field status fittencode.Chat.Status
Expand Down

0 comments on commit 39d180c

Please sign in to comment.