@@ -20,7 +20,18 @@ local function run_systemlist(cmd)
2020end
2121
2222local function try_tool (tool , args , pattern , max , ignore_patterns )
23+ if type (args ) == ' function' then
24+ local promise = args (pattern , max )
25+ local result = promise and promise :wait ()
26+
27+ if result and type (result ) == ' table' then
28+ return vim .tbl_filter (should_keep (ignore_patterns ), result )
29+ end
30+ end
31+
32+ -- Handle string-based commands (CLI tools)
2333 if vim .fn .executable (tool ) then
34+ pattern = vim .fn .shellescape (pattern ) or ' .'
2435 local result = run_systemlist (tool .. string.format (args , pattern , max ))
2536 if result then
2637 return vim .tbl_filter (should_keep (ignore_patterns ), result )
3243--- @param pattern string
3344--- @return string[]
3445local function find_files_fast (pattern )
35- pattern = vim .fn .shellescape (pattern ) or ' .'
3646 local file_config = config .ui .completion .file_sources
3747 local cli_tool = last_successful_tool or file_config .preferred_cli_tool or ' fd'
3848 local max = file_config .max_files or 10
3949 local ignore_patterns = file_config .ignore_patterns or {}
4050
41- local tools_order = { ' fd' , ' fdfind' , ' rg' , ' git' }
51+ local tools_order = { ' fd' , ' fdfind' , ' rg' , ' git' , ' server ' }
4252 local commands = {
4353 fd = ' --type f --type l --full-path --color=never -E .git -E node_modules -i %s --max-results %d 2>/dev/null' ,
4454 fdfind = ' --type f --type l --color=never -E .git -E node_modules --full-path -i %s --max-results %d 2>/dev/null' ,
4555 rg = ' --files --no-messages --color=never | grep -i %s 2>/dev/null | head -%d' ,
4656 git = ' ls-files --cached --others --exclude-standard | grep -i %s | head -%d' ,
57+ server = function (pattern , max )
58+ return require (' opencode.state' ).api_client :find_files (pattern )
59+ end ,
4760 }
4861
4962 if cli_tool and commands [cli_tool ] then
6679
6780--- @param file string
6881--- @return CompletionItem
69- local function create_file_item (file )
82+ local function create_file_item (file , suffix )
7083 local filename = vim .fn .fnamemodify (file , ' :t' )
7184 local dir = vim .fn .fnamemodify (file , ' :h' )
7285 local file_path = dir == ' .' and filename or dir .. ' /' .. filename
@@ -81,7 +94,7 @@ local function create_file_item(file)
8194 end
8295
8396 return {
84- label = display_label ,
97+ label = display_label .. ( suffix or ' ' ) ,
8598 kind = ' file' ,
8699 detail = detail ,
87100 documentation = ' Path: ' .. detail ,
94107--- @type CompletionSource
95108local file_source = {
96109 name = ' files' ,
97- priority = 0 ,
110+ priority = 5 ,
98111 complete = function (context )
99112 local sort_util = require (' opencode.ui.completion.sort' )
100113 local file_config = config .ui .completion .file_sources
@@ -136,10 +149,17 @@ local file_source = {
136149function M .get_recent_files ()
137150 local project = require (' opencode.config_file' ).get_opencode_project ()
138151 local max = config .ui .completion .file_sources .max_files
139- local is_git = project and project .vcs == ' git'
140-
141- local recent_files = is_git and M .get_git_changed_files () or M .get_old_files () or {}
142- return vim .tbl_map (create_file_item , { unpack (recent_files , 1 , max ) })
152+ local api_client = require (' opencode.state' ).api_client
153+
154+ local result = api_client :get_file_status ():wait ()
155+ local recent_files = {}
156+ if result then
157+ for _ , file in ipairs (result ) do
158+ local suffix = table.concat ({ file .added and ' +' .. file .added , file .removed and ' -' .. file .removed }, ' ' )
159+ table.insert (recent_files , create_file_item (file .path , ' ' .. suffix ))
160+ end
161+ end
162+ return recent_files
143163end
144164
145165--- Get the list of old files in the current working directory
0 commit comments