2018-06-29 15:46:05 -07:00
|
|
|
#!/usr/bin/env python3
|
2019-12-24 01:04:14 -07:00
|
|
|
"""Generates Nvim :help docs from C/Lua docstrings, using Doxygen.
|
2019-12-19 20:42:24 -07:00
|
|
|
|
|
|
|
Also generates *.mpack files. To inspect the *.mpack structure:
|
|
|
|
|
2019-12-24 01:04:14 -07:00
|
|
|
:new | put=v:lua.vim.inspect(msgpackparse(readfile('runtime/doc/api.mpack')))
|
|
|
|
|
2019-12-19 20:42:24 -07:00
|
|
|
|
|
|
|
Flow:
|
2019-12-24 01:04:14 -07:00
|
|
|
main
|
2019-12-19 20:42:24 -07:00
|
|
|
extract_from_xml
|
2019-12-24 01:04:14 -07:00
|
|
|
fmt_node_as_vimhelp \
|
|
|
|
para_as_map } recursive
|
|
|
|
update_params_map /
|
|
|
|
render_node
|
2017-01-03 05:11:19 -07:00
|
|
|
|
|
|
|
This would be easier using lxml and XSLT, but:
|
|
|
|
|
|
|
|
1. This should avoid needing Python dependencies, especially ones that are
|
|
|
|
C modules that have library dependencies (lxml requires libxml and
|
|
|
|
libxslt).
|
|
|
|
2. I wouldn't know how to deal with nested indentation in <para> tags using
|
|
|
|
XSLT.
|
|
|
|
|
2019-11-17 23:49:28 -07:00
|
|
|
Each function :help block is formatted as follows:
|
2017-01-03 05:11:19 -07:00
|
|
|
|
2019-11-17 23:49:28 -07:00
|
|
|
- Max width of 78 columns (`text_width`).
|
|
|
|
- Indent with spaces (not tabs).
|
|
|
|
- Indent of 16 columns for body text.
|
|
|
|
- Function signature and helptag (right-aligned) on the same line.
|
2017-01-03 05:11:19 -07:00
|
|
|
- Signature and helptag must have a minimum of 8 spaces between them.
|
2019-11-17 23:49:28 -07:00
|
|
|
- If the signature is too long, it is placed on the line after the helptag.
|
|
|
|
Signature wraps at `text_width - 8` characters with subsequent
|
|
|
|
lines indented to the open parenthesis.
|
2017-01-03 05:11:19 -07:00
|
|
|
- Subsection bodies are indented an additional 4 spaces.
|
2019-11-17 23:49:28 -07:00
|
|
|
- Body consists of function description, parameters, return description, and
|
|
|
|
C declaration (`INCLUDE_C_DECL`).
|
2017-01-03 05:11:19 -07:00
|
|
|
- Parameters are omitted for the `void` and `Error *` types, or if the
|
|
|
|
parameter is marked as [out].
|
|
|
|
- Each function documentation is separated by a single line.
|
|
|
|
"""
|
2020-08-08 12:47:59 -07:00
|
|
|
import argparse
|
2017-01-03 05:11:19 -07:00
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import sys
|
|
|
|
import shutil
|
|
|
|
import textwrap
|
|
|
|
import subprocess
|
2019-03-03 07:01:16 -07:00
|
|
|
import collections
|
2019-10-26 12:54:54 -07:00
|
|
|
import msgpack
|
2017-01-03 05:11:19 -07:00
|
|
|
|
|
|
|
from xml.dom import minidom
|
|
|
|
|
2020-07-24 13:42:25 -07:00
|
|
|
MIN_PYTHON_VERSION = (3, 5)
|
|
|
|
|
|
|
|
if sys.version_info < MIN_PYTHON_VERSION:
|
|
|
|
print("requires Python {}.{}+".format(*MIN_PYTHON_VERSION))
|
2017-11-05 20:15:43 -07:00
|
|
|
sys.exit(1)
|
|
|
|
|
2019-03-03 07:01:16 -07:00
|
|
|
DEBUG = ('DEBUG' in os.environ)
|
|
|
|
INCLUDE_C_DECL = ('INCLUDE_C_DECL' in os.environ)
|
|
|
|
INCLUDE_DEPRECATED = ('INCLUDE_DEPRECATED' in os.environ)
|
|
|
|
|
2019-12-24 01:04:14 -07:00
|
|
|
fmt_vimhelp = False # HACK
|
2019-03-29 13:54:34 -07:00
|
|
|
text_width = 78
|
|
|
|
script_path = os.path.abspath(__file__)
|
|
|
|
base_dir = os.path.dirname(os.path.dirname(script_path))
|
2019-12-31 08:12:10 -07:00
|
|
|
out_dir = os.path.join(base_dir, 'tmp-{target}-doc')
|
2019-03-29 13:54:34 -07:00
|
|
|
filter_cmd = '%s %s' % (sys.executable, script_path)
|
|
|
|
seen_funcs = set()
|
2020-08-31 00:51:35 -07:00
|
|
|
msgs = [] # Messages to show on exit.
|
2019-03-29 13:54:34 -07:00
|
|
|
lua2dox_filter = os.path.join(base_dir, 'scripts', 'lua2dox_filter')
|
|
|
|
|
|
|
|
CONFIG = {
|
2019-07-28 19:43:28 -07:00
|
|
|
'api': {
|
2019-12-31 07:52:14 -07:00
|
|
|
'mode': 'c',
|
2019-07-28 19:43:28 -07:00
|
|
|
'filename': 'api.txt',
|
|
|
|
# String used to find the start of the generated part of the doc.
|
|
|
|
'section_start_token': '*api-global*',
|
|
|
|
# Section ordering.
|
|
|
|
'section_order': [
|
|
|
|
'vim.c',
|
|
|
|
'buffer.c',
|
|
|
|
'window.c',
|
|
|
|
'tabpage.c',
|
|
|
|
'ui.c',
|
|
|
|
],
|
|
|
|
# List of files/directories for doxygen to read, separated by blanks
|
|
|
|
'files': os.path.join(base_dir, 'src/nvim/api'),
|
|
|
|
# file patterns used by doxygen
|
|
|
|
'file_patterns': '*.h *.c',
|
|
|
|
# Only function with this prefix are considered
|
2019-12-31 07:52:14 -07:00
|
|
|
'fn_name_prefix': 'nvim_',
|
2019-07-28 19:43:28 -07:00
|
|
|
# Section name overrides.
|
|
|
|
'section_name': {
|
|
|
|
'vim.c': 'Global',
|
|
|
|
},
|
2019-12-31 07:52:14 -07:00
|
|
|
# For generated section names.
|
|
|
|
'section_fmt': lambda name: f'{name} Functions',
|
|
|
|
# Section helptag.
|
|
|
|
'helptag_fmt': lambda name: f'*api-{name.lower()}*',
|
|
|
|
# Per-function helptag.
|
|
|
|
'fn_helptag_fmt': lambda fstem, name: f'*{name}()*',
|
2019-07-28 19:43:28 -07:00
|
|
|
# Module name overrides (for Lua).
|
|
|
|
'module_override': {},
|
|
|
|
# Append the docs for these modules, do not start a new section.
|
|
|
|
'append_only': [],
|
2019-05-18 13:04:31 -07:00
|
|
|
},
|
2019-07-28 19:43:28 -07:00
|
|
|
'lua': {
|
2019-12-31 07:52:14 -07:00
|
|
|
'mode': 'lua',
|
2019-11-17 20:06:59 -07:00
|
|
|
'filename': 'lua.txt',
|
2019-07-28 19:43:28 -07:00
|
|
|
'section_start_token': '*lua-vim*',
|
|
|
|
'section_order': [
|
|
|
|
'vim.lua',
|
|
|
|
'shared.lua',
|
2020-09-14 06:12:17 -07:00
|
|
|
'uri.lua',
|
2019-07-28 19:43:28 -07:00
|
|
|
],
|
|
|
|
'files': ' '.join([
|
|
|
|
os.path.join(base_dir, 'src/nvim/lua/vim.lua'),
|
|
|
|
os.path.join(base_dir, 'runtime/lua/vim/shared.lua'),
|
2020-09-14 06:12:17 -07:00
|
|
|
os.path.join(base_dir, 'runtime/lua/vim/uri.lua'),
|
2019-05-18 13:04:31 -07:00
|
|
|
]),
|
2019-07-28 19:43:28 -07:00
|
|
|
'file_patterns': '*.lua',
|
2019-12-31 07:52:14 -07:00
|
|
|
'fn_name_prefix': '',
|
|
|
|
'section_name': {
|
|
|
|
'lsp.lua': 'core',
|
|
|
|
},
|
|
|
|
'section_fmt': lambda name: f'Lua module: {name.lower()}',
|
|
|
|
'helptag_fmt': lambda name: f'*lua-{name.lower()}*',
|
|
|
|
'fn_helptag_fmt': lambda fstem, name: f'*{fstem}.{name}()*',
|
2019-07-28 19:43:28 -07:00
|
|
|
'module_override': {
|
|
|
|
# `shared` functions are exposed on the `vim` module.
|
|
|
|
'shared': 'vim',
|
2020-09-14 06:12:17 -07:00
|
|
|
'uri': 'vim',
|
2019-07-28 19:43:28 -07:00
|
|
|
},
|
|
|
|
'append_only': [
|
|
|
|
'shared.lua',
|
|
|
|
],
|
2019-05-18 13:04:31 -07:00
|
|
|
},
|
2019-12-31 07:52:14 -07:00
|
|
|
'lsp': {
|
|
|
|
'mode': 'lua',
|
|
|
|
'filename': 'lsp.txt',
|
|
|
|
'section_start_token': '*lsp-core*',
|
|
|
|
'section_order': [
|
|
|
|
'lsp.lua',
|
|
|
|
'protocol.lua',
|
|
|
|
'buf.lua',
|
|
|
|
'callbacks.lua',
|
|
|
|
'log.lua',
|
|
|
|
'rpc.lua',
|
|
|
|
'util.lua'
|
|
|
|
],
|
|
|
|
'files': ' '.join([
|
|
|
|
os.path.join(base_dir, 'runtime/lua/vim/lsp'),
|
|
|
|
os.path.join(base_dir, 'runtime/lua/vim/lsp.lua'),
|
|
|
|
]),
|
|
|
|
'file_patterns': '*.lua',
|
|
|
|
'fn_name_prefix': '',
|
|
|
|
'section_name': {},
|
2019-12-31 08:12:10 -07:00
|
|
|
'section_fmt': lambda name: (
|
|
|
|
'Lua module: vim.lsp'
|
2019-12-31 07:52:14 -07:00
|
|
|
if name.lower() == 'lsp'
|
|
|
|
else f'Lua module: vim.lsp.{name.lower()}'),
|
2019-12-31 08:12:10 -07:00
|
|
|
'helptag_fmt': lambda name: (
|
|
|
|
'*lsp-core*'
|
2019-12-31 07:52:14 -07:00
|
|
|
if name.lower() == 'lsp'
|
|
|
|
else f'*lsp-{name.lower()}*'),
|
2019-12-31 08:12:10 -07:00
|
|
|
'fn_helptag_fmt': lambda fstem, name: (
|
|
|
|
f'*vim.lsp.{name}()*'
|
2019-12-31 07:52:14 -07:00
|
|
|
if fstem == 'lsp' and name != 'client'
|
2019-12-31 08:12:10 -07:00
|
|
|
else (
|
|
|
|
'*vim.lsp.client*'
|
2019-12-31 07:52:14 -07:00
|
|
|
# HACK. TODO(justinmk): class/structure support in lua2dox
|
|
|
|
if 'lsp.client' == f'{fstem}.{name}'
|
|
|
|
else f'*vim.lsp.{fstem}.{name}()*')),
|
2020-01-13 00:41:55 -07:00
|
|
|
'module_override': {},
|
2019-12-31 07:52:14 -07:00
|
|
|
'append_only': [],
|
|
|
|
},
|
2017-01-03 05:11:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
param_exclude = (
|
|
|
|
'channel_id',
|
|
|
|
)
|
|
|
|
|
2017-03-01 09:55:34 -07:00
|
|
|
# Annotations are displayed as line items after API function descriptions.
|
|
|
|
annotation_map = {
|
2019-08-25 16:01:01 -07:00
|
|
|
'FUNC_API_FAST': '{fast}',
|
2017-03-01 09:55:34 -07:00
|
|
|
}
|
|
|
|
|
2017-01-03 05:11:19 -07:00
|
|
|
|
|
|
|
# Tracks `xrefsect` titles. As of this writing, used only for separating
|
|
|
|
# deprecated functions.
|
|
|
|
xrefs = set()
|
|
|
|
|
2019-07-28 19:43:28 -07:00
|
|
|
|
2019-11-17 23:49:28 -07:00
|
|
|
# Raises an error with details about `o`, if `cond` is in object `o`,
|
|
|
|
# or if `cond()` is callable and returns True.
|
2020-08-31 00:51:35 -07:00
|
|
|
def debug_this(o, cond=True):
|
2019-11-17 23:49:28 -07:00
|
|
|
name = ''
|
|
|
|
if not isinstance(o, str):
|
|
|
|
try:
|
|
|
|
name = o.nodeName
|
|
|
|
o = o.toprettyxml(indent=' ', newl='\n')
|
2019-12-22 23:08:49 -07:00
|
|
|
except Exception:
|
2019-11-17 23:49:28 -07:00
|
|
|
pass
|
|
|
|
if ((callable(cond) and cond())
|
2019-12-28 04:27:25 -07:00
|
|
|
or (not callable(cond) and cond)
|
2019-11-17 23:49:28 -07:00
|
|
|
or (not callable(cond) and cond in o)):
|
2019-03-03 07:01:16 -07:00
|
|
|
raise RuntimeError('xxx: {}\n{}'.format(name, o))
|
|
|
|
|
2017-01-03 05:11:19 -07:00
|
|
|
|
2020-08-31 00:51:35 -07:00
|
|
|
# Appends a message to a list which will be printed on exit.
|
|
|
|
def msg(s):
|
|
|
|
msgs.append(s)
|
|
|
|
|
|
|
|
|
|
|
|
# Print all collected messages.
|
|
|
|
def msg_report():
|
|
|
|
for m in msgs:
|
|
|
|
print(f' {m}')
|
|
|
|
|
|
|
|
|
|
|
|
# Print collected messages, then throw an exception.
|
|
|
|
def fail(s):
|
|
|
|
msg_report()
|
|
|
|
raise RuntimeError(s)
|
|
|
|
|
|
|
|
|
2017-01-03 05:11:19 -07:00
|
|
|
def find_first(parent, name):
|
|
|
|
"""Finds the first matching node within parent."""
|
|
|
|
sub = parent.getElementsByTagName(name)
|
|
|
|
if not sub:
|
|
|
|
return None
|
|
|
|
return sub[0]
|
|
|
|
|
|
|
|
|
2019-12-24 01:04:14 -07:00
|
|
|
def iter_children(parent, name):
|
|
|
|
"""Yields matching child nodes within parent."""
|
2017-01-03 05:11:19 -07:00
|
|
|
for child in parent.childNodes:
|
|
|
|
if child.nodeType == child.ELEMENT_NODE and child.nodeName == name:
|
|
|
|
yield child
|
|
|
|
|
|
|
|
|
|
|
|
def get_child(parent, name):
|
2019-12-24 01:04:14 -07:00
|
|
|
"""Gets the first matching child node."""
|
|
|
|
for child in iter_children(parent, name):
|
2017-01-03 05:11:19 -07:00
|
|
|
return child
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
2019-12-24 01:04:14 -07:00
|
|
|
def self_or_child(n):
|
|
|
|
"""Gets the first child node, or self."""
|
|
|
|
if len(n.childNodes) == 0:
|
|
|
|
return n
|
|
|
|
return n.childNodes[0]
|
|
|
|
|
|
|
|
|
2017-01-03 05:11:19 -07:00
|
|
|
def clean_text(text):
|
|
|
|
"""Cleans text.
|
|
|
|
|
|
|
|
Only cleans superfluous whitespace at the moment.
|
|
|
|
"""
|
|
|
|
return ' '.join(text.split()).strip()
|
|
|
|
|
|
|
|
|
|
|
|
def clean_lines(text):
|
|
|
|
"""Removes superfluous lines.
|
|
|
|
|
|
|
|
The beginning and end of the string is trimmed. Empty lines are collapsed.
|
|
|
|
"""
|
|
|
|
return re.sub(r'\A\n\s*\n*|\n\s*\n*\Z', '', re.sub(r'(\n\s*\n+)+', '\n\n', text))
|
|
|
|
|
|
|
|
|
2019-03-03 07:01:16 -07:00
|
|
|
def is_blank(text):
|
|
|
|
return '' == clean_lines(text)
|
|
|
|
|
|
|
|
|
2019-12-24 01:04:14 -07:00
|
|
|
def get_text(n, preformatted=False):
|
|
|
|
"""Recursively concatenates all text in a node tree."""
|
|
|
|
text = ''
|
|
|
|
if n.nodeType == n.TEXT_NODE:
|
|
|
|
return n.data
|
|
|
|
if n.nodeName == 'computeroutput':
|
|
|
|
for node in n.childNodes:
|
|
|
|
text += get_text(node)
|
|
|
|
return '`{}` '.format(text)
|
|
|
|
for node in n.childNodes:
|
2017-01-03 05:11:19 -07:00
|
|
|
if node.nodeType == node.TEXT_NODE:
|
2019-12-24 01:04:14 -07:00
|
|
|
text += node.data if preformatted else clean_text(node.data)
|
2017-01-03 05:11:19 -07:00
|
|
|
elif node.nodeType == node.ELEMENT_NODE:
|
2019-12-24 01:04:14 -07:00
|
|
|
text += ' ' + get_text(node, preformatted)
|
|
|
|
return text
|
2017-01-03 05:11:19 -07:00
|
|
|
|
|
|
|
|
2019-03-03 07:01:16 -07:00
|
|
|
# Gets the length of the last line in `text`, excluding newline ("\n") char.
|
|
|
|
def len_lastline(text):
|
|
|
|
lastnl = text.rfind('\n')
|
|
|
|
if -1 == lastnl:
|
|
|
|
return len(text)
|
|
|
|
if '\n' == text[-1]:
|
2019-07-28 19:43:28 -07:00
|
|
|
return lastnl - (1 + text.rfind('\n', 0, lastnl))
|
2019-03-03 07:01:16 -07:00
|
|
|
return len(text) - (1 + lastnl)
|
|
|
|
|
|
|
|
|
|
|
|
def len_lastline_withoutindent(text, indent):
|
|
|
|
n = len_lastline(text)
|
|
|
|
return (n - len(indent)) if n > len(indent) else 0
|
|
|
|
|
|
|
|
|
|
|
|
# Returns True if node `n` contains only inline (not block-level) elements.
|
|
|
|
def is_inline(n):
|
2019-12-24 01:04:14 -07:00
|
|
|
# if len(n.childNodes) == 0:
|
|
|
|
# return n.nodeType == n.TEXT_NODE or n.nodeName == 'computeroutput'
|
2019-03-03 07:01:16 -07:00
|
|
|
for c in n.childNodes:
|
|
|
|
if c.nodeType != c.TEXT_NODE and c.nodeName != 'computeroutput':
|
|
|
|
return False
|
|
|
|
if not is_inline(c):
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
2019-07-28 19:43:28 -07:00
|
|
|
|
2019-03-03 07:01:16 -07:00
|
|
|
def doc_wrap(text, prefix='', width=70, func=False, indent=None):
|
2017-01-03 05:11:19 -07:00
|
|
|
"""Wraps text to `width`.
|
|
|
|
|
2019-03-03 07:01:16 -07:00
|
|
|
First line is prefixed with `prefix`, subsequent lines are aligned.
|
2017-01-03 05:11:19 -07:00
|
|
|
If `func` is True, only wrap at commas.
|
|
|
|
"""
|
|
|
|
if not width:
|
2019-03-03 07:01:16 -07:00
|
|
|
# return prefix + text
|
2017-01-03 05:11:19 -07:00
|
|
|
return text
|
|
|
|
|
2019-03-03 07:01:16 -07:00
|
|
|
# Whitespace used to indent all lines except the first line.
|
|
|
|
indent = ' ' * len(prefix) if indent is None else indent
|
|
|
|
indent_only = (prefix == '' and indent is not None)
|
2017-01-03 05:11:19 -07:00
|
|
|
|
|
|
|
if func:
|
|
|
|
lines = [prefix]
|
|
|
|
for part in text.split(', '):
|
|
|
|
if part[-1] not in ');':
|
|
|
|
part += ', '
|
|
|
|
if len(lines[-1]) + len(part) > width:
|
2019-03-03 07:01:16 -07:00
|
|
|
lines.append(indent)
|
2017-01-03 05:11:19 -07:00
|
|
|
lines[-1] += part
|
|
|
|
return '\n'.join(x.rstrip() for x in lines).rstrip()
|
|
|
|
|
2019-03-03 07:01:16 -07:00
|
|
|
# XXX: Dummy prefix to force TextWrapper() to wrap the first line.
|
|
|
|
if indent_only:
|
|
|
|
prefix = indent
|
|
|
|
|
2019-07-28 19:43:28 -07:00
|
|
|
tw = textwrap.TextWrapper(break_long_words=False,
|
|
|
|
break_on_hyphens=False,
|
2019-01-26 12:10:59 -07:00
|
|
|
width=width,
|
|
|
|
initial_indent=prefix,
|
2019-03-03 07:01:16 -07:00
|
|
|
subsequent_indent=indent)
|
|
|
|
result = '\n'.join(tw.wrap(text.strip()))
|
|
|
|
|
|
|
|
# XXX: Remove the dummy prefix.
|
|
|
|
if indent_only:
|
|
|
|
result = result[len(indent):]
|
|
|
|
|
|
|
|
return result
|
2017-01-03 05:11:19 -07:00
|
|
|
|
|
|
|
|
2019-12-24 01:04:14 -07:00
|
|
|
def max_name(names):
|
|
|
|
if len(names) == 0:
|
|
|
|
return 0
|
|
|
|
return max(len(name) for name in names)
|
|
|
|
|
|
|
|
|
2019-11-17 23:49:28 -07:00
|
|
|
def update_params_map(parent, ret_map, width=62):
|
|
|
|
"""Updates `ret_map` with name:desc key-value pairs extracted
|
2019-12-19 20:42:24 -07:00
|
|
|
from Doxygen XML node `parent`.
|
2019-11-17 23:49:28 -07:00
|
|
|
"""
|
2019-12-24 01:04:14 -07:00
|
|
|
params = collections.OrderedDict()
|
2019-03-03 07:01:16 -07:00
|
|
|
for node in parent.childNodes:
|
|
|
|
if node.nodeType == node.TEXT_NODE:
|
2017-01-03 05:11:19 -07:00
|
|
|
continue
|
2019-03-03 07:01:16 -07:00
|
|
|
name_node = find_first(node, 'parametername')
|
2017-01-03 05:11:19 -07:00
|
|
|
if name_node.getAttribute('direction') == 'out':
|
|
|
|
continue
|
|
|
|
name = get_text(name_node)
|
|
|
|
if name in param_exclude:
|
|
|
|
continue
|
2019-12-24 01:04:14 -07:00
|
|
|
params[name.strip()] = node
|
|
|
|
max_name_len = max_name(params.keys()) + 8
|
2019-11-17 23:49:28 -07:00
|
|
|
# `ret_map` is a name:desc map.
|
2019-12-24 01:04:14 -07:00
|
|
|
for name, node in params.items():
|
2017-01-03 05:11:19 -07:00
|
|
|
desc = ''
|
2019-03-03 07:01:16 -07:00
|
|
|
desc_node = get_child(node, 'parameterdescription')
|
2017-01-03 05:11:19 -07:00
|
|
|
if desc_node:
|
2019-12-28 04:27:25 -07:00
|
|
|
desc = fmt_node_as_vimhelp(
|
|
|
|
desc_node, width=width, indent=(' ' * max_name_len))
|
2019-11-17 23:49:28 -07:00
|
|
|
ret_map[name] = desc
|
|
|
|
return ret_map
|
[scripts/gen_vimdoc.py] Generate better-formatted mpack
Changes the generated msgpack result values in the runtime/doc/*.mpack
files to be formatted like this (instead of being formatted like Vim help text):
[
'nvim_win_get_var': {
'signature': 'nvim_win_get_var({window}, {name}, {err})',
'parameters': [('Window', 'window'), ('String', 'name'), ('Error *', 'err')],
'parameters_doc': [{'window': 'Window handle, or 0 for current window', 'name': 'Variable name'}],
'doc': ['Gets a window-scoped (w:) variable'],
'return': ['Variable value'],
'seealso': []
}
},
...
]
2019-11-06 15:22:20 -07:00
|
|
|
|
2019-03-03 07:01:16 -07:00
|
|
|
|
|
|
|
def render_node(n, text, prefix='', indent='', width=62):
|
2019-07-28 19:43:49 -07:00
|
|
|
"""Renders a node as Vim help text, recursively traversing all descendants."""
|
2019-12-24 01:04:14 -07:00
|
|
|
global fmt_vimhelp
|
2020-07-02 04:09:17 -07:00
|
|
|
global has_seen_preformatted
|
2019-12-28 04:27:25 -07:00
|
|
|
|
2019-12-24 01:04:14 -07:00
|
|
|
def ind(s):
|
|
|
|
return s if fmt_vimhelp else ''
|
2019-12-28 04:27:25 -07:00
|
|
|
|
2019-03-03 07:01:16 -07:00
|
|
|
text = ''
|
|
|
|
# space_preceding = (len(text) > 0 and ' ' == text[-1][-1])
|
|
|
|
# text += (int(not space_preceding) * ' ')
|
|
|
|
|
2019-12-24 01:04:14 -07:00
|
|
|
if n.nodeName == 'preformatted':
|
2019-04-27 09:25:55 -07:00
|
|
|
o = get_text(n, preformatted=True)
|
|
|
|
ensure_nl = '' if o[-1] == '\n' else '\n'
|
2019-12-24 01:04:14 -07:00
|
|
|
text += '>{}{}\n<'.format(ensure_nl, o)
|
2020-07-02 04:09:17 -07:00
|
|
|
|
2019-03-03 07:01:16 -07:00
|
|
|
elif is_inline(n):
|
2019-12-24 01:04:14 -07:00
|
|
|
text = doc_wrap(get_text(n), indent=indent, width=width)
|
2019-03-03 07:01:16 -07:00
|
|
|
elif n.nodeName == 'verbatim':
|
|
|
|
# TODO: currently we don't use this. The "[verbatim]" hint is there as
|
|
|
|
# a reminder that we must decide how to format this if we do use it.
|
|
|
|
text += ' [verbatim] {}'.format(get_text(n))
|
|
|
|
elif n.nodeName == 'listitem':
|
|
|
|
for c in n.childNodes:
|
2020-07-02 04:09:17 -07:00
|
|
|
result = render_node(
|
|
|
|
c,
|
|
|
|
text,
|
|
|
|
indent=indent + (' ' * len(prefix)),
|
|
|
|
width=width
|
2019-07-28 19:43:49 -07:00
|
|
|
)
|
2020-07-02 04:09:17 -07:00
|
|
|
|
|
|
|
if is_blank(result):
|
|
|
|
continue
|
|
|
|
|
|
|
|
text += indent + prefix + result
|
2019-05-18 13:04:31 -07:00
|
|
|
elif n.nodeName in ('para', 'heading'):
|
2019-03-03 07:01:16 -07:00
|
|
|
for c in n.childNodes:
|
|
|
|
text += render_node(c, text, indent=indent, width=width)
|
|
|
|
elif n.nodeName == 'itemizedlist':
|
|
|
|
for c in n.childNodes:
|
2019-05-25 01:00:41 -07:00
|
|
|
text += '{}\n'.format(render_node(c, text, prefix='• ',
|
2019-07-28 19:43:28 -07:00
|
|
|
indent=indent, width=width))
|
2019-03-03 07:01:16 -07:00
|
|
|
elif n.nodeName == 'orderedlist':
|
|
|
|
i = 1
|
|
|
|
for c in n.childNodes:
|
|
|
|
if is_blank(get_text(c)):
|
|
|
|
text += '\n'
|
|
|
|
continue
|
|
|
|
text += '{}\n'.format(render_node(c, text, prefix='{}. '.format(i),
|
2019-07-28 19:43:28 -07:00
|
|
|
indent=indent, width=width))
|
2019-03-03 07:01:16 -07:00
|
|
|
i = i + 1
|
|
|
|
elif n.nodeName == 'simplesect' and 'note' == n.getAttribute('kind'):
|
|
|
|
text += 'Note:\n '
|
|
|
|
for c in n.childNodes:
|
|
|
|
text += render_node(c, text, indent=' ', width=width)
|
|
|
|
text += '\n'
|
|
|
|
elif n.nodeName == 'simplesect' and 'warning' == n.getAttribute('kind'):
|
|
|
|
text += 'Warning:\n '
|
|
|
|
for c in n.childNodes:
|
|
|
|
text += render_node(c, text, indent=' ', width=width)
|
|
|
|
text += '\n'
|
|
|
|
elif (n.nodeName == 'simplesect'
|
|
|
|
and n.getAttribute('kind') in ('return', 'see')):
|
2019-12-24 01:04:14 -07:00
|
|
|
text += ind(' ')
|
2019-03-03 07:01:16 -07:00
|
|
|
for c in n.childNodes:
|
|
|
|
text += render_node(c, text, indent=' ', width=width)
|
|
|
|
else:
|
|
|
|
raise RuntimeError('unhandled node type: {}\n{}'.format(
|
|
|
|
n.nodeName, n.toprettyxml(indent=' ', newl='\n')))
|
2020-07-02 04:09:17 -07:00
|
|
|
|
2019-03-03 07:01:16 -07:00
|
|
|
return text
|
2017-01-03 05:11:19 -07:00
|
|
|
|
2019-07-28 19:43:28 -07:00
|
|
|
|
[scripts/gen_vimdoc.py] Generate better-formatted mpack
Changes the generated msgpack result values in the runtime/doc/*.mpack
files to be formatted like this (instead of being formatted like Vim help text):
[
'nvim_win_get_var': {
'signature': 'nvim_win_get_var({window}, {name}, {err})',
'parameters': [('Window', 'window'), ('String', 'name'), ('Error *', 'err')],
'parameters_doc': [{'window': 'Window handle, or 0 for current window', 'name': 'Variable name'}],
'doc': ['Gets a window-scoped (w:) variable'],
'return': ['Variable value'],
'seealso': []
}
},
...
]
2019-11-06 15:22:20 -07:00
|
|
|
def para_as_map(parent, indent='', width=62):
|
2019-11-17 23:49:28 -07:00
|
|
|
"""Extracts a Doxygen XML <para> node to a map.
|
2017-01-03 05:11:19 -07:00
|
|
|
|
2019-11-17 23:49:28 -07:00
|
|
|
Keys:
|
|
|
|
'text': Text from this <para> element
|
|
|
|
'params': <parameterlist> map
|
|
|
|
'return': List of @return strings
|
|
|
|
'seealso': List of @see strings
|
|
|
|
'xrefs': ?
|
2017-01-03 05:11:19 -07:00
|
|
|
"""
|
2019-11-17 23:49:28 -07:00
|
|
|
chunks = {
|
|
|
|
'text': '',
|
|
|
|
'params': collections.OrderedDict(),
|
|
|
|
'return': [],
|
|
|
|
'seealso': [],
|
|
|
|
'xrefs': []
|
|
|
|
}
|
|
|
|
|
2019-03-03 07:01:16 -07:00
|
|
|
# Ordered dict of ordered lists.
|
|
|
|
groups = collections.OrderedDict([
|
|
|
|
('params', []),
|
|
|
|
('return', []),
|
|
|
|
('seealso', []),
|
|
|
|
('xrefs', []),
|
|
|
|
])
|
|
|
|
|
|
|
|
# Gather nodes into groups. Mostly this is because we want "parameterlist"
|
|
|
|
# nodes to appear together.
|
|
|
|
text = ''
|
|
|
|
kind = ''
|
|
|
|
last = ''
|
2019-12-24 01:04:14 -07:00
|
|
|
if is_inline(parent):
|
|
|
|
# Flatten inline text from a tree of non-block nodes.
|
|
|
|
text = doc_wrap(render_node(parent, ""), indent=indent, width=width)
|
|
|
|
else:
|
|
|
|
prev = None # Previous node
|
|
|
|
for child in parent.childNodes:
|
|
|
|
if child.nodeName == 'parameterlist':
|
|
|
|
groups['params'].append(child)
|
|
|
|
elif child.nodeName == 'xrefsect':
|
|
|
|
groups['xrefs'].append(child)
|
|
|
|
elif child.nodeName == 'simplesect':
|
|
|
|
last = kind
|
|
|
|
kind = child.getAttribute('kind')
|
|
|
|
if kind == 'return' or (kind == 'note' and last == 'return'):
|
|
|
|
groups['return'].append(child)
|
|
|
|
elif kind == 'see':
|
|
|
|
groups['seealso'].append(child)
|
|
|
|
elif kind in ('note', 'warning'):
|
|
|
|
text += render_node(child, text, indent=indent, width=width)
|
|
|
|
else:
|
|
|
|
raise RuntimeError('unhandled simplesect: {}\n{}'.format(
|
|
|
|
child.nodeName, child.toprettyxml(indent=' ', newl='\n')))
|
2017-01-03 05:11:19 -07:00
|
|
|
else:
|
2019-12-24 01:04:14 -07:00
|
|
|
if (prev is not None
|
|
|
|
and is_inline(self_or_child(prev))
|
|
|
|
and is_inline(self_or_child(child))
|
|
|
|
and '' != get_text(self_or_child(child)).strip()
|
|
|
|
and ' ' != text[-1]):
|
|
|
|
text += ' '
|
2020-07-02 04:09:17 -07:00
|
|
|
|
2019-12-24 01:04:14 -07:00
|
|
|
text += render_node(child, text, indent=indent, width=width)
|
|
|
|
prev = child
|
2019-03-03 07:01:16 -07:00
|
|
|
|
2019-12-24 01:04:14 -07:00
|
|
|
chunks['text'] += text
|
[scripts/gen_vimdoc.py] Generate better-formatted mpack
Changes the generated msgpack result values in the runtime/doc/*.mpack
files to be formatted like this (instead of being formatted like Vim help text):
[
'nvim_win_get_var': {
'signature': 'nvim_win_get_var({window}, {name}, {err})',
'parameters': [('Window', 'window'), ('String', 'name'), ('Error *', 'err')],
'parameters_doc': [{'window': 'Window handle, or 0 for current window', 'name': 'Variable name'}],
'doc': ['Gets a window-scoped (w:) variable'],
'return': ['Variable value'],
'seealso': []
}
},
...
]
2019-11-06 15:22:20 -07:00
|
|
|
|
2019-11-17 23:49:28 -07:00
|
|
|
# Generate map from the gathered items.
|
|
|
|
if len(groups['params']) > 0:
|
2019-03-03 07:01:16 -07:00
|
|
|
for child in groups['params']:
|
2019-11-17 23:49:28 -07:00
|
|
|
update_params_map(child, ret_map=chunks['params'], width=width)
|
|
|
|
for child in groups['return']:
|
|
|
|
chunks['return'].append(render_node(
|
2019-12-24 01:04:14 -07:00
|
|
|
child, '', indent=indent, width=width))
|
2019-11-17 23:49:28 -07:00
|
|
|
for child in groups['seealso']:
|
|
|
|
chunks['seealso'].append(render_node(
|
|
|
|
child, '', indent=indent, width=width))
|
2019-03-03 07:01:16 -07:00
|
|
|
for child in groups['xrefs']:
|
2019-12-19 18:48:40 -07:00
|
|
|
# XXX: Add a space (or any char) to `title` here, otherwise xrefs
|
|
|
|
# ("Deprecated" section) acts very weird...
|
|
|
|
title = get_text(get_child(child, 'xreftitle')) + ' '
|
2019-03-03 07:01:16 -07:00
|
|
|
xrefs.add(title)
|
2019-12-19 18:48:40 -07:00
|
|
|
xrefdesc = get_text(get_child(child, 'xrefdescription'))
|
[scripts/gen_vimdoc.py] Generate better-formatted mpack
Changes the generated msgpack result values in the runtime/doc/*.mpack
files to be formatted like this (instead of being formatted like Vim help text):
[
'nvim_win_get_var': {
'signature': 'nvim_win_get_var({window}, {name}, {err})',
'parameters': [('Window', 'window'), ('String', 'name'), ('Error *', 'err')],
'parameters_doc': [{'window': 'Window handle, or 0 for current window', 'name': 'Variable name'}],
'doc': ['Gets a window-scoped (w:) variable'],
'return': ['Variable value'],
'seealso': []
}
},
...
]
2019-11-06 15:22:20 -07:00
|
|
|
chunks['xrefs'].append(doc_wrap(xrefdesc, prefix='{}: '.format(title),
|
|
|
|
width=width) + '\n')
|
2017-01-03 05:11:19 -07:00
|
|
|
|
[scripts/gen_vimdoc.py] Generate better-formatted mpack
Changes the generated msgpack result values in the runtime/doc/*.mpack
files to be formatted like this (instead of being formatted like Vim help text):
[
'nvim_win_get_var': {
'signature': 'nvim_win_get_var({window}, {name}, {err})',
'parameters': [('Window', 'window'), ('String', 'name'), ('Error *', 'err')],
'parameters_doc': [{'window': 'Window handle, or 0 for current window', 'name': 'Variable name'}],
'doc': ['Gets a window-scoped (w:) variable'],
'return': ['Variable value'],
'seealso': []
}
},
...
]
2019-11-06 15:22:20 -07:00
|
|
|
return chunks
|
2017-01-03 05:11:19 -07:00
|
|
|
|
|
|
|
|
2019-12-19 20:42:24 -07:00
|
|
|
def fmt_node_as_vimhelp(parent, width=62, indent=''):
|
|
|
|
"""Renders (nested) Doxygen <para> nodes as Vim :help text.
|
2017-01-03 05:11:19 -07:00
|
|
|
|
2019-03-03 07:01:16 -07:00
|
|
|
NB: Blank lines in a docstring manifest as <para> tags.
|
2017-01-03 05:11:19 -07:00
|
|
|
"""
|
2019-12-19 20:42:24 -07:00
|
|
|
rendered_blocks = []
|
2019-12-24 01:04:14 -07:00
|
|
|
|
|
|
|
def fmt_param_doc(m):
|
|
|
|
"""Renders a params map as Vim :help text."""
|
|
|
|
max_name_len = max_name(m.keys()) + 4
|
|
|
|
out = ''
|
|
|
|
for name, desc in m.items():
|
|
|
|
name = ' {}'.format('{{{}}}'.format(name).ljust(max_name_len))
|
|
|
|
out += '{}{}\n'.format(name, desc)
|
|
|
|
return out.rstrip()
|
|
|
|
|
|
|
|
def has_nonexcluded_params(m):
|
|
|
|
"""Returns true if any of the given params has at least
|
|
|
|
one non-excluded item."""
|
|
|
|
if fmt_param_doc(m) != '':
|
|
|
|
return True
|
|
|
|
|
2019-12-19 20:42:24 -07:00
|
|
|
for child in parent.childNodes:
|
|
|
|
para = para_as_map(child, indent, width)
|
|
|
|
|
|
|
|
# Generate text from the gathered items.
|
|
|
|
chunks = [para['text']]
|
|
|
|
if len(para['params']) > 0 and has_nonexcluded_params(para['params']):
|
|
|
|
chunks.append('\nParameters: ~')
|
2019-12-24 01:04:14 -07:00
|
|
|
chunks.append(fmt_param_doc(para['params']))
|
2019-12-19 20:42:24 -07:00
|
|
|
if len(para['return']) > 0:
|
|
|
|
chunks.append('\nReturn: ~')
|
|
|
|
for s in para['return']:
|
|
|
|
chunks.append(s)
|
|
|
|
if len(para['seealso']) > 0:
|
|
|
|
chunks.append('\nSee also: ~')
|
|
|
|
for s in para['seealso']:
|
|
|
|
chunks.append(s)
|
|
|
|
for s in para['xrefs']:
|
2019-11-17 23:49:28 -07:00
|
|
|
chunks.append(s)
|
2019-03-03 07:01:16 -07:00
|
|
|
|
2019-12-19 20:42:24 -07:00
|
|
|
rendered_blocks.append(clean_lines('\n'.join(chunks).strip()))
|
|
|
|
rendered_blocks.append('')
|
2020-07-02 04:09:17 -07:00
|
|
|
|
2019-12-19 20:42:24 -07:00
|
|
|
return clean_lines('\n'.join(rendered_blocks).strip())
|
2017-01-03 05:11:19 -07:00
|
|
|
|
|
|
|
|
2019-12-31 08:12:10 -07:00
|
|
|
def extract_from_xml(filename, target, width):
|
2019-11-17 23:49:28 -07:00
|
|
|
"""Extracts Doxygen info as maps without formatting the text.
|
[scripts/gen_vimdoc.py] Generate better-formatted mpack
Changes the generated msgpack result values in the runtime/doc/*.mpack
files to be formatted like this (instead of being formatted like Vim help text):
[
'nvim_win_get_var': {
'signature': 'nvim_win_get_var({window}, {name}, {err})',
'parameters': [('Window', 'window'), ('String', 'name'), ('Error *', 'err')],
'parameters_doc': [{'window': 'Window handle, or 0 for current window', 'name': 'Variable name'}],
'doc': ['Gets a window-scoped (w:) variable'],
'return': ['Variable value'],
'seealso': []
}
},
...
]
2019-11-06 15:22:20 -07:00
|
|
|
|
|
|
|
Returns two maps:
|
2019-11-17 23:49:28 -07:00
|
|
|
1. Functions
|
|
|
|
2. Deprecated functions
|
[scripts/gen_vimdoc.py] Generate better-formatted mpack
Changes the generated msgpack result values in the runtime/doc/*.mpack
files to be formatted like this (instead of being formatted like Vim help text):
[
'nvim_win_get_var': {
'signature': 'nvim_win_get_var({window}, {name}, {err})',
'parameters': [('Window', 'window'), ('String', 'name'), ('Error *', 'err')],
'parameters_doc': [{'window': 'Window handle, or 0 for current window', 'name': 'Variable name'}],
'doc': ['Gets a window-scoped (w:) variable'],
'return': ['Variable value'],
'seealso': []
}
},
...
]
2019-11-06 15:22:20 -07:00
|
|
|
|
2019-12-24 01:04:14 -07:00
|
|
|
The `fmt_vimhelp` global controls some special cases for use by
|
2019-11-17 23:49:28 -07:00
|
|
|
fmt_doxygen_xml_as_vimhelp(). (TODO: ugly :)
|
2017-01-03 05:11:19 -07:00
|
|
|
"""
|
|
|
|
global xrefs
|
2019-12-24 01:04:14 -07:00
|
|
|
global fmt_vimhelp
|
2019-12-19 18:48:40 -07:00
|
|
|
xrefs.clear()
|
2019-12-24 01:04:14 -07:00
|
|
|
fns = {} # Map of func_name:docstring.
|
|
|
|
deprecated_fns = {} # Map of func_name:docstring.
|
2017-01-03 05:11:19 -07:00
|
|
|
|
|
|
|
dom = minidom.parse(filename)
|
2019-03-29 13:54:34 -07:00
|
|
|
compoundname = get_text(dom.getElementsByTagName('compoundname')[0])
|
2017-01-03 05:11:19 -07:00
|
|
|
for member in dom.getElementsByTagName('memberdef'):
|
|
|
|
if member.getAttribute('static') == 'yes' or \
|
2019-03-29 13:54:34 -07:00
|
|
|
member.getAttribute('kind') != 'function' or \
|
|
|
|
member.getAttribute('prot') == 'private' or \
|
|
|
|
get_text(get_child(member, 'name')).startswith('_'):
|
2017-01-03 05:11:19 -07:00
|
|
|
continue
|
|
|
|
|
|
|
|
loc = find_first(member, 'location')
|
|
|
|
if 'private' in loc.getAttribute('file'):
|
|
|
|
continue
|
|
|
|
|
|
|
|
return_type = get_text(get_child(member, 'type'))
|
|
|
|
if return_type == '':
|
|
|
|
continue
|
|
|
|
|
|
|
|
if return_type.startswith(('ArrayOf', 'DictionaryOf')):
|
|
|
|
parts = return_type.strip('_').split('_')
|
2019-03-03 07:01:16 -07:00
|
|
|
return_type = '{}({})'.format(parts[0], ', '.join(parts[1:]))
|
2017-01-03 05:11:19 -07:00
|
|
|
|
2017-11-05 20:15:43 -07:00
|
|
|
name = get_text(get_child(member, 'name'))
|
|
|
|
|
2017-03-01 09:55:34 -07:00
|
|
|
annotations = get_text(get_child(member, 'argsstring'))
|
|
|
|
if annotations and ')' in annotations:
|
|
|
|
annotations = annotations.rsplit(')', 1)[-1].strip()
|
2017-12-09 17:30:05 -07:00
|
|
|
# XXX: (doxygen 1.8.11) 'argsstring' only includes attributes of
|
|
|
|
# non-void functions. Special-case void functions here.
|
2017-11-05 20:15:43 -07:00
|
|
|
if name == 'nvim_get_mode' and len(annotations) == 0:
|
2019-08-25 16:01:01 -07:00
|
|
|
annotations += 'FUNC_API_FAST'
|
2017-03-01 09:55:34 -07:00
|
|
|
annotations = filter(None, map(lambda x: annotation_map.get(x),
|
|
|
|
annotations.split()))
|
|
|
|
|
2019-11-17 23:49:28 -07:00
|
|
|
if not fmt_vimhelp:
|
|
|
|
pass
|
2019-03-29 13:54:34 -07:00
|
|
|
else:
|
2019-12-31 07:52:14 -07:00
|
|
|
fstem = '?'
|
|
|
|
if '.' in compoundname:
|
|
|
|
fstem = compoundname.split('.')[0]
|
2019-12-31 08:12:10 -07:00
|
|
|
fstem = CONFIG[target]['module_override'].get(fstem, fstem)
|
|
|
|
vimtag = CONFIG[target]['fn_helptag_fmt'](fstem, name)
|
2019-03-29 13:54:34 -07:00
|
|
|
|
2019-03-03 07:01:16 -07:00
|
|
|
params = []
|
2017-01-03 05:11:19 -07:00
|
|
|
type_length = 0
|
|
|
|
|
2019-12-24 01:04:14 -07:00
|
|
|
for param in iter_children(member, 'param'):
|
2019-03-03 07:01:16 -07:00
|
|
|
param_type = get_text(get_child(param, 'type')).strip()
|
|
|
|
param_name = ''
|
2017-01-03 05:11:19 -07:00
|
|
|
declname = get_child(param, 'declname')
|
|
|
|
if declname:
|
2019-03-03 07:01:16 -07:00
|
|
|
param_name = get_text(declname).strip()
|
2019-12-31 08:12:10 -07:00
|
|
|
elif CONFIG[target]['mode'] == 'lua':
|
2019-12-31 07:52:14 -07:00
|
|
|
# XXX: this is what lua2dox gives us...
|
2019-03-29 13:54:34 -07:00
|
|
|
param_name = param_type
|
|
|
|
param_type = ''
|
2017-01-03 05:11:19 -07:00
|
|
|
|
2019-03-03 07:01:16 -07:00
|
|
|
if param_name in param_exclude:
|
2017-01-03 05:11:19 -07:00
|
|
|
continue
|
|
|
|
|
2019-11-17 23:49:28 -07:00
|
|
|
if fmt_vimhelp and param_type.endswith('*'):
|
2019-03-03 07:01:16 -07:00
|
|
|
param_type = param_type.strip('* ')
|
|
|
|
param_name = '*' + param_name
|
|
|
|
type_length = max(type_length, len(param_type))
|
|
|
|
params.append((param_type, param_name))
|
2017-01-03 05:11:19 -07:00
|
|
|
|
|
|
|
c_args = []
|
2019-03-03 07:01:16 -07:00
|
|
|
for param_type, param_name in params:
|
2019-11-17 23:49:28 -07:00
|
|
|
c_args.append((' ' if fmt_vimhelp else '') + (
|
2019-03-03 07:01:16 -07:00
|
|
|
'%s %s' % (param_type.ljust(type_length), param_name)).strip())
|
2017-01-03 05:11:19 -07:00
|
|
|
|
|
|
|
prefix = '%s(' % name
|
2019-03-03 07:01:16 -07:00
|
|
|
suffix = '%s)' % ', '.join('{%s}' % a[1] for a in params
|
2017-01-03 05:11:19 -07:00
|
|
|
if a[0] not in ('void', 'Error'))
|
2019-11-17 23:49:28 -07:00
|
|
|
if not fmt_vimhelp:
|
|
|
|
c_decl = '%s %s(%s);' % (return_type, name, ', '.join(c_args))
|
|
|
|
signature = prefix + suffix
|
|
|
|
else:
|
|
|
|
c_decl = textwrap.indent('%s %s(\n%s\n);' % (return_type, name,
|
|
|
|
',\n'.join(c_args)),
|
|
|
|
' ')
|
2017-01-03 05:11:19 -07:00
|
|
|
|
2019-11-17 23:49:28 -07:00
|
|
|
# Minimum 8 chars between signature and vimtag
|
2019-12-31 07:52:14 -07:00
|
|
|
lhs = (width - 8) - len(vimtag)
|
2017-01-03 05:11:19 -07:00
|
|
|
|
2019-11-17 23:49:28 -07:00
|
|
|
if len(prefix) + len(suffix) > lhs:
|
2019-12-24 01:04:14 -07:00
|
|
|
signature = vimtag.rjust(width) + '\n'
|
|
|
|
signature += doc_wrap(suffix, width=width-8, prefix=prefix,
|
2019-11-17 23:49:28 -07:00
|
|
|
func=True)
|
|
|
|
else:
|
|
|
|
signature = prefix + suffix
|
2019-12-24 01:04:14 -07:00
|
|
|
signature += vimtag.rjust(width - len(signature))
|
2017-01-03 05:11:19 -07:00
|
|
|
|
2019-11-17 23:49:28 -07:00
|
|
|
paras = []
|
2020-07-02 04:09:17 -07:00
|
|
|
brief_desc = find_first(member, 'briefdescription')
|
|
|
|
if brief_desc:
|
|
|
|
for child in brief_desc.childNodes:
|
|
|
|
paras.append(para_as_map(child))
|
|
|
|
|
2017-01-03 05:11:19 -07:00
|
|
|
desc = find_first(member, 'detaileddescription')
|
|
|
|
if desc:
|
2019-11-17 23:49:28 -07:00
|
|
|
for child in desc.childNodes:
|
2019-12-22 23:08:49 -07:00
|
|
|
paras.append(para_as_map(child))
|
2019-03-03 07:01:16 -07:00
|
|
|
if DEBUG:
|
2017-01-03 05:11:19 -07:00
|
|
|
print(textwrap.indent(
|
|
|
|
re.sub(r'\n\s*\n+', '\n',
|
|
|
|
desc.toprettyxml(indent=' ', newl='\n')), ' ' * 16))
|
|
|
|
|
2019-11-17 23:49:28 -07:00
|
|
|
fn = {
|
|
|
|
'annotations': list(annotations),
|
|
|
|
'signature': signature,
|
|
|
|
'parameters': params,
|
2019-12-19 17:52:37 -07:00
|
|
|
'parameters_doc': collections.OrderedDict(),
|
2019-11-17 23:49:28 -07:00
|
|
|
'doc': [],
|
2019-12-19 17:52:37 -07:00
|
|
|
'return': [],
|
|
|
|
'seealso': [],
|
2019-11-17 23:49:28 -07:00
|
|
|
}
|
|
|
|
if fmt_vimhelp:
|
|
|
|
fn['desc_node'] = desc # HACK :(
|
[scripts/gen_vimdoc.py] Generate better-formatted mpack
Changes the generated msgpack result values in the runtime/doc/*.mpack
files to be formatted like this (instead of being formatted like Vim help text):
[
'nvim_win_get_var': {
'signature': 'nvim_win_get_var({window}, {name}, {err})',
'parameters': [('Window', 'window'), ('String', 'name'), ('Error *', 'err')],
'parameters_doc': [{'window': 'Window handle, or 0 for current window', 'name': 'Variable name'}],
'doc': ['Gets a window-scoped (w:) variable'],
'return': ['Variable value'],
'seealso': []
}
},
...
]
2019-11-06 15:22:20 -07:00
|
|
|
|
2019-11-17 23:49:28 -07:00
|
|
|
for m in paras:
|
[scripts/gen_vimdoc.py] Generate better-formatted mpack
Changes the generated msgpack result values in the runtime/doc/*.mpack
files to be formatted like this (instead of being formatted like Vim help text):
[
'nvim_win_get_var': {
'signature': 'nvim_win_get_var({window}, {name}, {err})',
'parameters': [('Window', 'window'), ('String', 'name'), ('Error *', 'err')],
'parameters_doc': [{'window': 'Window handle, or 0 for current window', 'name': 'Variable name'}],
'doc': ['Gets a window-scoped (w:) variable'],
'return': ['Variable value'],
'seealso': []
}
},
...
]
2019-11-06 15:22:20 -07:00
|
|
|
if 'text' in m:
|
|
|
|
if not m['text'] == '':
|
2019-11-17 23:49:28 -07:00
|
|
|
fn['doc'].append(m['text'])
|
[scripts/gen_vimdoc.py] Generate better-formatted mpack
Changes the generated msgpack result values in the runtime/doc/*.mpack
files to be formatted like this (instead of being formatted like Vim help text):
[
'nvim_win_get_var': {
'signature': 'nvim_win_get_var({window}, {name}, {err})',
'parameters': [('Window', 'window'), ('String', 'name'), ('Error *', 'err')],
'parameters_doc': [{'window': 'Window handle, or 0 for current window', 'name': 'Variable name'}],
'doc': ['Gets a window-scoped (w:) variable'],
'return': ['Variable value'],
'seealso': []
}
},
...
]
2019-11-06 15:22:20 -07:00
|
|
|
if 'params' in m:
|
2019-12-19 17:52:37 -07:00
|
|
|
# Merge OrderedDicts.
|
|
|
|
fn['parameters_doc'].update(m['params'])
|
|
|
|
if 'return' in m and len(m['return']) > 0:
|
|
|
|
fn['return'] += m['return']
|
2019-12-19 18:48:40 -07:00
|
|
|
if 'seealso' in m and len(m['seealso']) > 0:
|
|
|
|
fn['seealso'] += m['seealso']
|
[scripts/gen_vimdoc.py] Generate better-formatted mpack
Changes the generated msgpack result values in the runtime/doc/*.mpack
files to be formatted like this (instead of being formatted like Vim help text):
[
'nvim_win_get_var': {
'signature': 'nvim_win_get_var({window}, {name}, {err})',
'parameters': [('Window', 'window'), ('String', 'name'), ('Error *', 'err')],
'parameters_doc': [{'window': 'Window handle, or 0 for current window', 'name': 'Variable name'}],
'doc': ['Gets a window-scoped (w:) variable'],
'return': ['Variable value'],
'seealso': []
}
},
...
]
2019-11-06 15:22:20 -07:00
|
|
|
|
|
|
|
if INCLUDE_C_DECL:
|
2019-11-17 23:49:28 -07:00
|
|
|
fn['c_decl'] = c_decl
|
[scripts/gen_vimdoc.py] Generate better-formatted mpack
Changes the generated msgpack result values in the runtime/doc/*.mpack
files to be formatted like this (instead of being formatted like Vim help text):
[
'nvim_win_get_var': {
'signature': 'nvim_win_get_var({window}, {name}, {err})',
'parameters': [('Window', 'window'), ('String', 'name'), ('Error *', 'err')],
'parameters_doc': [{'window': 'Window handle, or 0 for current window', 'name': 'Variable name'}],
'doc': ['Gets a window-scoped (w:) variable'],
'return': ['Variable value'],
'seealso': []
}
},
...
]
2019-11-06 15:22:20 -07:00
|
|
|
|
2019-12-28 03:15:06 -07:00
|
|
|
if 'Deprecated' in str(xrefs):
|
2019-12-24 01:04:14 -07:00
|
|
|
deprecated_fns[name] = fn
|
2019-12-31 08:12:10 -07:00
|
|
|
elif name.startswith(CONFIG[target]['fn_name_prefix']):
|
2019-12-24 01:04:14 -07:00
|
|
|
fns[name] = fn
|
[scripts/gen_vimdoc.py] Generate better-formatted mpack
Changes the generated msgpack result values in the runtime/doc/*.mpack
files to be formatted like this (instead of being formatted like Vim help text):
[
'nvim_win_get_var': {
'signature': 'nvim_win_get_var({window}, {name}, {err})',
'parameters': [('Window', 'window'), ('String', 'name'), ('Error *', 'err')],
'parameters_doc': [{'window': 'Window handle, or 0 for current window', 'name': 'Variable name'}],
'doc': ['Gets a window-scoped (w:) variable'],
'return': ['Variable value'],
'seealso': []
}
},
...
]
2019-11-06 15:22:20 -07:00
|
|
|
|
|
|
|
xrefs.clear()
|
|
|
|
|
2019-12-28 04:27:25 -07:00
|
|
|
fns = collections.OrderedDict(sorted(fns.items()))
|
|
|
|
deprecated_fns = collections.OrderedDict(sorted(deprecated_fns.items()))
|
2019-12-24 01:04:14 -07:00
|
|
|
return (fns, deprecated_fns)
|
[scripts/gen_vimdoc.py] Generate better-formatted mpack
Changes the generated msgpack result values in the runtime/doc/*.mpack
files to be formatted like this (instead of being formatted like Vim help text):
[
'nvim_win_get_var': {
'signature': 'nvim_win_get_var({window}, {name}, {err})',
'parameters': [('Window', 'window'), ('String', 'name'), ('Error *', 'err')],
'parameters_doc': [{'window': 'Window handle, or 0 for current window', 'name': 'Variable name'}],
'doc': ['Gets a window-scoped (w:) variable'],
'return': ['Variable value'],
'seealso': []
}
},
...
]
2019-11-06 15:22:20 -07:00
|
|
|
|
|
|
|
|
2019-12-31 08:12:10 -07:00
|
|
|
def fmt_doxygen_xml_as_vimhelp(filename, target):
|
2019-12-24 01:04:14 -07:00
|
|
|
"""Entrypoint for generating Vim :help from from Doxygen XML.
|
2019-11-17 23:49:28 -07:00
|
|
|
|
2019-12-24 01:04:14 -07:00
|
|
|
Returns 3 items:
|
|
|
|
1. Vim help text for functions found in `filename`.
|
|
|
|
2. Vim help text for deprecated functions.
|
2017-01-03 05:11:19 -07:00
|
|
|
"""
|
2019-12-24 01:04:14 -07:00
|
|
|
global fmt_vimhelp
|
|
|
|
fmt_vimhelp = True
|
|
|
|
fns_txt = {} # Map of func_name:vim-help-text.
|
|
|
|
deprecated_fns_txt = {} # Map of func_name:vim-help-text.
|
2019-12-31 08:12:10 -07:00
|
|
|
fns, _ = extract_from_xml(filename, target, width=text_width)
|
2017-01-03 05:11:19 -07:00
|
|
|
|
2019-11-17 23:49:28 -07:00
|
|
|
for name, fn in fns.items():
|
2019-12-19 20:42:24 -07:00
|
|
|
# Generate Vim :help for parameters.
|
2019-11-17 23:49:28 -07:00
|
|
|
if fn['desc_node']:
|
2019-12-19 20:42:24 -07:00
|
|
|
doc = fmt_node_as_vimhelp(fn['desc_node'])
|
2017-01-03 05:11:19 -07:00
|
|
|
if not doc:
|
|
|
|
doc = 'TODO: Documentation'
|
|
|
|
|
2019-11-17 23:49:28 -07:00
|
|
|
annotations = '\n'.join(fn['annotations'])
|
2017-03-01 09:55:34 -07:00
|
|
|
if annotations:
|
2018-07-02 11:41:11 -07:00
|
|
|
annotations = ('\n\nAttributes: ~\n' +
|
2017-03-01 09:55:34 -07:00
|
|
|
textwrap.indent(annotations, ' '))
|
2018-07-02 11:41:11 -07:00
|
|
|
i = doc.rfind('Parameters: ~')
|
2017-03-01 09:55:34 -07:00
|
|
|
if i == -1:
|
|
|
|
doc += annotations
|
|
|
|
else:
|
|
|
|
doc = doc[:i] + annotations + '\n\n' + doc[i:]
|
|
|
|
|
2019-03-03 07:01:16 -07:00
|
|
|
if INCLUDE_C_DECL:
|
2018-07-02 11:41:11 -07:00
|
|
|
doc += '\n\nC Declaration: ~\n>\n'
|
2019-11-17 23:49:28 -07:00
|
|
|
doc += fn['c_decl']
|
2017-01-03 05:11:19 -07:00
|
|
|
doc += '\n<'
|
|
|
|
|
2019-11-17 23:49:28 -07:00
|
|
|
func_doc = fn['signature'] + '\n'
|
2017-01-03 05:11:19 -07:00
|
|
|
func_doc += textwrap.indent(clean_lines(doc), ' ' * 16)
|
2020-07-02 04:09:17 -07:00
|
|
|
|
|
|
|
# Verbatim handling.
|
2017-01-03 05:11:19 -07:00
|
|
|
func_doc = re.sub(r'^\s+([<>])$', r'\1', func_doc, flags=re.M)
|
|
|
|
|
2020-07-02 04:09:17 -07:00
|
|
|
split_lines = func_doc.split('\n')
|
|
|
|
start = 0
|
|
|
|
while True:
|
|
|
|
try:
|
|
|
|
start = split_lines.index('>', start)
|
|
|
|
except ValueError:
|
|
|
|
break
|
|
|
|
|
|
|
|
try:
|
|
|
|
end = split_lines.index('<', start)
|
|
|
|
except ValueError:
|
|
|
|
break
|
|
|
|
|
|
|
|
split_lines[start + 1:end] = [
|
|
|
|
(' ' + x).rstrip()
|
|
|
|
for x in textwrap.dedent(
|
|
|
|
"\n".join(
|
|
|
|
split_lines[start+1:end]
|
|
|
|
)
|
|
|
|
).split("\n")
|
|
|
|
]
|
|
|
|
|
|
|
|
start = end
|
|
|
|
|
|
|
|
func_doc = "\n".join(split_lines)
|
|
|
|
|
2017-01-03 05:11:19 -07:00
|
|
|
if 'Deprecated' in xrefs:
|
2019-12-24 01:04:14 -07:00
|
|
|
deprecated_fns_txt[name] = func_doc
|
2019-12-31 08:12:10 -07:00
|
|
|
elif name.startswith(CONFIG[target]['fn_name_prefix']):
|
2019-12-24 01:04:14 -07:00
|
|
|
fns_txt[name] = func_doc
|
2017-01-03 05:11:19 -07:00
|
|
|
|
|
|
|
xrefs.clear()
|
|
|
|
|
2019-12-24 01:04:14 -07:00
|
|
|
fmt_vimhelp = False
|
|
|
|
return ('\n\n'.join(list(fns_txt.values())),
|
|
|
|
'\n\n'.join(list(deprecated_fns_txt.values())))
|
2017-01-03 05:11:19 -07:00
|
|
|
|
|
|
|
|
2017-03-01 09:18:03 -07:00
|
|
|
def delete_lines_below(filename, tokenstr):
|
|
|
|
"""Deletes all lines below the line containing `tokenstr`, the line itself,
|
|
|
|
and one line above it.
|
|
|
|
"""
|
|
|
|
lines = open(filename).readlines()
|
|
|
|
i = 0
|
2019-12-31 07:52:14 -07:00
|
|
|
found = False
|
2017-03-01 09:18:03 -07:00
|
|
|
for i, line in enumerate(lines, 1):
|
|
|
|
if tokenstr in line:
|
2019-12-31 07:52:14 -07:00
|
|
|
found = True
|
2017-03-01 09:18:03 -07:00
|
|
|
break
|
2019-12-31 07:52:14 -07:00
|
|
|
if not found:
|
|
|
|
raise RuntimeError(f'not found: "{tokenstr}"')
|
2017-03-01 09:18:03 -07:00
|
|
|
i = max(0, i - 2)
|
|
|
|
with open(filename, 'wt') as fp:
|
|
|
|
fp.writelines(lines[0:i])
|
|
|
|
|
2019-07-28 19:43:28 -07:00
|
|
|
|
2020-08-31 00:51:35 -07:00
|
|
|
def main(config, args):
|
2019-12-24 01:04:14 -07:00
|
|
|
"""Generates:
|
|
|
|
|
|
|
|
1. Vim :help docs
|
|
|
|
2. *.mpack files for use by API clients
|
2017-01-03 05:11:19 -07:00
|
|
|
|
|
|
|
Doxygen is called and configured through stdin.
|
|
|
|
"""
|
2019-12-31 08:12:10 -07:00
|
|
|
for target in CONFIG:
|
2020-08-31 00:51:35 -07:00
|
|
|
if args.target is not None and target != args.target:
|
2019-12-31 07:52:14 -07:00
|
|
|
continue
|
2019-10-26 16:21:22 -07:00
|
|
|
mpack_file = os.path.join(
|
[scripts/gen_vimdoc.py] Generate better-formatted mpack
Changes the generated msgpack result values in the runtime/doc/*.mpack
files to be formatted like this (instead of being formatted like Vim help text):
[
'nvim_win_get_var': {
'signature': 'nvim_win_get_var({window}, {name}, {err})',
'parameters': [('Window', 'window'), ('String', 'name'), ('Error *', 'err')],
'parameters_doc': [{'window': 'Window handle, or 0 for current window', 'name': 'Variable name'}],
'doc': ['Gets a window-scoped (w:) variable'],
'return': ['Variable value'],
'seealso': []
}
},
...
]
2019-11-06 15:22:20 -07:00
|
|
|
base_dir, 'runtime', 'doc',
|
2019-12-31 08:12:10 -07:00
|
|
|
CONFIG[target]['filename'].replace('.txt', '.mpack'))
|
2019-10-26 12:54:54 -07:00
|
|
|
if os.path.exists(mpack_file):
|
|
|
|
os.remove(mpack_file)
|
|
|
|
|
2019-12-31 08:12:10 -07:00
|
|
|
output_dir = out_dir.format(target=target)
|
|
|
|
p = subprocess.Popen(
|
|
|
|
['doxygen', '-'],
|
|
|
|
stdin=subprocess.PIPE,
|
2019-12-31 07:52:14 -07:00
|
|
|
# silence warnings
|
2019-12-31 08:12:10 -07:00
|
|
|
# runtime/lua/vim/lsp.lua:209: warning: argument 'foo' not found
|
2020-01-13 00:41:55 -07:00
|
|
|
stderr=(subprocess.STDOUT if DEBUG else subprocess.DEVNULL))
|
2019-03-29 13:54:34 -07:00
|
|
|
p.communicate(
|
|
|
|
config.format(
|
2019-12-31 08:12:10 -07:00
|
|
|
input=CONFIG[target]['files'],
|
2019-03-29 13:54:34 -07:00
|
|
|
output=output_dir,
|
|
|
|
filter=filter_cmd,
|
2019-12-31 08:12:10 -07:00
|
|
|
file_patterns=CONFIG[target]['file_patterns'])
|
2019-03-29 13:54:34 -07:00
|
|
|
.encode('utf8')
|
|
|
|
)
|
|
|
|
if p.returncode:
|
|
|
|
sys.exit(p.returncode)
|
|
|
|
|
gen_vimdoc.py: mpack: collect functions in 1 dict
All Nvim API, core Vimscript, and core Lua functions are globally
unique, so there is no need for per-module nested dicts.
BEFORE (generated mpack structure):
[
{
"buffer.c": {
"nvim__buf_stats": { ... },
...
},
"window.c": {
"nvim_win_close": { ... },
...
},
...
}
]
AFTER (generated mpack structure):
[
{
"nvim__buf_stats": {
...
},
"nvim_buf_attach": {
...
},
"nvim_tabpage_set_var": {
...
},
"nvim_ui_attach": {
...
},
"nvim_win_close": {
...
}
}
]
2019-12-19 19:17:43 -07:00
|
|
|
fn_map_full = {} # Collects all functions as each module is processed.
|
2019-03-29 13:54:34 -07:00
|
|
|
sections = {}
|
|
|
|
intros = {}
|
|
|
|
sep = '=' * text_width
|
|
|
|
|
|
|
|
base = os.path.join(output_dir, 'xml')
|
|
|
|
dom = minidom.parse(os.path.join(base, 'index.xml'))
|
|
|
|
|
|
|
|
# generate docs for section intros
|
|
|
|
for compound in dom.getElementsByTagName('compound'):
|
|
|
|
if compound.getAttribute('kind') != 'group':
|
|
|
|
continue
|
2018-07-24 21:07:55 -07:00
|
|
|
|
2019-03-29 13:54:34 -07:00
|
|
|
groupname = get_text(find_first(compound, 'name'))
|
2019-07-28 19:43:28 -07:00
|
|
|
groupxml = os.path.join(base, '%s.xml' %
|
|
|
|
compound.getAttribute('refid'))
|
2018-07-24 21:07:55 -07:00
|
|
|
|
2020-07-02 04:09:17 -07:00
|
|
|
group_parsed = minidom.parse(groupxml)
|
|
|
|
doc_list = []
|
|
|
|
brief_desc = find_first(group_parsed, 'briefdescription')
|
|
|
|
if brief_desc:
|
|
|
|
for child in brief_desc.childNodes:
|
|
|
|
doc_list.append(fmt_node_as_vimhelp(child))
|
|
|
|
|
|
|
|
desc = find_first(group_parsed, 'detaileddescription')
|
2019-03-29 13:54:34 -07:00
|
|
|
if desc:
|
2019-12-19 20:42:24 -07:00
|
|
|
doc = fmt_node_as_vimhelp(desc)
|
2020-07-02 04:09:17 -07:00
|
|
|
|
2019-03-29 13:54:34 -07:00
|
|
|
if doc:
|
2020-07-02 04:09:17 -07:00
|
|
|
doc_list.append(doc)
|
|
|
|
|
|
|
|
intros[groupname] = "\n".join(doc_list)
|
2018-07-24 21:07:55 -07:00
|
|
|
|
2019-03-29 13:54:34 -07:00
|
|
|
for compound in dom.getElementsByTagName('compound'):
|
|
|
|
if compound.getAttribute('kind') != 'file':
|
|
|
|
continue
|
2017-01-03 05:11:19 -07:00
|
|
|
|
2019-03-29 13:54:34 -07:00
|
|
|
filename = get_text(find_first(compound, 'name'))
|
|
|
|
if filename.endswith('.c') or filename.endswith('.lua'):
|
2020-08-31 00:51:35 -07:00
|
|
|
xmlfile = os.path.join(base,
|
|
|
|
'{}.xml'.format(compound.getAttribute('refid')))
|
2019-12-24 01:04:14 -07:00
|
|
|
# Extract unformatted (*.mpack).
|
2020-08-31 00:51:35 -07:00
|
|
|
fn_map, _ = extract_from_xml(xmlfile, target, width=9999)
|
2019-12-24 01:04:14 -07:00
|
|
|
# Extract formatted (:help).
|
|
|
|
functions_text, deprecated_text = fmt_doxygen_xml_as_vimhelp(
|
2019-10-26 16:21:22 -07:00
|
|
|
os.path.join(base, '{}.xml'.format(
|
2019-12-31 08:12:10 -07:00
|
|
|
compound.getAttribute('refid'))), target)
|
2017-01-03 05:11:19 -07:00
|
|
|
|
2019-10-26 12:54:54 -07:00
|
|
|
if not functions_text and not deprecated_text:
|
2019-03-29 13:54:34 -07:00
|
|
|
continue
|
2019-10-26 12:54:54 -07:00
|
|
|
else:
|
2019-12-31 07:52:14 -07:00
|
|
|
name = os.path.splitext(
|
|
|
|
os.path.basename(filename))[0].lower()
|
|
|
|
sectname = name.upper() if name == 'ui' else name.title()
|
2019-03-29 13:54:34 -07:00
|
|
|
doc = ''
|
2019-12-31 07:52:14 -07:00
|
|
|
intro = intros.get(f'api-{name}')
|
2019-03-29 13:54:34 -07:00
|
|
|
if intro:
|
|
|
|
doc += '\n\n' + intro
|
2018-07-24 21:07:55 -07:00
|
|
|
|
2019-10-26 12:54:54 -07:00
|
|
|
if functions_text:
|
|
|
|
doc += '\n\n' + functions_text
|
2017-01-03 05:11:19 -07:00
|
|
|
|
2019-10-26 12:54:54 -07:00
|
|
|
if INCLUDE_DEPRECATED and deprecated_text:
|
2019-12-31 07:52:14 -07:00
|
|
|
doc += f'\n\n\nDeprecated {sectname} Functions: ~\n\n'
|
2019-10-26 12:54:54 -07:00
|
|
|
doc += deprecated_text
|
2017-01-03 05:11:19 -07:00
|
|
|
|
2019-03-29 13:54:34 -07:00
|
|
|
if doc:
|
|
|
|
filename = os.path.basename(filename)
|
2019-12-31 08:12:10 -07:00
|
|
|
sectname = CONFIG[target]['section_name'].get(
|
2019-12-31 07:52:14 -07:00
|
|
|
filename, sectname)
|
2019-12-31 08:12:10 -07:00
|
|
|
title = CONFIG[target]['section_fmt'](sectname)
|
|
|
|
helptag = CONFIG[target]['helptag_fmt'](sectname)
|
2019-03-29 13:54:34 -07:00
|
|
|
sections[filename] = (title, helptag, doc)
|
gen_vimdoc.py: mpack: collect functions in 1 dict
All Nvim API, core Vimscript, and core Lua functions are globally
unique, so there is no need for per-module nested dicts.
BEFORE (generated mpack structure):
[
{
"buffer.c": {
"nvim__buf_stats": { ... },
...
},
"window.c": {
"nvim_win_close": { ... },
...
},
...
}
]
AFTER (generated mpack structure):
[
{
"nvim__buf_stats": {
...
},
"nvim_buf_attach": {
...
},
"nvim_tabpage_set_var": {
...
},
"nvim_ui_attach": {
...
},
"nvim_win_close": {
...
}
}
]
2019-12-19 19:17:43 -07:00
|
|
|
fn_map_full.update(fn_map)
|
2017-01-03 05:11:19 -07:00
|
|
|
|
2020-08-31 00:51:35 -07:00
|
|
|
if len(sections) == 0:
|
|
|
|
fail(f'no sections for target: {target}')
|
2019-12-31 08:12:10 -07:00
|
|
|
if len(sections) > len(CONFIG[target]['section_order']):
|
2019-12-31 07:52:14 -07:00
|
|
|
raise RuntimeError(
|
|
|
|
'found new modules "{}"; update the "section_order" map'.format(
|
2019-12-31 08:12:10 -07:00
|
|
|
set(sections).difference(CONFIG[target]['section_order'])))
|
2017-01-03 05:11:19 -07:00
|
|
|
|
2019-03-29 13:54:34 -07:00
|
|
|
docs = ''
|
2017-01-03 05:11:19 -07:00
|
|
|
|
2019-03-29 13:54:34 -07:00
|
|
|
i = 0
|
2019-12-31 08:12:10 -07:00
|
|
|
for filename in CONFIG[target]['section_order']:
|
2020-08-19 09:17:08 -07:00
|
|
|
try:
|
|
|
|
title, helptag, section_doc = sections.pop(filename)
|
|
|
|
except KeyError:
|
2020-08-31 00:51:35 -07:00
|
|
|
msg(f'warning: empty docs, skipping (target={target}): {filename}')
|
2020-08-19 09:17:08 -07:00
|
|
|
continue
|
2017-01-03 05:11:19 -07:00
|
|
|
i += 1
|
2019-12-31 08:12:10 -07:00
|
|
|
if filename not in CONFIG[target]['append_only']:
|
2019-03-29 13:54:34 -07:00
|
|
|
docs += sep
|
2019-07-28 19:43:28 -07:00
|
|
|
docs += '\n%s%s' % (title,
|
|
|
|
helptag.rjust(text_width - len(title)))
|
2019-05-18 13:04:31 -07:00
|
|
|
docs += section_doc
|
|
|
|
docs += '\n\n\n'
|
2017-01-03 05:11:19 -07:00
|
|
|
|
2019-03-29 13:54:34 -07:00
|
|
|
docs = docs.rstrip() + '\n\n'
|
|
|
|
docs += ' vim:tw=78:ts=8:ft=help:norl:\n'
|
|
|
|
|
|
|
|
doc_file = os.path.join(base_dir, 'runtime', 'doc',
|
2019-12-31 08:12:10 -07:00
|
|
|
CONFIG[target]['filename'])
|
2019-03-29 13:54:34 -07:00
|
|
|
|
2019-12-31 08:12:10 -07:00
|
|
|
delete_lines_below(doc_file, CONFIG[target]['section_start_token'])
|
2019-03-29 13:54:34 -07:00
|
|
|
with open(doc_file, 'ab') as fp:
|
|
|
|
fp.write(docs.encode('utf8'))
|
[scripts/gen_vimdoc.py] Generate better-formatted mpack
Changes the generated msgpack result values in the runtime/doc/*.mpack
files to be formatted like this (instead of being formatted like Vim help text):
[
'nvim_win_get_var': {
'signature': 'nvim_win_get_var({window}, {name}, {err})',
'parameters': [('Window', 'window'), ('String', 'name'), ('Error *', 'err')],
'parameters_doc': [{'window': 'Window handle, or 0 for current window', 'name': 'Variable name'}],
'doc': ['Gets a window-scoped (w:) variable'],
'return': ['Variable value'],
'seealso': []
}
},
...
]
2019-11-06 15:22:20 -07:00
|
|
|
|
2019-12-28 04:27:25 -07:00
|
|
|
fn_map_full = collections.OrderedDict(sorted(fn_map_full.items()))
|
2019-10-26 12:54:54 -07:00
|
|
|
with open(mpack_file, 'wb') as fp:
|
gen_vimdoc.py: mpack: collect functions in 1 dict
All Nvim API, core Vimscript, and core Lua functions are globally
unique, so there is no need for per-module nested dicts.
BEFORE (generated mpack structure):
[
{
"buffer.c": {
"nvim__buf_stats": { ... },
...
},
"window.c": {
"nvim_win_close": { ... },
...
},
...
}
]
AFTER (generated mpack structure):
[
{
"nvim__buf_stats": {
...
},
"nvim_buf_attach": {
...
},
"nvim_tabpage_set_var": {
...
},
"nvim_ui_attach": {
...
},
"nvim_win_close": {
...
}
}
]
2019-12-19 19:17:43 -07:00
|
|
|
fp.write(msgpack.packb(fn_map_full, use_bin_type=True))
|
2019-03-29 13:54:34 -07:00
|
|
|
|
2020-08-08 12:47:59 -07:00
|
|
|
if not args.keep_tmpfiles:
|
|
|
|
shutil.rmtree(output_dir)
|
2017-01-03 05:11:19 -07:00
|
|
|
|
2020-08-31 00:51:35 -07:00
|
|
|
msg_report()
|
|
|
|
|
2017-01-03 05:11:19 -07:00
|
|
|
|
|
|
|
def filter_source(filename):
|
2019-03-29 13:54:34 -07:00
|
|
|
name, extension = os.path.splitext(filename)
|
|
|
|
if extension == '.lua':
|
|
|
|
p = subprocess.run([lua2dox_filter, filename], stdout=subprocess.PIPE)
|
|
|
|
op = ('?' if 0 != p.returncode else p.stdout.decode('utf-8'))
|
|
|
|
print(op)
|
|
|
|
else:
|
|
|
|
"""Filters the source to fix macros that confuse Doxygen."""
|
|
|
|
with open(filename, 'rt') as fp:
|
|
|
|
print(re.sub(r'^(ArrayOf|DictionaryOf)(\(.*?\))',
|
|
|
|
lambda m: m.group(1)+'_'.join(
|
|
|
|
re.split(r'[^\w]+', m.group(2))),
|
|
|
|
fp.read(), flags=re.M))
|
2017-01-03 05:11:19 -07:00
|
|
|
|
|
|
|
|
2020-08-08 12:47:59 -07:00
|
|
|
def parse_args():
|
2020-08-31 00:51:35 -07:00
|
|
|
targets = ', '.join(CONFIG.keys())
|
2020-08-08 12:47:59 -07:00
|
|
|
ap = argparse.ArgumentParser()
|
|
|
|
ap.add_argument('source_filter', nargs='*',
|
|
|
|
help="Filter source file(s)")
|
|
|
|
ap.add_argument('-k', '--keep-tmpfiles', action='store_true',
|
|
|
|
help="Keep temporary files")
|
2020-08-31 00:51:35 -07:00
|
|
|
ap.add_argument('-t', '--target',
|
|
|
|
help=f'One of ({targets}), defaults to "all"')
|
2020-08-08 12:47:59 -07:00
|
|
|
return ap.parse_args()
|
|
|
|
|
|
|
|
|
2019-11-17 23:49:28 -07:00
|
|
|
Doxyfile = textwrap.dedent('''
|
|
|
|
OUTPUT_DIRECTORY = {output}
|
|
|
|
INPUT = {input}
|
|
|
|
INPUT_ENCODING = UTF-8
|
|
|
|
FILE_PATTERNS = {file_patterns}
|
|
|
|
RECURSIVE = YES
|
|
|
|
INPUT_FILTER = "{filter}"
|
|
|
|
EXCLUDE =
|
|
|
|
EXCLUDE_SYMLINKS = NO
|
|
|
|
EXCLUDE_PATTERNS = */private/*
|
|
|
|
EXCLUDE_SYMBOLS =
|
|
|
|
EXTENSION_MAPPING = lua=C
|
|
|
|
EXTRACT_PRIVATE = NO
|
|
|
|
|
|
|
|
GENERATE_HTML = NO
|
|
|
|
GENERATE_DOCSET = NO
|
|
|
|
GENERATE_HTMLHELP = NO
|
|
|
|
GENERATE_QHP = NO
|
|
|
|
GENERATE_TREEVIEW = NO
|
|
|
|
GENERATE_LATEX = NO
|
|
|
|
GENERATE_RTF = NO
|
|
|
|
GENERATE_MAN = NO
|
|
|
|
GENERATE_DOCBOOK = NO
|
|
|
|
GENERATE_AUTOGEN_DEF = NO
|
|
|
|
|
|
|
|
GENERATE_XML = YES
|
|
|
|
XML_OUTPUT = xml
|
|
|
|
XML_PROGRAMLISTING = NO
|
|
|
|
|
|
|
|
ENABLE_PREPROCESSING = YES
|
|
|
|
MACRO_EXPANSION = YES
|
|
|
|
EXPAND_ONLY_PREDEF = NO
|
|
|
|
MARKDOWN_SUPPORT = YES
|
|
|
|
''')
|
2017-01-03 05:11:19 -07:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2020-08-08 12:47:59 -07:00
|
|
|
args = parse_args()
|
|
|
|
if len(args.source_filter) > 0:
|
|
|
|
filter_source(args.source_filter[0])
|
2017-01-03 05:11:19 -07:00
|
|
|
else:
|
2020-08-08 12:47:59 -07:00
|
|
|
main(Doxyfile, args)
|
2017-01-03 05:11:19 -07:00
|
|
|
|
2019-11-17 23:49:28 -07:00
|
|
|
# vim: set ft=python ts=4 sw=4 tw=79 et :
|