Skip to content

Commit

Permalink
chore: apply stylua formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
aarondill committed Nov 5, 2023
1 parent 9751d72 commit ad13e2e
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 78 deletions.
8 changes: 4 additions & 4 deletions lua/tabnine.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
local auto_commands = require("tabnine.auto_commands")
local chat_setup = require("tabnine.chat.setup")
local config = require("tabnine.config")
local consts = require("tabnine.consts")
local keymaps = require("tabnine.keymaps")
local semver = require("tabnine.third_party.semver.semver")
local auto_commands = require("tabnine.auto_commands")
local user_commands = require("tabnine.user_commands")
local status = require("tabnine.status")
local keymaps = require("tabnine.keymaps")
local chat_setup = require("tabnine.chat.setup")
local user_commands = require("tabnine.user_commands")

local M = {}

Expand Down
8 changes: 3 additions & 5 deletions lua/tabnine/auto_commands.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
local api = vim.api
local consts = require("tabnine.consts")
local state = require("tabnine.state")
local completion = require("tabnine.completion")
local config = require("tabnine.config")
local consts = require("tabnine.consts")
local state = require("tabnine.state")

local M = {}

Expand Down Expand Up @@ -30,9 +30,7 @@ function M.setup()
api.nvim_create_autocmd("BufEnter", {
pattern = "*",
callback = function()
if completion.should_prefetch() then
completion.prefetch()
end
if completion.should_prefetch() then completion.prefetch() end
end,
})

Expand Down
10 changes: 3 additions & 7 deletions lua/tabnine/binary.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
local uv = vim.loop
local fn = vim.fn
local json = vim.json
local utils = require("tabnine.utils")
local consts = require("tabnine.consts")
local semver = require("tabnine.third_party.semver.semver")
local utils = require("tabnine.utils")
local TabnineBinary = {}
local config = require("tabnine.config")

Expand Down Expand Up @@ -52,12 +52,8 @@ end
local function optional_args()
local config = config.get_config()
local args = {}
if config.log_file_path then
table.insert(args, "--log-file-path=" .. config.log_file_path)
end
if config.tabnine_enterprise_host then
table.insert(args, "--cloud2_url=" .. config.tabnine_enterprise_host)
end
if config.log_file_path then table.insert(args, "--log-file-path=" .. config.log_file_path) end
if config.tabnine_enterprise_host then table.insert(args, "--cloud2_url=" .. config.tabnine_enterprise_host) end
return args
end

Expand Down
4 changes: 1 addition & 3 deletions lua/tabnine/chat/auto_commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ function M.setup()
api.nvim_create_autocmd("VimLeavePre", {
pattern = "*",
callback = function()
if chat.is_open() then
chat.close()
end
if chat.is_open() then chat.close() end
end,
})
end
Expand Down
8 changes: 2 additions & 6 deletions lua/tabnine/chat/binary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,12 @@ function ChatBinary:close()
end

function ChatBinary:is_open()
if self.handle == nil then
return false
end
if self.handle == nil then return false end
return self.handle:is_active()
end

function ChatBinary:start()
if self.pid then
return
end
if self.pid then return end

self.stdin = uv.new_pipe()
self.stdout = uv.new_pipe()
Expand Down
14 changes: 4 additions & 10 deletions lua/tabnine/chat/init.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
local chat_binary = require("tabnine.chat.binary")
local fn = vim.fn
local utils = require("tabnine.utils")
local tabnine_binary = require("tabnine.binary")
local utils = require("tabnine.utils")
local api = vim.api
local config = require("tabnine.config")

Expand All @@ -12,9 +12,7 @@ local chat_state = nil

local function get_diagnostics_text()
local diagnostics = vim.diagnostic.get(0)
if #diagnostics == 0 then
return ""
end
if #diagnostics == 0 then return "" end
local text = ""
for _, diagnostic in ipairs(diagnostics) do
text = text .. diagnostic.message .. "\n"
Expand All @@ -25,9 +23,7 @@ end
local function read_chat_state()
if fn.filereadable(CHAT_STATE_FILE) == 1 then
local lines = fn.readfile(CHAT_STATE_FILE)
if #lines > 0 then
return vim.json.decode(lines[1], { luanil = { object = true, array = true } })
end
if #lines > 0 then return vim.json.decode(lines[1], { luanil = { object = true, array = true } }) end
return { conversations = {} }
end
return { conversations = {} }
Expand All @@ -40,9 +36,7 @@ end
local function register_events()
chat_binary:register_event("init", function(_, answer)
local init = { ide = "ij", isDarkTheme = true }
if config.is_enterprise() then
init.serverUrl = config.get_config().tabnine_enterprise_host
end
if config.is_enterprise() then init.serverUrl = config.get_config().tabnine_enterprise_host end
answer(init)
end)

Expand Down
4 changes: 2 additions & 2 deletions lua/tabnine/chat/setup.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
local user_commands = require("tabnine.chat.user_commands")
local auto_commands = require("tabnine.chat.auto_commands")
local features = require("tabnine.features")
local chat = require("tabnine.chat")
local config = require("tabnine.config")
local features = require("tabnine.features")
local user_commands = require("tabnine.chat.user_commands")

local M = {}

Expand Down
2 changes: 1 addition & 1 deletion lua/tabnine/chat/user_commands.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
local M = {}
local api = vim.api
local config = require("tabnine.config")
local chat = require("tabnine.chat")
local config = require("tabnine.config")

function M.setup()
if not config.is_enterprise() then
Expand Down
14 changes: 5 additions & 9 deletions lua/tabnine/completion.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ local M = {}
local api = vim.api
local fn = vim.fn
local uv = vim.loop
local state = require("tabnine.state")
local config = require("tabnine.config")
local consts = require("tabnine.consts")
local utils = require("tabnine.utils")
local state = require("tabnine.state")
local tabnine_binary = require("tabnine.binary")
local config = require("tabnine.config")
local utils = require("tabnine.utils")

local function valid_response(response)
return response and response.results and #response.results > 0 and #response.results[1].new_prefix > 0
Expand All @@ -31,9 +31,7 @@ function M.accept()
end

function M.clear()
if state.cancel_completion then
state.cancel_completion()
end
if state.cancel_completion then state.cancel_completion() end
state.debounce_timer:stop()
api.nvim_buf_clear_namespace(0, consts.tabnine_namespace, 0, -1)
end
Expand Down Expand Up @@ -92,9 +90,7 @@ function M.complete()
end

function M.render(completion, old_prefix, changedtick)
if not (vim.b.changedtick == changedtick) then
return
end
if not (vim.b.changedtick == changedtick) then return end

local lines = utils.str_to_lines(completion)

Expand Down
4 changes: 1 addition & 3 deletions lua/tabnine/features.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ local tabnine_binary = require("tabnine.binary")

function M.if_feature_enabled(features, run_if_enabled)
tabnine_binary:request({ Features = { dummy = true } }, function(response)
if not response or not response.enabled_features then
return
end
if not response or not response.enabled_features then return end
for _, feature in ipairs(features) do
if vim.tbl_contains(response.enabled_features, feature) then
run_if_enabled()
Expand Down
12 changes: 4 additions & 8 deletions lua/tabnine/keymaps.lua
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
local M = {}
local state = require("tabnine.state")
local config = require("tabnine.config")
local completion = require("tabnine.completion")
local config = require("tabnine.config")
local state = require("tabnine.state")

function M.setup()
local accept_keymap = config.get_config().accept_keymap
local dismiss_keymap = config.get_config().dismiss_keymap
vim.keymap.set("i", accept_keymap, function()
if not state.completions_cache then
return accept_keymap
end
if not state.completions_cache then return accept_keymap end
vim.schedule(completion.accept)
end, { expr = true })

vim.keymap.set("i", dismiss_keymap, function()
if not state.completions_cache then
return dismiss_keymap
end
if not state.completions_cache then return dismiss_keymap end
vim.schedule(function()
completion.clear()
state.completions_cache = nil
Expand Down
4 changes: 2 additions & 2 deletions lua/tabnine/user_commands.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
local M = {}
local api = vim.api
local status = require("tabnine.status")
local chat = require("tabnine.chat")
local config = require("tabnine.config")
local status = require("tabnine.status")
local tabnine_binary = require("tabnine.binary")
local chat = require("tabnine.chat")

function M.setup()
if not config.is_enterprise() then
Expand Down
24 changes: 6 additions & 18 deletions lua/tabnine/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,12 @@ function M.lines_to_str(lines)
end

function M.remove_matching_suffix(str, suffix)
if not M.ends_with(str, suffix) then
return str
end
if not M.ends_with(str, suffix) then return str end
return str:sub(1, -#suffix - 1)
end

function M.remove_matching_prefix(str, prefix)
if not M.starts_with(str, prefix) then
return str
end
if not M.starts_with(str, prefix) then return str end
return str:sub(#prefix)
end

Expand All @@ -37,9 +33,7 @@ end

function M.prequire(...)
local status, lib = pcall(require, ...)
if status then
return lib
end
if status then return lib end
return nil
end

Expand All @@ -57,17 +51,13 @@ function M.current_position()
end

function M.ends_with(str, suffix)
if str == "" then
return true
end
if str == "" then return true end

return str:sub(-#suffix) == suffix
end

function M.starts_with(str, prefix)
if str == "" then
return true
end
if str == "" then return true end

return str:sub(1, #prefix) == prefix
end
Expand All @@ -88,9 +78,7 @@ end

function M.selected_text()
local mode = vim.fn.mode()
if mode ~= "v" and mode ~= "V" and mode ~= "" then
return ""
end
if mode ~= "v" and mode ~= "V" and mode ~= "" then return "" end
local a_orig = vim.fn.getreg("a")
vim.cmd([[silent! normal! "aygv]])
local text = vim.fn.getreg("a")
Expand Down

0 comments on commit ad13e2e

Please sign in to comment.