@@ -382,3 +382,64 @@ describe('Autocompletion', function()
382382 end )
383383 end )
384384end )
385+
386+ describe (' Blink completion' , function ()
387+ after_each (function ()
388+ vim .cmd ([[ silent! %bw!]] )
389+ end )
390+
391+ it (' should preserve `#+` prefix when completing directives' , function ()
392+ helpers .create_file ({
393+ ' #+fi' ,
394+ })
395+
396+ vim .fn .cursor (1 , 5 )
397+
398+ local blink = require (' orgmode.org.autocompletion.blink' )
399+ local source = blink .new ()
400+
401+ local line = vim .fn .getline (' .' )
402+ local col = vim .fn .col (' .' ) - 1 -- blink uses 0-indexed columns
403+
404+ local ctx = {
405+ line = line ,
406+ cursor = { 1 , col },
407+ bufnr = vim .api .nvim_get_current_buf (),
408+ }
409+
410+ local completion_result = nil
411+ local completed = false
412+
413+ source :get_completions (ctx , function (result )
414+ completion_result = result
415+ completed = true
416+ end )
417+
418+ vim .wait (500 , function ()
419+ return completed
420+ end )
421+
422+ assert (completed , ' Completion should have finished' )
423+ assert (completion_result and completion_result .items , ' Should have completion items' )
424+
425+ if # completion_result .items == 0 then
426+ error (' No completion items returned' )
427+ end
428+
429+ local directive_item = nil
430+ for _ , item in ipairs (completion_result .items ) do
431+ if item .label and item .label :match (' ^#%+.*' ) then
432+ directive_item = item
433+ break
434+ end
435+ end
436+
437+ assert (directive_item , ' Should find a directive completion item' )
438+ assert (
439+ directive_item .insertText :match (' ^#%+' ),
440+ string.format (" insertText should start with '+#', got: %s" , directive_item .insertText )
441+ )
442+
443+ assert (line :sub (1 , 4 ) == ' #+fi' , " Original line should contain '#+fi'" )
444+ end )
445+ end )
0 commit comments