Skip to content

Commit

Permalink
Adding enable_completions
Browse files Browse the repository at this point in the history
  • Loading branch information
luozhiya committed Jun 12, 2024
1 parent 4b682b6 commit 7ec83d8
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# The language server has a built-in code formatter, courtesy of CppCXY/EmmyLuaCodeStyle
# The language server has a built-in code formatter, courtesy of CppCXY/EmmyLuaCodeStyle
# https://luals.github.io/wiki/formatter/
# https://github.com/CppCXY/EmmyLuaCodeStyle/blob/master/lua.template.editorconfig

Expand All @@ -10,3 +10,4 @@ insert_final_newline = true
indent_style = space
indent_size = 2
quote_style = single
max_line_length = 200
3 changes: 3 additions & 0 deletions lua/fittencode/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ M.api = {
triggering_completion = function()
InlineEngine.triggering_completion()
end,
enable_completions = function(opts)
InlineEngine.enable_completions(opts)
end,
---@return boolean
has_suggestions = function()
return InlineEngine.has_suggestions()
Expand Down
57 changes: 57 additions & 0 deletions lua/fittencode/engines/inline/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,63 @@ function M.is_inline_enabled()
return true
end

---@class EnableCompletionsOptions
---@field enable? boolean
---@field mode? 'inline' | 'source' | 'all'
---@field global? boolean
---@field suffixes? string[]
function M.enable_completions(opts)
if not opts then
return
end
local enable = opts.enable
local mode = opts.mode or 'inline'
local global = opts.global
local suffixes = opts.suffixes
global = global == nil and true or global
enable = enable == nil and true or enable
local _inline = function()
return mode == 'inline' or mode == 'all'
end
local _source = function()
return mode == 'source' or mode == 'all'
end
local _global = function()
if _inline() then
Config.options.inline_completion.enable = enable
end
if _source() then
Config.options.source_completion.enable = enable
end
end
local _suffixes = function(tbl, filters)
if enable then
tbl = vim.tbl_extend('force', tbl, filters)
else
tbl = vim.tbl_filter(function(ft)
return not vim.tbl_contains(filters, ft)
end, tbl)
end
end
local _local = function()
if _inline() then
_suffixes(Config.options.disable_specific_inline_completion.suffixes, suffixes)
else
_suffixes(Config.options.source_completion.disable_specific_source_completion.suffixes, suffixes)
end
end
if global then
_global()
else
_local()
end
if enable then
status:update(SC.IDLE)
else
status:update(SC.DISABLED)
end
end

---@return integer
function M.get_status()
return status:get_current()
Expand Down
11 changes: 6 additions & 5 deletions lua/fittencode/status.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ local M = {}

---@type StatusCodes
local C = {
IDLE = 0,
GENERATING = 1,
ERROR = 2,
NO_MORE_SUGGESTIONS = 3,
SUGGESTIONS_READY = 4,
DISABLED = 1,
IDLE = 2,
GENERATING = 3,
ERROR = 4,
NO_MORE_SUGGESTIONS = 5,
SUGGESTIONS_READY = 6,
}

M.C = C
Expand Down

0 comments on commit 7ec83d8

Please sign in to comment.