From ad13e2e735259bd6e8240874f8302241e07e5791 Mon Sep 17 00:00:00 2001 From: aarondill Date: Sun, 5 Nov 2023 15:13:36 -0600 Subject: [PATCH] chore: apply stylua formatting --- lua/tabnine.lua | 8 ++++---- lua/tabnine/auto_commands.lua | 8 +++----- lua/tabnine/binary.lua | 10 +++------- lua/tabnine/chat/auto_commands.lua | 4 +--- lua/tabnine/chat/binary.lua | 8 ++------ lua/tabnine/chat/init.lua | 14 ++++---------- lua/tabnine/chat/setup.lua | 4 ++-- lua/tabnine/chat/user_commands.lua | 2 +- lua/tabnine/completion.lua | 14 +++++--------- lua/tabnine/features.lua | 4 +--- lua/tabnine/keymaps.lua | 12 ++++-------- lua/tabnine/user_commands.lua | 4 ++-- lua/tabnine/utils.lua | 24 ++++++------------------ 13 files changed, 38 insertions(+), 78 deletions(-) diff --git a/lua/tabnine.lua b/lua/tabnine.lua index f835546..aa14c66 100644 --- a/lua/tabnine.lua +++ b/lua/tabnine.lua @@ -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 = {} diff --git a/lua/tabnine/auto_commands.lua b/lua/tabnine/auto_commands.lua index e5b73c7..40b5241 100644 --- a/lua/tabnine/auto_commands.lua +++ b/lua/tabnine/auto_commands.lua @@ -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 = {} @@ -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, }) diff --git a/lua/tabnine/binary.lua b/lua/tabnine/binary.lua index b3af5aa..b8c7662 100644 --- a/lua/tabnine/binary.lua +++ b/lua/tabnine/binary.lua @@ -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") @@ -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 diff --git a/lua/tabnine/chat/auto_commands.lua b/lua/tabnine/chat/auto_commands.lua index 8390c23..4c05be1 100644 --- a/lua/tabnine/chat/auto_commands.lua +++ b/lua/tabnine/chat/auto_commands.lua @@ -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 diff --git a/lua/tabnine/chat/binary.lua b/lua/tabnine/chat/binary.lua index d6c3f7a..5f2db86 100644 --- a/lua/tabnine/chat/binary.lua +++ b/lua/tabnine/chat/binary.lua @@ -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() diff --git a/lua/tabnine/chat/init.lua b/lua/tabnine/chat/init.lua index 5205187..0697df0 100644 --- a/lua/tabnine/chat/init.lua +++ b/lua/tabnine/chat/init.lua @@ -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") @@ -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" @@ -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 = {} } @@ -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) diff --git a/lua/tabnine/chat/setup.lua b/lua/tabnine/chat/setup.lua index b8f22e9..4c322eb 100644 --- a/lua/tabnine/chat/setup.lua +++ b/lua/tabnine/chat/setup.lua @@ -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 = {} diff --git a/lua/tabnine/chat/user_commands.lua b/lua/tabnine/chat/user_commands.lua index 61167e5..07820cd 100644 --- a/lua/tabnine/chat/user_commands.lua +++ b/lua/tabnine/chat/user_commands.lua @@ -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 diff --git a/lua/tabnine/completion.lua b/lua/tabnine/completion.lua index 5c6400a..cb162a3 100644 --- a/lua/tabnine/completion.lua +++ b/lua/tabnine/completion.lua @@ -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 @@ -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 @@ -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) diff --git a/lua/tabnine/features.lua b/lua/tabnine/features.lua index 4810c7f..155bd5e 100644 --- a/lua/tabnine/features.lua +++ b/lua/tabnine/features.lua @@ -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() diff --git a/lua/tabnine/keymaps.lua b/lua/tabnine/keymaps.lua index 64ed2cb..9eb6554 100644 --- a/lua/tabnine/keymaps.lua +++ b/lua/tabnine/keymaps.lua @@ -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 diff --git a/lua/tabnine/user_commands.lua b/lua/tabnine/user_commands.lua index ba78684..04960a3 100644 --- a/lua/tabnine/user_commands.lua +++ b/lua/tabnine/user_commands.lua @@ -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 diff --git a/lua/tabnine/utils.lua b/lua/tabnine/utils.lua index 1bee289..03735fc 100644 --- a/lua/tabnine/utils.lua +++ b/lua/tabnine/utils.lua @@ -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 @@ -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 @@ -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 @@ -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")