Skip to content

Commit 031bf0a

Browse files
committed
feat: support for folder mentions
1 parent e99a463 commit 031bf0a

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ require('opencode').setup({
181181
completion = {
182182
file_sources = {
183183
enabled = true,
184-
preferred_cli_tool = 'fd', -- 'fd','fdfind','rg','git' if nil, it will use the best available tool
184+
preferred_cli_tool = 'server', -- 'fd','fdfind','rg','git','server' if nil, it will use the best available tool, 'server' uses opencode cli to get file list (works cross platform) and supports folders
185185
ignore_patterns = {
186186
'^%.git/',
187187
'^%.svn/',

lua/opencode/context.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@ function M.add_file(file)
9696
M.context.mentioned_files = {}
9797
end
9898

99-
if vim.fn.filereadable(file) ~= 1 then
99+
local is_file = vim.fn.filereadable(file) == 1
100+
local is_dir = vim.fn.isdirectory(file) == 1
101+
if not is_file and not is_dir then
100102
vim.notify('File not added to context. Could not read.')
101103
return
102104
end

lua/opencode/ui/completion/files.lua

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,13 @@ end
2222
local function try_tool(tool, args, pattern, max, ignore_patterns)
2323
if type(args) == 'function' then
2424
local promise = args(pattern, max)
25-
local result = promise and promise:wait()
25+
local result = promise and promise.and_then and promise:wait()
2626

2727
if result and type(result) == 'table' then
2828
return vim.tbl_filter(should_keep(ignore_patterns), result)
2929
end
3030
end
3131

32-
-- Handle string-based commands (CLI tools)
3332
if vim.fn.executable(tool) then
3433
pattern = vim.fn.shellescape(pattern) or '.'
3534
local result = run_systemlist(tool .. string.format(args, pattern, max))
@@ -44,17 +43,17 @@ end
4443
---@return string[]
4544
local function find_files_fast(pattern)
4645
local file_config = config.ui.completion.file_sources
47-
local cli_tool = last_successful_tool or file_config.preferred_cli_tool or 'fd'
46+
local cli_tool = last_successful_tool or file_config.preferred_cli_tool or 'server'
4847
local max = file_config.max_files or 10
4948
local ignore_patterns = file_config.ignore_patterns or {}
5049

51-
local tools_order = { 'fd', 'fdfind', 'rg', 'git', 'server' }
50+
local tools_order = { 'server', 'fd', 'fdfind', 'rg', 'git' }
5251
local commands = {
5352
fd = ' --type f --type l --full-path --color=never -E .git -E node_modules -i %s --max-results %d 2>/dev/null',
5453
fdfind = ' --type f --type l --color=never -E .git -E node_modules --full-path -i %s --max-results %d 2>/dev/null',
5554
rg = ' --files --no-messages --color=never | grep -i %s 2>/dev/null | head -%d',
5655
git = ' ls-files --cached --others --exclude-standard | grep -i %s | head -%d',
57-
server = function(pattern, max)
56+
server = function(pattern)
5857
return require('opencode.state').api_client:find_files(pattern)
5958
end,
6059
}
@@ -147,8 +146,6 @@ local file_source = {
147146
---Get the list of recent files
148147
---@return CompletionItem[]
149148
function M.get_recent_files()
150-
local project = require('opencode.config_file').get_opencode_project()
151-
local max = config.ui.completion.file_sources.max_files
152149
local api_client = require('opencode.state').api_client
153150

154151
local result = api_client:get_file_status():wait()

0 commit comments

Comments
 (0)