From fe35eebc3778983d3965fba9507779574d92ab7f Mon Sep 17 00:00:00 2001 From: vinsymoyya <186405436+vinsymoyya@users.noreply.github.com> Date: Sat, 14 Nov 2026 14:07:45 +0530 Subject: [PATCH 1/2] Continue long free-form directives on indented comment lines --- README.md | 10 +++++++ tests/test_directive_continuations.py | 40 +++++++++++++++++++++++++++ vimdoc/parser.py | 19 ++++++++++++- 3 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 tests/test_directive_continuations.py diff --git a/README.md b/README.md index eae3f59..885387e 100644 --- a/README.md +++ b/README.md @@ -163,6 +163,16 @@ Available block directives include: The global directives (@stylized, @order, and @library) are all detected from inside a @section block (usually the Introduction section). +Long `@throws`, `@order`, and `@tagline` directives can continue on comment +lines with four spaces of indentation after the usual comment leader: + +```viml +" @throws Ambiguous if {name} refers to multiple sources within one +" namespace. +``` + +An unindented comment starts a separate documentation line. + ### Inline Directives Inline directives occur in the body of comment blocks. Most take one argument diff --git a/tests/test_directive_continuations.py b/tests/test_directive_continuations.py new file mode 100644 index 0000000..6280e9e --- /dev/null +++ b/tests/test_directive_continuations.py @@ -0,0 +1,40 @@ +import unittest + +from vimdoc import paragraph +from vimdoc import parser + + +class TestDirectiveContinuations(unittest.TestCase): + + def test_throws_description_continues_with_four_spaces(self): + source = ['""', '" @throws Ambiguous if {name} refers to multiple sources within one', + '" namespace.', 'function! example#Find(name)'] + block, = parser.ParseBlocks(source, 'autoload/example.vim') + description, = [p.description for p in block.paragraphs + if isinstance(p, paragraph.ExceptionLine)] + self.assertEqual('if {name} refers to multiple sources within one namespace.', + description) + + def test_order_continues_across_multiple_lines(self): + parsed = list(parser.EnumerateParsedLines([ + '""', '" @order intro', '" commands', '" about'])) + self.assertEqual(['intro', 'commands', 'about'], parsed[0][1].order) + self.assertEqual(1, parsed[0][0]) + + def test_unindented_description_is_a_separate_paragraph(self): + source = ['""', '" @throws Example first.', '" Separate paragraph.', + 'function! example#Find()'] + block, = parser.ParseBlocks(source, 'autoload/example.vim') + self.assertEqual('first.', block.paragraphs[0].description) + self.assertEqual('Separate paragraph.', block.paragraphs[1].text) + + def test_tagline_joins_as_one_value(self): + parsed = list(parser.EnumerateParsedLines( + ['""', '" @tagline First part', '" second part'])) + self.assertEqual('First part second part', parsed[0][1].tagline) + + def test_usage_descriptions_are_not_joined_to_the_header(self): + parsed = list(parser.EnumerateParsedLines( + ['""', '" @usage {name}', '" Indented description.'])) + self.assertEqual(2, len(parsed)) + self.assertEqual(' Indented description.', parsed[1][1].line) diff --git a/vimdoc/parser.py b/vimdoc/parser.py index 66e9bdd..d9229cd 100644 --- a/vimdoc/parser.py +++ b/vimdoc/parser.py @@ -48,9 +48,26 @@ def EnumerateStripNewlinesAndJoinContinuations(lines): yield lineno, cached +def EnumerateJoinedDirectiveLines(lines): + """Joins four-space continuations of free-form block directives.""" + pending = None + for lineno, line in EnumerateStripNewlinesAndJoinContinuations(lines): + directive = regex.block_directive.match(pending[1]) if pending else None + body = regex.comment_leader.sub('', line) if IsComment(line) else None + if (directive and directive.group(1) in ('throws', 'tagline', 'order') + and body and body.startswith(' ') and body.strip()): + pending = (pending[0], pending[1] + ' ' + body.lstrip()) + else: + if pending is not None: + yield pending + pending = (lineno, line) + if pending is not None: + yield pending + + def EnumerateParsedLines(lines): vimdoc_mode = False - for i, line in EnumerateStripNewlinesAndJoinContinuations(lines): + for i, line in EnumerateJoinedDirectiveLines(lines): if not vimdoc_mode: if regex.vimdoc_leader.match(line): vimdoc_mode = True From 4dd6fab30609eae696b6144262e344f561dc66ad Mon Sep 17 00:00:00 2001 From: vinsymoyya <186405436+vinsymoyya@users.noreply.github.com> Date: Sat, 14 Nov 2026 14:50:04 +0530 Subject: [PATCH 2/2] Keep indented block directives separate from continuation text --- tests/test_directive_continuations.py | 15 +++++++++++++++ vimdoc/parser.py | 3 ++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/tests/test_directive_continuations.py b/tests/test_directive_continuations.py index 6280e9e..2a5028c 100644 --- a/tests/test_directive_continuations.py +++ b/tests/test_directive_continuations.py @@ -2,6 +2,7 @@ from vimdoc import paragraph from vimdoc import parser +from vimdoc import docline class TestDirectiveContinuations(unittest.TestCase): @@ -38,3 +39,17 @@ def test_usage_descriptions_are_not_joined_to_the_header(self): ['""', '" @usage {name}', '" Indented description.'])) self.assertEqual(2, len(parsed)) self.assertEqual(' Indented description.', parsed[1][1].line) + + def test_indented_block_directives_remain_separate(self): + cases = [ + ('@tagline First', '@section Introduction', docline.Section), + ('@throws Example first', '@default value=0', docline.Default), + ('@order intro', '@section Introduction', docline.Section), + ] + for first, second, expected_type in cases: + with self.subTest(first=first, second=second): + parsed = list(parser.EnumerateParsedLines( + ['""', '" ' + first, '" ' + second])) + self.assertEqual(2, len(parsed)) + self.assertIsInstance(parsed[1][1], expected_type) + self.assertEqual(2, parsed[1][0]) diff --git a/vimdoc/parser.py b/vimdoc/parser.py index d9229cd..fe2db7a 100644 --- a/vimdoc/parser.py +++ b/vimdoc/parser.py @@ -55,7 +55,8 @@ def EnumerateJoinedDirectiveLines(lines): directive = regex.block_directive.match(pending[1]) if pending else None body = regex.comment_leader.sub('', line) if IsComment(line) else None if (directive and directive.group(1) in ('throws', 'tagline', 'order') - and body and body.startswith(' ') and body.strip()): + and body and body.startswith(' ') and body.strip() + and not regex.block_directive.match(line)): pending = (pending[0], pending[1] + ' ' + body.lstrip()) else: if pending is not None: