@@ -345,8 +345,17 @@ function Config:get_inheritable_tags(headline)
345
345
end , headline .tags )
346
346
end
347
347
348
+ function Config :get_priorities ()
349
+ return {
350
+ [self .opts .org_priority_highest ] = { type = ' highest' , hl_group = ' @org.priority.highest' },
351
+ [self .opts .org_priority_default ] = { type = ' default' , hl_group = ' @org.priority.default' },
352
+ [self .opts .org_priority_lowest ] = { type = ' lowest' , hl_group = ' @org.priority.lowest' },
353
+ }
354
+ end
355
+
348
356
function Config :setup_ts_predicates ()
349
357
local todo_keywords = self :get_todo_keywords ().KEYS
358
+ local valid_priorities = self :get_priorities ()
350
359
351
360
vim .treesitter .query .add_predicate (' org-is-todo-keyword?' , function (match , _ , source , predicate )
352
361
local node = match [predicate [2 ]]
@@ -358,6 +367,41 @@ function Config:setup_ts_predicates()
358
367
return false
359
368
end , true )
360
369
370
+ vim .treesitter .query .add_predicate (' org-is-valid-priority?' , function (match , _ , source , predicate )
371
+ local node = match [predicate [2 ]]
372
+ local type = predicate [3 ]
373
+ if not node then
374
+ return false
375
+ end
376
+
377
+ local text = vim .treesitter .get_node_text (node , source )
378
+ local is_valid = valid_priorities [text ] and valid_priorities [text ].type == type
379
+ if not is_valid then
380
+ return false
381
+ end
382
+ local priority_text = ' [#' .. text .. ' ]'
383
+ local full_node_text = vim .treesitter .get_node_text (node :parent (), source )
384
+ if priority_text ~= full_node_text then
385
+ return false
386
+ end
387
+
388
+ local prev_sibling = node :parent ():prev_sibling ()
389
+ -- If first child, consider it valid
390
+ if not prev_sibling then
391
+ return true
392
+ end
393
+
394
+ -- If prev sibling has more prev siblings, it means that the prev_sibling is not a todo keyword
395
+ -- so this priority is not valid
396
+ if prev_sibling :prev_sibling () then
397
+ return false
398
+ end
399
+
400
+ local todo_text = vim .treesitter .get_node_text (prev_sibling , source )
401
+ local is_prev_sibling_todo_keyword = todo_keywords [todo_text ] and true or false
402
+ return is_prev_sibling_todo_keyword
403
+ end , true )
404
+
361
405
vim .treesitter .query .add_directive (' org-set-block-language!' , function (match , _ , bufnr , pred , metadata )
362
406
local lang_node = match [pred [2 ]]
363
407
if not lang_node then
0 commit comments