Skip to content

Commit

Permalink
refactor!: remove utils.script_path and replace with utils.module_dir (
Browse files Browse the repository at this point in the history
…#166)

This more clearly describes what it returns.
script_path is replaced with script_dir which returns a value based on the currently running file

note: module_dir relies on utils.lua's location, and will break if the file is moved
  • Loading branch information
aarondill committed Mar 25, 2024
1 parent 5e813f8 commit f0eb52a
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 7 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
13 changes: 11 additions & 2 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

0 comments on commit f0eb52a

Please sign in to comment.