fix: thrown error when trying to use codebase with no buffer opened (#1541)

* Fix - Fix thrown error when trying to use @codebase with no buffer opened

* Style - Fix stylua formatting in repo_map and sidebar

* Fix - Restore code selection handling in sidebar
This was a mistake on my part while rushing to make the PR. I deleted an
unrelated commit that got sent by mistake, and during the second review,
I didn't notice that this important code selection functionality was
removed. The code has now been properly restored.
This commit is contained in:
Canopus
2025-03-09 16:20:43 +00:00
committed by GitHub
parent 05b3b843c8
commit 4976807a33
2 changed files with 27 additions and 5 deletions

View File

@@ -62,6 +62,12 @@ end
local cache = {}
function RepoMap.get_repo_map(file_ext)
-- Add safety check for file_ext
if not file_ext then
Utils.warn("No file extension available - please open a file first")
return {}
end
local repo_map = RepoMap._get_repo_map(file_ext) or {}
if not repo_map or next(repo_map) == nil then
Utils.warn("The repo map is empty. Maybe do not support this language: " .. file_ext)
@@ -70,7 +76,15 @@ function RepoMap.get_repo_map(file_ext)
end
function RepoMap._get_repo_map(file_ext)
file_ext = file_ext or vim.fn.expand("%:e")
-- Add safety check at the start of the function
if not file_ext then
local current_buf = vim.api.nvim_get_current_buf()
local buf_name = vim.api.nvim_buf_get_name(current_buf)
if buf_name and buf_name ~= "" then file_ext = vim.fn.fnamemodify(buf_name, ":e") end
if not file_ext or file_ext == "" then return {} end
end
local project_root = Utils.root.get()
local cache_key = project_root .. "." .. file_ext
local cached = cache[cache_key]