@@ -4,6 +4,11 @@ local state = require('opencode.state')
44local icons = require (' opencode.ui.icons' )
55
66local M = {}
7+ local kind_priority = {
8+ selection_item = 3 ,
9+ mentioned_file = 4 ,
10+ subagent = 5 ,
11+ }
712
813--- @generic T
914--- @param name string
@@ -13,7 +18,7 @@ local M = {}
1318--- @param icon string | nil
1419--- @param additional_data ? T
1520--- @return CompletionItem
16- local function create_context_item (name , type , available , documentation , icon , additional_data )
21+ local function create_context_item (name , type , available , documentation , icon , additional_data , priority )
1722 local label = name
1823
1924 return {
@@ -24,6 +29,7 @@ local function create_context_item(name, type, available, documentation, icon, a
2429 documentation = documentation or (available and name or ' Enable ' .. name .. ' for this message' ),
2530 insert_text = ' ' ,
2631 source_name = ' context' ,
32+ priority = priority or (available and 100 or 200 ),
2733 data = { type = type , name = name , available = available , additional_data = additional_data },
2834 }
2935end
@@ -100,7 +106,15 @@ local function add_mentioned_files_items(ctx)
100106 local filename = vim .fn .fnamemodify (file , ' :~:.' )
101107 table.insert (
102108 items ,
103- create_context_item (filename , ' mentioned_file' , true , ' Select to remove file ' .. filename , icons .get (' file' ))
109+ create_context_item (
110+ filename ,
111+ ' mentioned_file' ,
112+ true ,
113+ ' Select to remove file ' .. filename ,
114+ icons .get (' file' ),
115+ nil ,
116+ kind_priority .mentioned_file
117+ )
104118 )
105119 end
106120 end
@@ -125,7 +139,15 @@ local function add_selection_items(ctx)
125139 string.format (' Selection %d %s (%s)' , i , selection .file and selection .file .name or ' Untitled' , selection .lines )
126140 table.insert (
127141 items ,
128- create_context_item (label , ' selection_item' , true , format_selection (selection ), icons .get (' selection' ), selection )
142+ create_context_item (
143+ label ,
144+ ' selection_item' ,
145+ true ,
146+ format_selection (selection ),
147+ icons .get (' selection' ),
148+ selection ,
149+ kind_priority .selection_item
150+ )
129151 )
130152 end
131153 return items
@@ -141,7 +163,15 @@ local function add_subagents_items(ctx)
141163 for _ , agent in ipairs (ctx .mentioned_subagents or {}) do
142164 table.insert (
143165 items ,
144- create_context_item (agent .. ' (agent)' , ' subagent' , true , ' Select to remove agent ' .. agent , icons .get (' agent' ))
166+ create_context_item (
167+ agent .. ' (agent)' ,
168+ ' subagent' ,
169+ true ,
170+ ' Select to remove agent ' .. agent ,
171+ icons .get (' agent' ),
172+ nil ,
173+ kind_priority .subagent
174+ )
145175 )
146176 end
147177 return items
@@ -198,13 +228,6 @@ local context_source = {
198228 end , items )
199229 end
200230
201- table.sort (items , function (a , b )
202- if a .data .available ~= b .data .available then
203- return a .data .available
204- end
205- return a .label < b .label
206- end )
207-
208231 return items
209232 end ,
210233 on_complete = function (item )
0 commit comments