Merge pull request #17707 from tesaguri/refactor-gen_vimdoc

This commit is contained in:
James McCoy
2022-03-16 16:13:59 -04:00
committed by GitHub
6 changed files with 125 additions and 127 deletions

View File

@@ -594,7 +594,8 @@ nvim__id_float({flt}) *nvim__id_float()*
its argument. its argument.
nvim__inspect_cell({grid}, {row}, {col}) *nvim__inspect_cell()* nvim__inspect_cell({grid}, {row}, {col}) *nvim__inspect_cell()*
TODO: Documentation NB: if your UI doesn't use hlstate, this will not return
hlstate first time.
nvim__runtime_inspect() *nvim__runtime_inspect()* nvim__runtime_inspect() *nvim__runtime_inspect()*
TODO: Documentation TODO: Documentation
@@ -1247,8 +1248,8 @@ nvim_input_mouse({button}, {action}, {modifier}, {grid}, {row}, {col})
nvim_list_bufs() *nvim_list_bufs()* nvim_list_bufs() *nvim_list_bufs()*
Gets the current list of buffer handles Gets the current list of buffer handles
Includes unlisted (unloaded/deleted) buffers, like `:ls!` . Includes unlisted (unloaded/deleted) buffers, like `:ls!`. Use
Use |nvim_buf_is_loaded()| to check if a buffer is loaded. |nvim_buf_is_loaded()| to check if a buffer is loaded.
Return: ~ Return: ~
List of buffer handles List of buffer handles
@@ -1547,18 +1548,21 @@ nvim_set_hl({ns_id}, {name}, {*val}) *nvim_set_hl()*
Sets a highlight group. Sets a highlight group.
Parameters: ~ Parameters: ~
{ns_id} Namespace id for this highlight |nvim_create_namespace()|. {ns_id} Namespace id for this highlight
Use 0 to set a highlight group globally |:highlight|. |nvim_create_namespace()|. Use 0 to set a
highlight group globally |:highlight|.
{name} Highlight group name, e.g. "ErrorMsg" {name} Highlight group name, e.g. "ErrorMsg"
{val} Highlight definition map, like |synIDattr()|. In {val} Highlight definition map, like |synIDattr()|. In
addition, the following keys are recognized: addition, the following keys are recognized:
• default: Don't override existing definition |:hi-default| • default: Don't override existing definition
• ctermfg: Sets foreground of cterm color |highlight-ctermfg| |:hi-default|
• ctermbg: Sets background of cterm color |highlight-ctermbg| • ctermfg: Sets foreground of cterm color
|highlight-ctermfg|
• ctermbg: Sets background of cterm color
|highlight-ctermbg|
• cterm: cterm attribute map, like • cterm: cterm attribute map, like
|highlight-args|. |highlight-args|. Note: Attributes default to
Note: Attributes default to those set for `gui` those set for `gui` if not set.
if not set.
nvim_set_keymap({mode}, {lhs}, {rhs}, {*opts}) *nvim_set_keymap()* nvim_set_keymap({mode}, {lhs}, {rhs}, {*opts}) *nvim_set_keymap()*
Sets a global |mapping| for the given mode. Sets a global |mapping| for the given mode.
@@ -1879,8 +1883,9 @@ nvim_buf_attach({buffer}, {send_buffer}, {opts}) *nvim_buf_attach()*
{buffer} Buffer handle, or 0 for current buffer {buffer} Buffer handle, or 0 for current buffer
{send_buffer} True if the initial notification should {send_buffer} True if the initial notification should
contain the whole buffer: first contain the whole buffer: first
notification will be `nvim_buf_lines_event` notification will be
. Else the first notification will be `nvim_buf_lines_event`. Else the first
notification will be
`nvim_buf_changedtick_event`. Not for Lua `nvim_buf_changedtick_event`. Not for Lua
callbacks. callbacks.
{opts} Optional parameters. {opts} Optional parameters.

View File

@@ -800,8 +800,8 @@ start_client({config}) *vim.lsp.start_client()*
its result. its result.
• Note: To send an empty dictionary • Note: To send an empty dictionary
use use
`{[vim.type_idx]=vim.types.dictionary}` `{[vim.type_idx]=vim.types.dictionary}`,
, else it will be encoded as an else it will be encoded as an
array. array.
{handlers} Map of language server method names {handlers} Map of language server method names
to |lsp-handler| to |lsp-handler|

View File

@@ -1990,9 +1990,9 @@ set({mode}, {lhs}, {rhs}, {opts}) *vim.keymap.set()*
vim.keymap.set('n', 'asdf', require('jkl').my_fun) vim.keymap.set('n', 'asdf', require('jkl').my_fun)
< <
the require('jkl') gets evaluated during this call in order to the require('jkl )` gets evaluated during this call in order to access the
access the function. If you want to avoid this cost at startup function. If you want to avoid this cost at startup you can
you can wrap it in a function, for example: > wrap it in a function, for example: >
vim.keymap.set('n', 'asdf', function() return require('jkl').my_fun() end) vim.keymap.set('n', 'asdf', function() return require('jkl').my_fun() end)
< <

View File

@@ -528,8 +528,8 @@ Query:iter_matches({self}, {node}, {source}, {start}, {stop})
a table mapping capture indices to nodes, and metadata from a table mapping capture indices to nodes, and metadata from
any directives processing the match. If the query has more any directives processing the match. If the query has more
than one pattern the capture table might be sparse, and e.g. than one pattern the capture table might be sparse, and e.g.
`pairs()` method should be used over `ipairs` . Here an `pairs()` method should be used over `ipairs`. Here an example
example iterating over all captures in every match: iterating over all captures in every match:
> >
for pattern, match, metadata in cquery:iter_matches(tree:root(), bufnr, first, last) do for pattern, match, metadata in cquery:iter_matches(tree:root(), bufnr, first, last) do

View File

@@ -84,8 +84,6 @@ CONFIG = {
'api': { 'api': {
'mode': 'c', 'mode': 'c',
'filename': 'api.txt', 'filename': 'api.txt',
# String used to find the start of the generated part of the doc.
'section_start_token': '*api-global*',
# Section ordering. # Section ordering.
'section_order': [ 'section_order': [
'vim.c', 'vim.c',
@@ -98,8 +96,8 @@ CONFIG = {
'autocmd.c', 'autocmd.c',
'ui.c', 'ui.c',
], ],
# List of files/directories for doxygen to read, separated by blanks # List of files/directories for doxygen to read, relative to `base_dir`
'files': os.path.join(base_dir, 'src/nvim/api'), 'files': ['src/nvim/api'],
# file patterns used by doxygen # file patterns used by doxygen
'file_patterns': '*.h *.c', 'file_patterns': '*.h *.c',
# Only function with this prefix are considered # Only function with this prefix are considered
@@ -122,7 +120,6 @@ CONFIG = {
'lua': { 'lua': {
'mode': 'lua', 'mode': 'lua',
'filename': 'lua.txt', 'filename': 'lua.txt',
'section_start_token': '*lua-vim*',
'section_order': [ 'section_order': [
'_editor.lua', '_editor.lua',
'shared.lua', 'shared.lua',
@@ -131,14 +128,14 @@ CONFIG = {
'filetype.lua', 'filetype.lua',
'keymap.lua', 'keymap.lua',
], ],
'files': ' '.join([ 'files': [
os.path.join(base_dir, 'runtime/lua/vim/_editor.lua'), 'runtime/lua/vim/_editor.lua',
os.path.join(base_dir, 'runtime/lua/vim/shared.lua'), 'runtime/lua/vim/shared.lua',
os.path.join(base_dir, 'runtime/lua/vim/uri.lua'), 'runtime/lua/vim/uri.lua',
os.path.join(base_dir, 'runtime/lua/vim/ui.lua'), 'runtime/lua/vim/ui.lua',
os.path.join(base_dir, 'runtime/lua/vim/filetype.lua'), 'runtime/lua/vim/filetype.lua',
os.path.join(base_dir, 'runtime/lua/vim/keymap.lua'), 'runtime/lua/vim/keymap.lua',
]), ],
'file_patterns': '*.lua', 'file_patterns': '*.lua',
'fn_name_prefix': '', 'fn_name_prefix': '',
'section_name': { 'section_name': {
@@ -171,7 +168,6 @@ CONFIG = {
'lsp': { 'lsp': {
'mode': 'lua', 'mode': 'lua',
'filename': 'lsp.txt', 'filename': 'lsp.txt',
'section_start_token': '*lsp-core*',
'section_order': [ 'section_order': [
'lsp.lua', 'lsp.lua',
'buf.lua', 'buf.lua',
@@ -185,10 +181,10 @@ CONFIG = {
'sync.lua', 'sync.lua',
'protocol.lua', 'protocol.lua',
], ],
'files': ' '.join([ 'files': [
os.path.join(base_dir, 'runtime/lua/vim/lsp'), 'runtime/lua/vim/lsp',
os.path.join(base_dir, 'runtime/lua/vim/lsp.lua'), 'runtime/lua/vim/lsp.lua',
]), ],
'file_patterns': '*.lua', 'file_patterns': '*.lua',
'fn_name_prefix': '', 'fn_name_prefix': '',
'section_name': {'lsp.lua': 'lsp'}, 'section_name': {'lsp.lua': 'lsp'},
@@ -214,11 +210,10 @@ CONFIG = {
'diagnostic': { 'diagnostic': {
'mode': 'lua', 'mode': 'lua',
'filename': 'diagnostic.txt', 'filename': 'diagnostic.txt',
'section_start_token': '*diagnostic-api*',
'section_order': [ 'section_order': [
'diagnostic.lua', 'diagnostic.lua',
], ],
'files': os.path.join(base_dir, 'runtime/lua/vim/diagnostic.lua'), 'files': ['runtime/lua/vim/diagnostic.lua'],
'file_patterns': '*.lua', 'file_patterns': '*.lua',
'fn_name_prefix': '', 'fn_name_prefix': '',
'section_name': {'diagnostic.lua': 'diagnostic'}, 'section_name': {'diagnostic.lua': 'diagnostic'},
@@ -231,7 +226,6 @@ CONFIG = {
'treesitter': { 'treesitter': {
'mode': 'lua', 'mode': 'lua',
'filename': 'treesitter.txt', 'filename': 'treesitter.txt',
'section_start_token': '*lua-treesitter-core*',
'section_order': [ 'section_order': [
'treesitter.lua', 'treesitter.lua',
'language.lua', 'language.lua',
@@ -239,10 +233,10 @@ CONFIG = {
'highlighter.lua', 'highlighter.lua',
'languagetree.lua', 'languagetree.lua',
], ],
'files': ' '.join([ 'files': [
os.path.join(base_dir, 'runtime/lua/vim/treesitter.lua'), 'runtime/lua/vim/treesitter.lua',
os.path.join(base_dir, 'runtime/lua/vim/treesitter/'), 'runtime/lua/vim/treesitter/',
]), ],
'file_patterns': '*.lua', 'file_patterns': '*.lua',
'fn_name_prefix': '', 'fn_name_prefix': '',
'section_name': {}, 'section_name': {},
@@ -349,14 +343,6 @@ def self_or_child(n):
return n.childNodes[0] return n.childNodes[0]
def clean_text(text):
"""Cleans text.
Only cleans superfluous whitespace at the moment.
"""
return ' '.join(text.split()).strip()
def clean_lines(text): def clean_lines(text):
"""Removes superfluous lines. """Removes superfluous lines.
@@ -380,9 +366,9 @@ def get_text(n, preformatted=False):
return '`{}`'.format(text) return '`{}`'.format(text)
for node in n.childNodes: for node in n.childNodes:
if node.nodeType == node.TEXT_NODE: if node.nodeType == node.TEXT_NODE:
text += node.data if preformatted else clean_text(node.data) text += node.data
elif node.nodeType == node.ELEMENT_NODE: elif node.nodeType == node.ELEMENT_NODE:
text += ' ' + get_text(node, preformatted) text += get_text(node, preformatted)
return text return text
@@ -849,7 +835,9 @@ def extract_from_xml(filename, target, width):
'seealso': [], 'seealso': [],
} }
if fmt_vimhelp: if fmt_vimhelp:
fn['desc_node'] = desc # HACK :( # HACK :(
fn['desc_node'] = desc
fn['brief_desc_node'] = brief_desc
for m in paras: for m in paras:
if 'text' in m: if 'text' in m:
@@ -897,6 +885,8 @@ def fmt_doxygen_xml_as_vimhelp(filename, target):
# Generate Vim :help for parameters. # Generate Vim :help for parameters.
if fn['desc_node']: if fn['desc_node']:
doc = fmt_node_as_vimhelp(fn['desc_node']) doc = fmt_node_as_vimhelp(fn['desc_node'])
if not doc and fn['brief_desc_node']:
doc = fmt_node_as_vimhelp(fn['brief_desc_node'])
if not doc: if not doc:
doc = 'TODO: Documentation' doc = 'TODO: Documentation'
@@ -1006,7 +996,8 @@ def main(config, args):
stderr=(subprocess.STDOUT if debug else subprocess.DEVNULL)) stderr=(subprocess.STDOUT if debug else subprocess.DEVNULL))
p.communicate( p.communicate(
config.format( config.format(
input=CONFIG[target]['files'], input=' '.join(
[f'"{file}"' for file in CONFIG[target]['files']]),
output=output_dir, output=output_dir,
filter=filter_cmd, filter=filter_cmd,
file_patterns=CONFIG[target]['file_patterns']) file_patterns=CONFIG[target]['file_patterns'])
@@ -1096,6 +1087,7 @@ def main(config, args):
raise RuntimeError( raise RuntimeError(
'found new modules "{}"; update the "section_order" map'.format( 'found new modules "{}"; update the "section_order" map'.format(
set(sections).difference(CONFIG[target]['section_order']))) set(sections).difference(CONFIG[target]['section_order'])))
first_section_tag = sections[CONFIG[target]['section_order'][0]][1]
docs = '' docs = ''
@@ -1121,7 +1113,8 @@ def main(config, args):
doc_file = os.path.join(base_dir, 'runtime', 'doc', doc_file = os.path.join(base_dir, 'runtime', 'doc',
CONFIG[target]['filename']) CONFIG[target]['filename'])
delete_lines_below(doc_file, CONFIG[target]['section_start_token']) if os.path.exists(doc_file):
delete_lines_below(doc_file, first_section_tag)
with open(doc_file, 'ab') as fp: with open(doc_file, 'ab') as fp:
fp.write(docs.encode('utf8')) fp.write(docs.encode('utf8'))