Skip to content

Commit 854b42c

Browse files
committed
Fix missing suggestions when open file not from current workspace
For some cases opening a file from not current workspace (directory detected by `options.root_dir`, fallback to current working directory) would result in errors in logs and missing suggestions until you delete that buffer from another workspace. Now neocodeium only sends buffers from current workspace and properly changes workspace for `:h :lcd`
1 parent 0075d18 commit 854b42c

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

lua/neocodeium/doc.lua

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,23 @@ local nvim_buf_get_var = vim.api.nvim_buf_get_var
1414
local nvim_create_augroup = vim.api.nvim_create_augroup
1515
local nvim_create_autocmd = vim.api.nvim_create_autocmd
1616

17+
local uv = vim.uv
18+
1719
-- Cache --------------------------------------------------- {{{1
1820

1921
---Persistent cache of the buffers data.
2022
---@type table<bufnr, { data: document, tick: integer }>
2123
local cached_data = {}
2224

23-
local project_root = stdio.to_uri(stdio.get_project_root())
25+
local prev_cwd = uv.cwd()
26+
local project_root, project_root_uri
27+
28+
local function update_project_root()
29+
project_root = stdio.get_project_root()
30+
project_root_uri = stdio.to_uri(project_root)
31+
end
32+
33+
update_project_root()
2434

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

@@ -38,7 +48,18 @@ nvim_create_autocmd("DirChanged", {
3848
group = augroup,
3949
desc = "Update project's root directory",
4050
callback = function()
41-
project_root = stdio.to_uri(stdio.get_project_root())
51+
update_project_root()
52+
end,
53+
})
54+
55+
---Autocmd to update project's root directory.
56+
nvim_create_autocmd("WinEnter", {
57+
group = augroup,
58+
desc = "Update project's root directory",
59+
callback = function()
60+
if uv.cwd() ~= prev_cwd then
61+
update_project_root()
62+
end
4263
end,
4364
})
4465

@@ -69,7 +90,7 @@ function M.get(buf, ft, max_lines, pos)
6990
language = filetype.language[lang] or filetype.language.unspecified,
7091
cursor_position = { row = pos[1], col = pos[2] },
7192
absolute_uri = stdio.to_uri(name),
72-
workspace_uri = project_root,
93+
workspace_uri = project_root_uri,
7394
line_ending = "\n",
7495
}
7596
end
@@ -92,6 +113,7 @@ function M.get_all_loaded(cur_bufnr)
92113
and buf_ft ~= ""
93114
and utils.is_normal_buf(b)
94115
and state:get_status(b) == STATUS.enabled
116+
and nvim_buf_get_name(b):find(project_root, 1, true)
95117
then
96118
local buf_cache = cached_data[b]
97119
local buf_tick = nvim_buf_get_var(b, "changedtick") ---@type integer

0 commit comments

Comments
 (0)