Skip to content

Commit

Permalink
Adjust documentation gathering for new codeium versions
Browse files Browse the repository at this point in the history
Also bump codeium binary version to v1.26.0

Closes #24
  • Loading branch information
monkoose committed Nov 5, 2024
1 parent 17580e5 commit fa29aef
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 15 deletions.
4 changes: 2 additions & 2 deletions lua/neocodeium/_meta.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
---@field editor_language string
---@field cursor_position { row: integer, col: integer }
---@field language integer
---@field absolute_path string
---@field relative_path string
---@field absolute_uri string
---@field workspace_uri string|nil
---@field line_ending string

---@class request_metadata
Expand Down
2 changes: 1 addition & 1 deletion lua/neocodeium/binary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ local fn = vim.fn
---@field version string
---@field path filepath
---@field suffix? string
local Bin = { version = "1.14.12" }
local Bin = { version = "1.26.0" }

-- Auxiliary functions ------------------------------------- {{{1

Expand Down
11 changes: 2 additions & 9 deletions lua/neocodeium/chat.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ local options = require("neocodeium.options").options
local server = require("neocodeium.server")
local doc = require("neocodeium.doc")
local echo = require("neocodeium.utils.echo")

local fs = vim.fs
local uv = vim.uv
local stdio = require("neocodeium.utils.stdio")

local nvim_create_autocmd = vim.api.nvim_create_autocmd
local nvim_create_augroup = vim.api.nvim_create_augroup
Expand All @@ -23,11 +21,6 @@ nvim_create_autocmd("BufEnter", {
end,
})

---@return string|nil
local function get_project_root()
return fs.root(uv.cwd() or 0, options.root_dir)
end

---Opens chat in browser
---@param response table
function chat.launch(response)
Expand Down Expand Up @@ -81,7 +74,7 @@ end

---Sends a request to the server to add a tracked workspace
function chat.add_tracked_workspace()
local root = get_project_root()
local root = stdio.get_project_root()
if root then
server:request("AddTrackedWorkspace", { workspace = root })
end
Expand Down
17 changes: 14 additions & 3 deletions lua/neocodeium/doc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

local filetype = require("neocodeium.filetype")
local options = require("neocodeium.options").options
local stdio = require("neocodeium.utils.stdio")

local fn = vim.fn
local nvim_buf_get_lines = vim.api.nvim_buf_get_lines
local nvim_buf_get_name = vim.api.nvim_buf_get_name
local nvim_list_bufs = vim.api.nvim_list_bufs
Expand All @@ -19,6 +19,8 @@ local nvim_create_autocmd = vim.api.nvim_create_autocmd
---@type table<bufnr, { data: document, tick: integer }>
local cached_data = {}

local project_root = stdio.to_uri(stdio.get_project_root())

local augroup = nvim_create_augroup("neocodeium_docs", {})

---Autocmd to clear docs cache
Expand All @@ -30,6 +32,15 @@ nvim_create_autocmd("BufUnload", {
end,
})

---Autocmd to update project's root directory
nvim_create_autocmd("DirChanged", {
group = augroup,
desc = "Update project's root directory",
callback = function()
project_root = stdio.to_uri(stdio.get_project_root())
end,
})

-- Auxiliary functions ------------------------------------- {{{1

---Returns iterator over numbers of all loaded buffers
Expand Down Expand Up @@ -76,8 +87,8 @@ function M.get(buf, ft, max_lines, pos)
editor_language = ft == "" and "unspecified" or ft,
language = filetype.language[lang] or filetype.language.unspecified,
cursor_position = { row = pos[1], col = pos[2] },
absolute_path = name,
relative_path = fn.fnamemodify(name, ":."),
absolute_uri = stdio.to_uri(name),
workspace_uri = project_root,
line_ending = "\n",
}
end
Expand Down
26 changes: 26 additions & 0 deletions lua/neocodeium/utils/stdio.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
local options = require("neocodeium.options").options
local utils = require("neocodeium.utils")

local fn = vim.fn
local fs = vim.fs
local uv = vim.uv

local M = {}

Expand Down Expand Up @@ -40,4 +45,25 @@ function M.root_dir()
return fn.fnamemodify(script_path(), ":h:h:h:h")
end

---@return string|nil
function M.get_project_root()
return fs.root(0, options.root_dir) or uv.cwd()
end

local is_windows = utils.get_system_info().is_win
---@param path? string
---@return string|nil
function M.to_uri(path)
if not path then
return
end

if is_windows then
path = path:gsub("\\", "/")
return "file:///" .. path
else
return "file://" .. path
end
end

return M

0 comments on commit fa29aef

Please sign in to comment.