Skip to content

Commit

Permalink
Merge branch 'master' into refactor_export_keymaps
Browse files Browse the repository at this point in the history
  • Loading branch information
amirbilu committed Mar 26, 2024
2 parents f5b546d + 3328272 commit 1bfba7b
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lua/tabnine/binary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ local TabnineBinary = {}
local config = require("tabnine.config")

local api_version = "4.4.223"
local binaries_path = utils.script_path() .. "/binaries"
local binaries_path = utils.module_dir() .. "/binaries"

local function arch_and_platform()
local os_uname = uv.os_uname()
Expand Down
2 changes: 1 addition & 1 deletion lua/tabnine/chat/binary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ local function binary_name()
end
end

local binary_path = utils.script_path() .. "/../chat/target/release/" .. binary_name()
local binary_path = utils.module_dir() .. "/chat/target/release/" .. binary_name()

function ChatBinary:available()
return vim.fn.executable(binary_path) == 1
Expand Down
4 changes: 2 additions & 2 deletions lua/tabnine/chat/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ local get_symbols_request = nil

local M = { enabled = false }

local CHAT_STATE_FILE = utils.script_path() .. "/../chat_state.json"
local CHAT_SETTINGS_FILE = utils.script_path() .. "/../chat_settings.json"
local CHAT_STATE_FILE = utils.module_dir() .. "/chat_state.json"
local CHAT_SETTINGS_FILE = utils.module_dir() .. "/chat_settings.json"

local chat_state = nil
local chat_settings = nil
Expand Down
2 changes: 1 addition & 1 deletion lua/tabnine/status.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ local fn = vim.fn
local utils = require("tabnine.utils")

local M = {}
local DISABLED_FILE = utils.script_path() .. "/.disabled"
local DISABLED_FILE = utils.module_dir() .. "/.disabled"
local config = require("tabnine.config")
local state = require("tabnine.state")
local tabnine_binary = require("tabnine.binary")
Expand Down
20 changes: 16 additions & 4 deletions lua/tabnine/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,18 @@ function M.subset(tbl, from, to)
return { unpack(tbl, from, to) }
end

function M.script_path()
---returns the directory of the running script
---@return string
function M.script_dir()
local str = debug.getinfo(2, "S").source:sub(2)
return str:match("(.*/)") .. "../.."
return str:match("(.*/)") or "./"
end

---returns the directory of the root of the module
---@return string
function M.module_dir()
-- HACK: This only works if this file is not moved!
return M.script_dir() .. "../.."
end

function M.prequire(...)
Expand Down Expand Up @@ -111,14 +120,17 @@ function M.set(array)
return uniqueValues
end

function M.select_range(range)
---Selects a given range of text
---@param range table
---@param selection_mode? 'charwise'|'linewise'|'blockwise'|'v'|'V'|'<C-v>'
function M.select_range(range, selection_mode)
local start_row, start_col, end_row, end_col = range[1][1], range[1][2], range[2][1], range[2][2]

local v_table = { charwise = "v", linewise = "V", blockwise = "<C-v>" }
selection_mode = selection_mode or "charwise"

-- Normalise selection_mode
if vim.tbl_contains(vim.tbl_keys(v_table), selection_mode) then selection_mode = v_table[selection_mode] end
selection_mode = v_table[selection_mode] or selection_mode

-- enter visual mode if normal or operator-pending (no) mode
-- Why? According to https://learnvimscriptthehardway.stevelosh.com/chapters/15.html
Expand Down

0 comments on commit 1bfba7b

Please sign in to comment.