2018-06-29 15:46:05 -07:00
|
|
|
#!/usr/bin/env python3
|
2023-12-28 11:04:34 -07:00
|
|
|
|
|
|
|
r"""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:
|
2023-06-23 03:16:55 -07:00
|
|
|
:new | put=v:lua.vim.inspect(v:lua.vim.mpack.decode(readfile('runtime/doc/api.mpack','B')))
|
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
|
|
|
|
2022-10-14 08:01:13 -07:00
|
|
|
TODO: eliminate this script and use Lua+treesitter (requires parsers for C and
|
|
|
|
Lua markdown-style docstrings).
|
2017-01-03 05:11:19 -07:00
|
|
|
|
2022-10-14 08:01:13 -07:00
|
|
|
The generated :help text for each function 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).
|
2022-08-08 11:24:50 -07:00
|
|
|
- Indent of 4 columns for body text (`indentation`).
|
2019-11-17 23:49:28 -07:00
|
|
|
- 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.
|
|
|
|
"""
|
2023-12-28 11:04:34 -07:00
|
|
|
|
2024-01-04 09:09:13 -07:00
|
|
|
from __future__ import annotations # PEP-563, python 3.7+
|
2023-12-28 11:04:34 -07:00
|
|
|
|
2020-08-08 12:47:59 -07:00
|
|
|
import argparse
|
2023-12-28 11:04:34 -07:00
|
|
|
import collections
|
|
|
|
import dataclasses
|
|
|
|
import logging
|
2017-01-03 05:11:19 -07:00
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import shutil
|
|
|
|
import subprocess
|
2023-12-28 11:04:34 -07:00
|
|
|
import sys
|
|
|
|
import textwrap
|
2023-02-25 08:35:45 -07:00
|
|
|
from pathlib import Path
|
2024-01-04 09:09:13 -07:00
|
|
|
from typing import Any, Callable, Dict, List, Tuple
|
2017-01-03 05:11:19 -07:00
|
|
|
from xml.dom import minidom
|
2023-12-28 11:04:34 -07:00
|
|
|
|
2024-01-04 09:09:13 -07:00
|
|
|
if sys.version_info >= (3, 8):
|
|
|
|
from typing import Literal
|
|
|
|
|
2023-12-28 11:04:34 -07:00
|
|
|
import msgpack
|
|
|
|
|
2023-07-17 02:39:52 -07:00
|
|
|
Element = minidom.Element
|
2023-07-17 07:22:44 -07:00
|
|
|
Document = minidom.Document
|
2017-01-03 05:11:19 -07:00
|
|
|
|
2023-12-28 11:04:34 -07:00
|
|
|
MIN_PYTHON_VERSION = (3, 7)
|
2022-05-01 08:53:22 -07:00
|
|
|
MIN_DOXYGEN_VERSION = (1, 9, 0)
|
2020-07-24 13:42:25 -07:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
2022-06-25 03:03:02 -07:00
|
|
|
doxygen_version = tuple((int(i) for i in subprocess.check_output(["doxygen", "-v"],
|
|
|
|
universal_newlines=True).split()[0].split('.')))
|
2022-05-01 08:53:22 -07:00
|
|
|
|
|
|
|
if doxygen_version < MIN_DOXYGEN_VERSION:
|
2022-05-02 02:14:34 -07:00
|
|
|
print("\nRequires doxygen {}.{}.{}+".format(*MIN_DOXYGEN_VERSION))
|
|
|
|
print("Your doxygen version is {}.{}.{}\n".format(*doxygen_version))
|
2022-05-01 08:53:22 -07:00
|
|
|
sys.exit(1)
|
|
|
|
|
2023-02-25 08:35:45 -07:00
|
|
|
|
2023-02-25 09:24:43 -07:00
|
|
|
# Need a `nvim` that supports `-l`, try the local build
|
|
|
|
nvim_path = Path(__file__).parent / "../build/bin/nvim"
|
|
|
|
if nvim_path.exists():
|
2023-12-28 11:04:34 -07:00
|
|
|
nvim = nvim_path.resolve()
|
2023-02-25 09:24:43 -07:00
|
|
|
else:
|
|
|
|
# Until 0.9 is released, use this hacky way to check that "nvim -l foo.lua" works.
|
|
|
|
nvim_out = subprocess.check_output(['nvim', '-h'], universal_newlines=True)
|
|
|
|
nvim_version = [line for line in nvim_out.split('\n')
|
|
|
|
if '-l ' in line]
|
|
|
|
if len(nvim_version) == 0:
|
|
|
|
print((
|
|
|
|
"\nYou need to have a local Neovim build or a `nvim` version 0.9 for `-l` "
|
|
|
|
"support to build the documentation."))
|
|
|
|
sys.exit(1)
|
|
|
|
nvim = 'nvim'
|
2021-09-20 19:00:50 -07:00
|
|
|
|
2023-02-25 08:35:45 -07:00
|
|
|
|
2021-02-28 07:49:43 -07:00
|
|
|
# DEBUG = ('DEBUG' in os.environ)
|
2023-12-29 04:32:37 -07:00
|
|
|
INCLUDE_C_DECL = os.environ.get('INCLUDE_C_DECL', '0') != '0'
|
|
|
|
INCLUDE_DEPRECATED = os.environ.get('INCLUDE_DEPRECATED', '0') != '0'
|
2019-03-03 07:01:16 -07:00
|
|
|
|
2021-02-28 07:49:43 -07:00
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
LOG_LEVELS = {
|
|
|
|
logging.getLevelName(level): level for level in [
|
|
|
|
logging.DEBUG, logging.INFO, logging.ERROR
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
2019-03-29 13:54:34 -07:00
|
|
|
text_width = 78
|
2022-08-08 11:24:50 -07:00
|
|
|
indentation = 4
|
2023-12-29 03:52:31 -07:00
|
|
|
SECTION_SEP = '=' * text_width
|
|
|
|
|
2019-03-29 13:54:34 -07:00
|
|
|
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)
|
2020-08-31 00:51:35 -07:00
|
|
|
msgs = [] # Messages to show on exit.
|
2021-09-20 19:00:50 -07:00
|
|
|
lua2dox = os.path.join(base_dir, 'scripts', 'lua2dox.lua')
|
2019-03-29 13:54:34 -07:00
|
|
|
|
2023-12-28 11:04:34 -07:00
|
|
|
|
|
|
|
SectionName = str
|
|
|
|
|
2023-12-28 12:11:13 -07:00
|
|
|
Docstring = str # Represents (formatted) vimdoc string
|
|
|
|
|
|
|
|
FunctionName = str
|
|
|
|
|
|
|
|
|
2023-12-28 11:04:34 -07:00
|
|
|
@dataclasses.dataclass
|
|
|
|
class Config:
|
|
|
|
"""Config for documentation."""
|
|
|
|
|
|
|
|
mode: Literal['c', 'lua']
|
|
|
|
|
|
|
|
filename: str
|
|
|
|
"""Generated documentation target, e.g. api.txt"""
|
|
|
|
|
|
|
|
section_order: List[str]
|
|
|
|
"""Section ordering."""
|
|
|
|
|
|
|
|
files: List[str]
|
|
|
|
"""List of files/directories for doxygen to read, relative to `base_dir`."""
|
|
|
|
|
|
|
|
file_patterns: str
|
|
|
|
"""file patterns used by doxygen."""
|
|
|
|
|
|
|
|
section_name: Dict[str, SectionName]
|
|
|
|
"""Section name overrides. Key: filename (e.g., vim.c)"""
|
|
|
|
|
|
|
|
section_fmt: Callable[[SectionName], str]
|
|
|
|
"""For generated section names."""
|
|
|
|
|
|
|
|
helptag_fmt: Callable[[SectionName], str]
|
|
|
|
"""Section helptag."""
|
|
|
|
|
|
|
|
fn_helptag_fmt: Callable[[str, str, bool], str]
|
|
|
|
"""Per-function helptag."""
|
|
|
|
|
|
|
|
module_override: Dict[str, str]
|
|
|
|
"""Module name overrides (for Lua)."""
|
|
|
|
|
|
|
|
append_only: List[str]
|
|
|
|
"""Append the docs for these modules, do not start a new section."""
|
|
|
|
|
|
|
|
fn_name_prefix: str
|
|
|
|
"""Only function with this prefix are considered"""
|
|
|
|
|
|
|
|
fn_name_fmt: Callable[[str, str], str] | None = None
|
|
|
|
|
|
|
|
include_tables: bool = True
|
|
|
|
|
|
|
|
|
|
|
|
CONFIG: Dict[str, Config] = {
|
|
|
|
'api': Config(
|
2024-01-04 09:09:13 -07:00
|
|
|
mode='c',
|
2023-12-28 11:04:34 -07:00
|
|
|
filename = 'api.txt',
|
2019-07-28 19:43:28 -07:00
|
|
|
# Section ordering.
|
2023-12-29 04:32:37 -07:00
|
|
|
section_order=[x for x in [
|
2019-07-28 19:43:28 -07:00
|
|
|
'vim.c',
|
2021-10-26 06:10:17 -07:00
|
|
|
'vimscript.c',
|
2022-06-12 10:26:43 -07:00
|
|
|
'command.c',
|
|
|
|
'options.c',
|
2019-07-28 19:43:28 -07:00
|
|
|
'buffer.c',
|
2021-10-26 06:10:17 -07:00
|
|
|
'extmark.c',
|
2019-07-28 19:43:28 -07:00
|
|
|
'window.c',
|
2021-10-05 09:56:22 -07:00
|
|
|
'win_config.c',
|
2019-07-28 19:43:28 -07:00
|
|
|
'tabpage.c',
|
2021-05-28 12:45:34 -07:00
|
|
|
'autocmd.c',
|
2019-07-28 19:43:28 -07:00
|
|
|
'ui.c',
|
2023-12-29 04:32:37 -07:00
|
|
|
'deprecated.c' if INCLUDE_DEPRECATED else ''
|
|
|
|
] if x],
|
2023-12-28 11:04:34 -07:00
|
|
|
files=['src/nvim/api'],
|
|
|
|
file_patterns = '*.h *.c',
|
|
|
|
fn_name_prefix = 'nvim_',
|
|
|
|
section_name={
|
2019-07-28 19:43:28 -07:00
|
|
|
'vim.c': 'Global',
|
|
|
|
},
|
2023-12-28 11:04:34 -07:00
|
|
|
section_fmt=lambda name: f'{name} Functions',
|
|
|
|
helptag_fmt=lambda name: f'*api-{name.lower()}*',
|
|
|
|
fn_helptag_fmt=lambda fstem, name, istbl: f'*{name}()*',
|
|
|
|
module_override={},
|
|
|
|
append_only=[],
|
|
|
|
),
|
|
|
|
'lua': Config(
|
|
|
|
mode='lua',
|
|
|
|
filename='lua.txt',
|
|
|
|
section_order=[
|
2023-07-15 08:55:32 -07:00
|
|
|
'highlight.lua',
|
|
|
|
'regex.lua',
|
|
|
|
'diff.lua',
|
|
|
|
'mpack.lua',
|
|
|
|
'json.lua',
|
2023-10-31 07:15:32 -07:00
|
|
|
'base64.lua',
|
2023-07-15 08:55:32 -07:00
|
|
|
'spell.lua',
|
|
|
|
'builtin.lua',
|
|
|
|
'_options.lua',
|
2022-03-06 06:16:21 -07:00
|
|
|
'_editor.lua',
|
2022-12-14 02:46:54 -07:00
|
|
|
'_inspector.lua',
|
2019-07-28 19:43:28 -07:00
|
|
|
'shared.lua',
|
2023-03-26 03:42:15 -07:00
|
|
|
'loader.lua',
|
2020-09-14 06:12:17 -07:00
|
|
|
'uri.lua',
|
2021-09-27 12:57:28 -07:00
|
|
|
'ui.lua',
|
2022-01-04 07:28:29 -07:00
|
|
|
'filetype.lua',
|
feat(lua): add vim.keymap
This introduces two new functions `vim.keymap.set` & `vim.keymap.del`
differences compared to regular set_keymap:
- remap is used as opposite of noremap. By default it's true for <Plug> keymaps and false for others.
- rhs can be lua function.
- mode can be a list of modes.
- replace_keycodes option for lua function expr maps. (Default: true)
- handles buffer specific keymaps
Examples:
```lua
vim.keymap.set('n', 'asdf', function() print("real lua function") end)
vim.keymap.set({'n', 'v'}, '<leader>lr', vim.lsp.buf.references, {buffer=true})
vim.keymap.set('n', '<leader>w', "<cmd>w<cr>", {silent = true, buffer = 5 })
vim.keymap.set('i', '<Tab>', function()
return vim.fn.pumvisible() == 1 and "<C-n>" or "<Tab>"
end, {expr = true})
vim.keymap.set('n', '[%', '<Plug>(MatchitNormalMultiBackward)')
vim.keymap.del('n', 'asdf')
vim.keymap.del({'n', 'i', 'v'}, '<leader>w', {buffer = 5 })
```
2021-12-30 00:30:49 -07:00
|
|
|
'keymap.lua',
|
2022-05-15 13:38:19 -07:00
|
|
|
'fs.lua',
|
2024-01-02 06:32:43 -07:00
|
|
|
'glob.lua',
|
2022-11-05 12:37:05 -07:00
|
|
|
'secure.lua',
|
2023-02-19 04:33:57 -07:00
|
|
|
'version.lua',
|
2023-04-17 11:54:19 -07:00
|
|
|
'iter.lua',
|
2023-10-20 23:51:26 -07:00
|
|
|
'snippet.lua',
|
2023-11-16 10:35:54 -07:00
|
|
|
'text.lua',
|
2019-07-28 19:43:28 -07:00
|
|
|
],
|
2023-12-28 11:04:34 -07:00
|
|
|
files=[
|
2023-04-17 11:54:19 -07:00
|
|
|
'runtime/lua/vim/iter.lua',
|
2022-03-13 05:30:06 -07:00
|
|
|
'runtime/lua/vim/_editor.lua',
|
2023-07-15 08:55:32 -07:00
|
|
|
'runtime/lua/vim/_options.lua',
|
2022-03-13 05:30:06 -07:00
|
|
|
'runtime/lua/vim/shared.lua',
|
2023-03-26 03:42:15 -07:00
|
|
|
'runtime/lua/vim/loader.lua',
|
2022-03-13 05:30:06 -07:00
|
|
|
'runtime/lua/vim/uri.lua',
|
|
|
|
'runtime/lua/vim/ui.lua',
|
|
|
|
'runtime/lua/vim/filetype.lua',
|
|
|
|
'runtime/lua/vim/keymap.lua',
|
2022-05-15 13:38:19 -07:00
|
|
|
'runtime/lua/vim/fs.lua',
|
2023-07-15 08:55:32 -07:00
|
|
|
'runtime/lua/vim/highlight.lua',
|
2022-11-05 12:37:05 -07:00
|
|
|
'runtime/lua/vim/secure.lua',
|
2023-02-19 04:33:57 -07:00
|
|
|
'runtime/lua/vim/version.lua',
|
2022-12-14 02:46:54 -07:00
|
|
|
'runtime/lua/vim/_inspector.lua',
|
2023-10-20 23:51:26 -07:00
|
|
|
'runtime/lua/vim/snippet.lua',
|
2023-11-16 10:35:54 -07:00
|
|
|
'runtime/lua/vim/text.lua',
|
2024-01-02 06:32:43 -07:00
|
|
|
'runtime/lua/vim/glob.lua',
|
2023-07-15 08:55:32 -07:00
|
|
|
'runtime/lua/vim/_meta/builtin.lua',
|
|
|
|
'runtime/lua/vim/_meta/diff.lua',
|
|
|
|
'runtime/lua/vim/_meta/mpack.lua',
|
|
|
|
'runtime/lua/vim/_meta/json.lua',
|
2023-10-31 07:15:32 -07:00
|
|
|
'runtime/lua/vim/_meta/base64.lua',
|
2023-07-15 08:55:32 -07:00
|
|
|
'runtime/lua/vim/_meta/regex.lua',
|
|
|
|
'runtime/lua/vim/_meta/spell.lua',
|
2022-03-13 05:30:06 -07:00
|
|
|
],
|
2023-12-28 11:04:34 -07:00
|
|
|
file_patterns='*.lua',
|
|
|
|
fn_name_prefix='',
|
|
|
|
fn_name_fmt=lambda fstem, name: (
|
2023-07-15 08:55:32 -07:00
|
|
|
name if fstem in [ 'vim.iter' ] else
|
|
|
|
f'vim.{name}' if fstem in [ '_editor', 'vim.regex'] else
|
2023-07-18 07:42:30 -07:00
|
|
|
f'vim.{name}' if fstem == '_options' and not name[0].isupper() else
|
2023-07-15 08:55:32 -07:00
|
|
|
f'{fstem}.{name}' if fstem.startswith('vim') else
|
|
|
|
name
|
|
|
|
),
|
2023-12-28 11:04:34 -07:00
|
|
|
section_name={
|
2019-12-31 07:52:14 -07:00
|
|
|
'lsp.lua': 'core',
|
2022-12-14 02:46:54 -07:00
|
|
|
'_inspector.lua': 'inspector',
|
2019-12-31 07:52:14 -07:00
|
|
|
},
|
2023-12-28 11:04:34 -07:00
|
|
|
section_fmt=lambda name: (
|
2023-07-15 08:55:32 -07:00
|
|
|
'Lua module: vim' if name.lower() == '_editor' else
|
|
|
|
'LUA-VIMSCRIPT BRIDGE' if name.lower() == '_options' else
|
2023-10-31 07:15:32 -07:00
|
|
|
f'VIM.{name.upper()}' if name.lower() in [ 'highlight', 'mpack', 'json', 'base64', 'diff', 'spell', 'regex' ] else
|
2023-07-15 08:55:32 -07:00
|
|
|
'VIM' if name.lower() == 'builtin' else
|
|
|
|
f'Lua module: vim.{name.lower()}'),
|
2023-12-28 11:04:34 -07:00
|
|
|
helptag_fmt=lambda name: (
|
2023-07-15 08:55:32 -07:00
|
|
|
'*lua-vim*' if name.lower() == '_editor' else
|
|
|
|
'*lua-vimscript*' if name.lower() == '_options' else
|
2023-07-17 07:13:54 -07:00
|
|
|
f'*vim.{name.lower()}*'),
|
2023-12-28 11:04:34 -07:00
|
|
|
fn_helptag_fmt=lambda fstem, name, istbl: (
|
2023-07-15 08:55:32 -07:00
|
|
|
f'*vim.opt:{name.split(":")[-1]}()*' if ':' in name and name.startswith('Option') else
|
|
|
|
# Exclude fstem for methods
|
|
|
|
f'*{name}()*' if ':' in name else
|
|
|
|
f'*vim.{name}()*' if fstem.lower() == '_editor' else
|
2023-07-18 07:42:30 -07:00
|
|
|
f'*vim.{name}*' if fstem.lower() == '_options' and istbl else
|
2023-07-15 08:55:32 -07:00
|
|
|
# Prevents vim.regex.regex
|
|
|
|
f'*{fstem}()*' if fstem.endswith('.' + name) else
|
2023-07-18 07:42:30 -07:00
|
|
|
f'*{fstem}.{name}{"" if istbl else "()"}*'
|
2023-07-15 08:55:32 -07:00
|
|
|
),
|
2023-12-28 11:04:34 -07:00
|
|
|
module_override={
|
2019-07-28 19:43:28 -07:00
|
|
|
# `shared` functions are exposed on the `vim` module.
|
|
|
|
'shared': 'vim',
|
2022-12-14 02:46:54 -07:00
|
|
|
'_inspector': 'vim',
|
2020-09-14 06:12:17 -07:00
|
|
|
'uri': 'vim',
|
2021-09-27 12:57:28 -07:00
|
|
|
'ui': 'vim.ui',
|
2023-03-26 03:42:15 -07:00
|
|
|
'loader': 'vim.loader',
|
2022-01-04 07:28:29 -07:00
|
|
|
'filetype': 'vim.filetype',
|
feat(lua): add vim.keymap
This introduces two new functions `vim.keymap.set` & `vim.keymap.del`
differences compared to regular set_keymap:
- remap is used as opposite of noremap. By default it's true for <Plug> keymaps and false for others.
- rhs can be lua function.
- mode can be a list of modes.
- replace_keycodes option for lua function expr maps. (Default: true)
- handles buffer specific keymaps
Examples:
```lua
vim.keymap.set('n', 'asdf', function() print("real lua function") end)
vim.keymap.set({'n', 'v'}, '<leader>lr', vim.lsp.buf.references, {buffer=true})
vim.keymap.set('n', '<leader>w', "<cmd>w<cr>", {silent = true, buffer = 5 })
vim.keymap.set('i', '<Tab>', function()
return vim.fn.pumvisible() == 1 and "<C-n>" or "<Tab>"
end, {expr = true})
vim.keymap.set('n', '[%', '<Plug>(MatchitNormalMultiBackward)')
vim.keymap.del('n', 'asdf')
vim.keymap.del({'n', 'i', 'v'}, '<leader>w', {buffer = 5 })
```
2021-12-30 00:30:49 -07:00
|
|
|
'keymap': 'vim.keymap',
|
2022-05-15 13:38:19 -07:00
|
|
|
'fs': 'vim.fs',
|
2023-07-15 08:55:32 -07:00
|
|
|
'highlight': 'vim.highlight',
|
2022-11-05 12:37:05 -07:00
|
|
|
'secure': 'vim.secure',
|
2023-03-06 05:23:03 -07:00
|
|
|
'version': 'vim.version',
|
2023-04-24 18:57:40 -07:00
|
|
|
'iter': 'vim.iter',
|
2023-07-15 08:55:32 -07:00
|
|
|
'diff': 'vim',
|
|
|
|
'builtin': 'vim',
|
|
|
|
'mpack': 'vim.mpack',
|
|
|
|
'json': 'vim.json',
|
2023-10-31 07:15:32 -07:00
|
|
|
'base64': 'vim.base64',
|
2023-07-15 08:55:32 -07:00
|
|
|
'regex': 'vim.regex',
|
|
|
|
'spell': 'vim.spell',
|
2023-11-16 09:53:25 -07:00
|
|
|
'snippet': 'vim.snippet',
|
2023-11-16 10:35:54 -07:00
|
|
|
'text': 'vim.text',
|
2024-01-02 06:32:43 -07:00
|
|
|
'glob': 'vim.glob',
|
2019-07-28 19:43:28 -07:00
|
|
|
},
|
2023-12-28 11:04:34 -07:00
|
|
|
append_only=[
|
2019-07-28 19:43:28 -07:00
|
|
|
'shared.lua',
|
|
|
|
],
|
2023-12-28 11:04:34 -07:00
|
|
|
),
|
|
|
|
'lsp': Config(
|
|
|
|
mode='lua',
|
|
|
|
filename='lsp.txt',
|
|
|
|
section_order=[
|
2019-12-31 07:52:14 -07:00
|
|
|
'lsp.lua',
|
|
|
|
'buf.lua',
|
lsp: vim.lsp.diagnostic (#12655)
Breaking Changes:
- Deprecated all `vim.lsp.util.{*diagnostics*}()` functions.
- Instead, all functions must be found in vim.lsp.diagnostic
- For now, they issue a warning ONCE per neovim session. In a
"little while" we will remove them completely.
- `vim.lsp.callbacks` has moved to `vim.lsp.handlers`.
- For a "little while" we will just redirect `vim.lsp.callbacks` to
`vim.lsp.handlers`. However, we will remove this at some point, so
it is recommended that you change all of your references to
`callbacks` into `handlers`.
- This also means that for functions like |vim.lsp.start_client()|
and similar, keyword style arguments have moved from "callbacks"
to "handlers". Once again, these are currently being forward, but
will cease to be forwarded in a "little while".
- Changed the highlight groups for LspDiagnostic highlight as they were
inconsistently named.
- For more information, see |lsp-highlight-diagnostics|
- Changed the sign group names as well, to be consistent with
|lsp-highlight-diagnostics|
General Enhancements:
- Rewrote much of the getting started help document for lsp. It also
provides a much nicer configuration strategy, so as to not recommend
globally overwriting builtin neovim mappings.
LSP Enhancements:
- Introduced the concept of |lsp-handlers| which will allow much better
customization for users without having to copy & paste entire files /
functions / etc.
Diagnostic Enhancements:
- "goto next diagnostic" |vim.lsp.diagnostic.goto_next()|
- "goto prev diagnostic" |vim.lsp.diagnostic.goto_prev()|
- For each of the gotos, auto open diagnostics is available as a
configuration option
- Configurable diagnostic handling:
- See |vim.lsp.diagnostic.on_publish_diagnostics()|
- Delay display until after insert mode
- Configure signs
- Configure virtual text
- Configure underline
- Set the location list with the buffers diagnostics.
- See |vim.lsp.diagnostic.set_loclist()|
- Better performance for getting counts and line diagnostics
- They are now cached on save, to enhance lookups.
- Particularly useful for checking in statusline, etc.
- Actual testing :)
- See ./test/functional/plugin/lsp/diagnostic_spec.lua
- Added `guisp` for underline highlighting
NOTE: "a little while" means enough time to feel like most plugins and
plugin authors have had a chance to refactor their code to use the
updated calls. Then we will remove them completely. There is no need to
keep them, because we don't have any released version of neovim that
exposes these APIs. I'm trying to be nice to people following HEAD :)
Co-authored: [Twitch Chat 2020](https://twitch.tv/teej_dv)
2020-11-12 20:21:34 -07:00
|
|
|
'diagnostic.lua',
|
2020-10-26 03:50:57 -07:00
|
|
|
'codelens.lua',
|
2023-11-12 05:54:27 -07:00
|
|
|
'inlay_hint.lua',
|
2021-11-18 10:29:25 -07:00
|
|
|
'tagfunc.lua',
|
2022-11-23 09:06:36 -07:00
|
|
|
'semantic_tokens.lua',
|
lsp: vim.lsp.diagnostic (#12655)
Breaking Changes:
- Deprecated all `vim.lsp.util.{*diagnostics*}()` functions.
- Instead, all functions must be found in vim.lsp.diagnostic
- For now, they issue a warning ONCE per neovim session. In a
"little while" we will remove them completely.
- `vim.lsp.callbacks` has moved to `vim.lsp.handlers`.
- For a "little while" we will just redirect `vim.lsp.callbacks` to
`vim.lsp.handlers`. However, we will remove this at some point, so
it is recommended that you change all of your references to
`callbacks` into `handlers`.
- This also means that for functions like |vim.lsp.start_client()|
and similar, keyword style arguments have moved from "callbacks"
to "handlers". Once again, these are currently being forward, but
will cease to be forwarded in a "little while".
- Changed the highlight groups for LspDiagnostic highlight as they were
inconsistently named.
- For more information, see |lsp-highlight-diagnostics|
- Changed the sign group names as well, to be consistent with
|lsp-highlight-diagnostics|
General Enhancements:
- Rewrote much of the getting started help document for lsp. It also
provides a much nicer configuration strategy, so as to not recommend
globally overwriting builtin neovim mappings.
LSP Enhancements:
- Introduced the concept of |lsp-handlers| which will allow much better
customization for users without having to copy & paste entire files /
functions / etc.
Diagnostic Enhancements:
- "goto next diagnostic" |vim.lsp.diagnostic.goto_next()|
- "goto prev diagnostic" |vim.lsp.diagnostic.goto_prev()|
- For each of the gotos, auto open diagnostics is available as a
configuration option
- Configurable diagnostic handling:
- See |vim.lsp.diagnostic.on_publish_diagnostics()|
- Delay display until after insert mode
- Configure signs
- Configure virtual text
- Configure underline
- Set the location list with the buffers diagnostics.
- See |vim.lsp.diagnostic.set_loclist()|
- Better performance for getting counts and line diagnostics
- They are now cached on save, to enhance lookups.
- Particularly useful for checking in statusline, etc.
- Actual testing :)
- See ./test/functional/plugin/lsp/diagnostic_spec.lua
- Added `guisp` for underline highlighting
NOTE: "a little while" means enough time to feel like most plugins and
plugin authors have had a chance to refactor their code to use the
updated calls. Then we will remove them completely. There is no need to
keep them, because we don't have any released version of neovim that
exposes these APIs. I'm trying to be nice to people following HEAD :)
Co-authored: [Twitch Chat 2020](https://twitch.tv/teej_dv)
2020-11-12 20:21:34 -07:00
|
|
|
'handlers.lua',
|
|
|
|
'util.lua',
|
2019-12-31 07:52:14 -07:00
|
|
|
'log.lua',
|
|
|
|
'rpc.lua',
|
lsp: vim.lsp.diagnostic (#12655)
Breaking Changes:
- Deprecated all `vim.lsp.util.{*diagnostics*}()` functions.
- Instead, all functions must be found in vim.lsp.diagnostic
- For now, they issue a warning ONCE per neovim session. In a
"little while" we will remove them completely.
- `vim.lsp.callbacks` has moved to `vim.lsp.handlers`.
- For a "little while" we will just redirect `vim.lsp.callbacks` to
`vim.lsp.handlers`. However, we will remove this at some point, so
it is recommended that you change all of your references to
`callbacks` into `handlers`.
- This also means that for functions like |vim.lsp.start_client()|
and similar, keyword style arguments have moved from "callbacks"
to "handlers". Once again, these are currently being forward, but
will cease to be forwarded in a "little while".
- Changed the highlight groups for LspDiagnostic highlight as they were
inconsistently named.
- For more information, see |lsp-highlight-diagnostics|
- Changed the sign group names as well, to be consistent with
|lsp-highlight-diagnostics|
General Enhancements:
- Rewrote much of the getting started help document for lsp. It also
provides a much nicer configuration strategy, so as to not recommend
globally overwriting builtin neovim mappings.
LSP Enhancements:
- Introduced the concept of |lsp-handlers| which will allow much better
customization for users without having to copy & paste entire files /
functions / etc.
Diagnostic Enhancements:
- "goto next diagnostic" |vim.lsp.diagnostic.goto_next()|
- "goto prev diagnostic" |vim.lsp.diagnostic.goto_prev()|
- For each of the gotos, auto open diagnostics is available as a
configuration option
- Configurable diagnostic handling:
- See |vim.lsp.diagnostic.on_publish_diagnostics()|
- Delay display until after insert mode
- Configure signs
- Configure virtual text
- Configure underline
- Set the location list with the buffers diagnostics.
- See |vim.lsp.diagnostic.set_loclist()|
- Better performance for getting counts and line diagnostics
- They are now cached on save, to enhance lookups.
- Particularly useful for checking in statusline, etc.
- Actual testing :)
- See ./test/functional/plugin/lsp/diagnostic_spec.lua
- Added `guisp` for underline highlighting
NOTE: "a little while" means enough time to feel like most plugins and
plugin authors have had a chance to refactor their code to use the
updated calls. Then we will remove them completely. There is no need to
keep them, because we don't have any released version of neovim that
exposes these APIs. I'm trying to be nice to people following HEAD :)
Co-authored: [Twitch Chat 2020](https://twitch.tv/teej_dv)
2020-11-12 20:21:34 -07:00
|
|
|
'protocol.lua',
|
2019-12-31 07:52:14 -07:00
|
|
|
],
|
2023-12-28 11:04:34 -07:00
|
|
|
files=[
|
2022-03-13 05:30:06 -07:00
|
|
|
'runtime/lua/vim/lsp',
|
|
|
|
'runtime/lua/vim/lsp.lua',
|
|
|
|
],
|
2023-12-28 11:04:34 -07:00
|
|
|
file_patterns='*.lua',
|
|
|
|
fn_name_prefix='',
|
|
|
|
section_name={'lsp.lua': 'lsp'},
|
|
|
|
section_fmt=lambda name: (
|
2019-12-31 08:12:10 -07:00
|
|
|
'Lua module: vim.lsp'
|
2019-12-31 07:52:14 -07:00
|
|
|
if name.lower() == 'lsp'
|
|
|
|
else f'Lua module: vim.lsp.{name.lower()}'),
|
2023-12-28 11:04:34 -07:00
|
|
|
helptag_fmt=lambda name: (
|
2019-12-31 08:12:10 -07:00
|
|
|
'*lsp-core*'
|
2019-12-31 07:52:14 -07:00
|
|
|
if name.lower() == 'lsp'
|
|
|
|
else f'*lsp-{name.lower()}*'),
|
2023-12-28 11:04:34 -07:00
|
|
|
fn_helptag_fmt=lambda fstem, name, istbl: (
|
2023-07-18 07:42:30 -07:00
|
|
|
f'*vim.lsp.{name}{"" if istbl else "()"}*' if fstem == 'lsp' and name != 'client' else
|
|
|
|
# HACK. TODO(justinmk): class/structure support in lua2dox
|
|
|
|
'*vim.lsp.client*' if 'lsp.client' == f'{fstem}.{name}' else
|
|
|
|
f'*vim.lsp.{fstem}.{name}{"" if istbl else "()"}*'),
|
2023-12-28 11:04:34 -07:00
|
|
|
module_override={},
|
|
|
|
append_only=[],
|
|
|
|
),
|
|
|
|
'diagnostic': Config(
|
|
|
|
mode='lua',
|
|
|
|
filename='diagnostic.txt',
|
|
|
|
section_order=[
|
2021-09-06 19:21:18 -07:00
|
|
|
'diagnostic.lua',
|
|
|
|
],
|
2023-12-28 11:04:34 -07:00
|
|
|
files=['runtime/lua/vim/diagnostic.lua'],
|
|
|
|
file_patterns='*.lua',
|
|
|
|
fn_name_prefix='',
|
|
|
|
include_tables=False,
|
|
|
|
section_name={'diagnostic.lua': 'diagnostic'},
|
|
|
|
section_fmt=lambda _: 'Lua module: vim.diagnostic',
|
|
|
|
helptag_fmt=lambda _: '*diagnostic-api*',
|
|
|
|
fn_helptag_fmt=lambda fstem, name, istbl: f'*vim.{fstem}.{name}{"" if istbl else "()"}*',
|
|
|
|
module_override={},
|
|
|
|
append_only=[],
|
|
|
|
),
|
|
|
|
'treesitter': Config(
|
|
|
|
mode='lua',
|
|
|
|
filename='treesitter.txt',
|
|
|
|
section_order=[
|
2021-05-01 05:19:48 -07:00
|
|
|
'treesitter.lua',
|
|
|
|
'language.lua',
|
|
|
|
'query.lua',
|
|
|
|
'highlighter.lua',
|
|
|
|
'languagetree.lua',
|
2023-06-06 08:23:20 -07:00
|
|
|
'dev.lua',
|
2021-05-01 05:19:48 -07:00
|
|
|
],
|
2023-12-28 11:04:34 -07:00
|
|
|
files=[
|
2022-03-13 05:30:06 -07:00
|
|
|
'runtime/lua/vim/treesitter.lua',
|
|
|
|
'runtime/lua/vim/treesitter/',
|
|
|
|
],
|
2023-12-28 11:04:34 -07:00
|
|
|
file_patterns='*.lua',
|
|
|
|
fn_name_prefix='',
|
|
|
|
section_name={},
|
|
|
|
section_fmt=lambda name: (
|
2021-05-01 05:19:48 -07:00
|
|
|
'Lua module: vim.treesitter'
|
|
|
|
if name.lower() == 'treesitter'
|
|
|
|
else f'Lua module: vim.treesitter.{name.lower()}'),
|
2023-12-28 11:04:34 -07:00
|
|
|
helptag_fmt=lambda name: (
|
2021-05-01 05:19:48 -07:00
|
|
|
'*lua-treesitter-core*'
|
|
|
|
if name.lower() == 'treesitter'
|
2022-09-14 02:08:31 -07:00
|
|
|
else f'*lua-treesitter-{name.lower()}*'),
|
2023-12-28 11:04:34 -07:00
|
|
|
fn_helptag_fmt=lambda fstem, name, istbl: (
|
2022-12-07 01:27:41 -07:00
|
|
|
f'*vim.{fstem}.{name}()*'
|
|
|
|
if fstem == 'treesitter'
|
|
|
|
else f'*{name}()*'
|
|
|
|
if name[0].isupper()
|
2023-03-24 07:43:14 -07:00
|
|
|
else f'*vim.treesitter.{fstem}.{name}()*'),
|
2023-12-28 11:04:34 -07:00
|
|
|
module_override={},
|
|
|
|
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 = {
|
2022-04-30 16:16:16 -07:00
|
|
|
'FUNC_API_FAST': '|api-fast|',
|
2023-04-20 13:17:25 -07:00
|
|
|
'FUNC_API_TEXTLOCK': 'not allowed when |textlock| is active or in the |cmdwin|',
|
|
|
|
'FUNC_API_TEXTLOCK_ALLOW_CMDWIN': 'not allowed when |textlock| is active',
|
2022-04-30 16:16:16 -07:00
|
|
|
'FUNC_API_REMOTE_ONLY': '|RPC| only',
|
2022-10-09 05:21:52 -07:00
|
|
|
'FUNC_API_LUA_ONLY': 'Lua |vim.api| only',
|
2017-03-01 09:55:34 -07:00
|
|
|
}
|
|
|
|
|
2017-01-03 05:11:19 -07:00
|
|
|
|
2023-11-27 09:23:04 -07:00
|
|
|
def nvim_api_info() -> Tuple[int, bool]:
|
|
|
|
"""Returns NVIM_API_LEVEL, NVIM_API_PRERELEASE from CMakeLists.txt"""
|
|
|
|
if not hasattr(nvim_api_info, 'LEVEL'):
|
|
|
|
script_dir = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
cmake_file_path = os.path.join(script_dir, '..', 'CMakeLists.txt')
|
|
|
|
with open(cmake_file_path, 'r') as cmake_file:
|
|
|
|
cmake_content = cmake_file.read()
|
|
|
|
|
|
|
|
api_level_match = re.search(r'set\(NVIM_API_LEVEL (\d+)\)', cmake_content)
|
|
|
|
api_prerelease_match = re.search(
|
|
|
|
r'set\(NVIM_API_PRERELEASE (\w+)\)', cmake_content
|
|
|
|
)
|
|
|
|
|
|
|
|
if not api_level_match or not api_prerelease_match:
|
|
|
|
raise RuntimeError(
|
|
|
|
'Could not find NVIM_API_LEVEL or NVIM_API_PRERELEASE in CMakeLists.txt'
|
|
|
|
)
|
|
|
|
|
|
|
|
nvim_api_info.LEVEL = int(api_level_match.group(1))
|
|
|
|
nvim_api_info.PRERELEASE = api_prerelease_match.group(1).lower() == 'true'
|
|
|
|
|
|
|
|
return nvim_api_info.LEVEL, nvim_api_info.PRERELEASE
|
|
|
|
|
|
|
|
|
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 = ''
|
2022-09-25 04:45:41 -07:00
|
|
|
if cond is False:
|
|
|
|
return
|
2019-11-17 23:49:28 -07:00
|
|
|
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
|
2022-09-25 04:45:41 -07:00
|
|
|
if (cond is True
|
|
|
|
or (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]
|
|
|
|
|
|
|
|
|
2022-12-14 02:46:54 -07:00
|
|
|
def align_tags(line):
|
|
|
|
tag_regex = r"\s(\*.+?\*)(?:\s|$)"
|
|
|
|
tags = re.findall(tag_regex, line)
|
|
|
|
|
|
|
|
if len(tags) > 0:
|
|
|
|
line = re.sub(tag_regex, "", line)
|
|
|
|
tags = " " + " ".join(tags)
|
|
|
|
line = line + (" " * (78 - len(line) - len(tags))) + tags
|
|
|
|
return line
|
|
|
|
|
|
|
|
|
2017-01-03 05:11:19 -07:00
|
|
|
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)
|
|
|
|
|
|
|
|
|
2023-09-13 06:38:28 -07:00
|
|
|
def get_text(n):
|
2019-12-24 01:04:14 -07:00
|
|
|
"""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)
|
2022-03-13 05:48:14 -07:00
|
|
|
return '`{}`'.format(text)
|
2023-09-13 06:38:28 -07:00
|
|
|
if n.nodeName == 'sp': # space, used in "programlisting" nodes
|
|
|
|
return ' '
|
2019-12-24 01:04:14 -07:00
|
|
|
for node in n.childNodes:
|
2017-01-03 05:11:19 -07:00
|
|
|
if node.nodeType == node.TEXT_NODE:
|
2022-03-13 05:48:14 -07:00
|
|
|
text += node.data
|
2017-01-03 05:11:19 -07:00
|
|
|
elif node.nodeType == node.ELEMENT_NODE:
|
2023-09-13 06:38:28 -07:00
|
|
|
text += get_text(node)
|
2019-12-24 01:04:14 -07:00
|
|
|
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
|
|
|
|
2024-01-04 09:09:13 -07:00
|
|
|
def doc_wrap(text, prefix='', width=70, func=False, indent=None) -> str:
|
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)
|
|
|
|
|
|
|
|
|
2022-08-08 11:24:50 -07:00
|
|
|
def update_params_map(parent, ret_map, width=text_width - indentation):
|
2019-11-17 23:49:28 -07:00
|
|
|
"""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
|
|
|
|
2024-01-04 09:09:13 -07:00
|
|
|
def render_node(n: Element, text: str, prefix='', *,
|
|
|
|
indent: str = '',
|
|
|
|
width: int = (text_width - indentation),
|
|
|
|
fmt_vimhelp: bool = False):
|
2019-07-28 19:43:49 -07:00
|
|
|
"""Renders a node as Vim help text, recursively traversing all descendants."""
|
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
|
|
|
|
2024-01-04 09:09:13 -07:00
|
|
|
# Get the current column offset from the last line of `text`
|
|
|
|
# (needed to appropriately wrap multiple and contiguous inline elements)
|
|
|
|
col_offset: int = len_lastline(text)
|
|
|
|
|
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':
|
2023-09-13 06:38:28 -07:00
|
|
|
o = get_text(n)
|
2019-04-27 09:25:55 -07:00
|
|
|
ensure_nl = '' if o[-1] == '\n' else '\n'
|
2022-11-23 04:31:49 -07:00
|
|
|
if o[0:4] == 'lua\n':
|
|
|
|
text += '>lua{}{}\n<'.format(ensure_nl, o[3:-1])
|
|
|
|
elif o[0:4] == 'vim\n':
|
|
|
|
text += '>vim{}{}\n<'.format(ensure_nl, o[3:-1])
|
2023-07-15 08:55:32 -07:00
|
|
|
elif o[0:5] == 'help\n':
|
|
|
|
text += o[4:-1]
|
2022-11-23 04:31:49 -07:00
|
|
|
else:
|
|
|
|
text += '>{}{}\n<'.format(ensure_nl, o)
|
2023-09-13 06:38:28 -07:00
|
|
|
elif n.nodeName == 'programlisting': # codeblock (```)
|
|
|
|
o = get_text(n)
|
2023-09-14 06:23:01 -07:00
|
|
|
text += '>'
|
|
|
|
if 'filename' in n.attributes:
|
|
|
|
filename = n.attributes['filename'].value
|
|
|
|
text += filename.lstrip('.')
|
2020-07-02 04:09:17 -07:00
|
|
|
|
2023-09-14 06:23:01 -07:00
|
|
|
text += '\n{}\n<'.format(textwrap.indent(o, ' ' * 4))
|
2019-03-03 07:01:16 -07:00
|
|
|
elif is_inline(n):
|
2024-01-04 09:09:13 -07:00
|
|
|
o = get_text(n).strip()
|
|
|
|
if o:
|
|
|
|
DEL = chr(127) # a dummy character to pad for proper line wrap
|
|
|
|
assert len(DEL) == 1
|
|
|
|
dummy_padding = DEL * max(0, col_offset - len(prefix))
|
|
|
|
text += doc_wrap(dummy_padding + o,
|
|
|
|
prefix=prefix, indent=indent, width=width
|
|
|
|
).replace(DEL, "")
|
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'):
|
2023-03-15 04:51:44 -07:00
|
|
|
did_prefix = False
|
2019-03-03 07:01:16 -07:00
|
|
|
for c in n.childNodes:
|
2024-01-09 10:36:46 -07:00
|
|
|
c_text = render_node(c, text, prefix=(prefix if not did_prefix else ''), indent=indent, width=width)
|
2021-10-19 12:55:22 -07:00
|
|
|
if (is_inline(c)
|
2024-01-09 10:36:46 -07:00
|
|
|
and '' != c_text.strip()
|
2021-10-19 12:55:22 -07:00
|
|
|
and text
|
2024-01-09 10:36:46 -07:00
|
|
|
and text[-1] not in (' ', '(', '|')
|
|
|
|
and not c_text.startswith(')')):
|
2021-10-19 12:55:22 -07:00
|
|
|
text += ' '
|
2024-01-09 10:36:46 -07:00
|
|
|
text += c_text
|
2023-03-15 04:51:44 -07:00
|
|
|
did_prefix = True
|
2019-03-03 07:01:16 -07:00
|
|
|
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'):
|
2023-07-06 13:47:27 -07:00
|
|
|
text += ind(' ')
|
2019-03-03 07:01:16 -07:00
|
|
|
for c in n.childNodes:
|
2023-07-06 13:47:27 -07:00
|
|
|
if is_blank(render_node(c, text, prefix='• ', indent=' ', width=width)):
|
|
|
|
continue
|
|
|
|
text += render_node(c, text, prefix='• ', indent=' ', width=width)
|
|
|
|
# text += '\n'
|
2019-03-03 07:01:16 -07:00
|
|
|
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'
|
2023-03-15 04:51:44 -07:00
|
|
|
elif n.nodeName == 'simplesect' and 'see' == n.getAttribute('kind'):
|
|
|
|
text += ind(' ')
|
|
|
|
# Example:
|
|
|
|
# <simplesect kind="see">
|
|
|
|
# <para>|autocommand|</para>
|
|
|
|
# </simplesect>
|
|
|
|
for c in n.childNodes:
|
|
|
|
text += render_node(c, text, prefix='• ', indent=' ', width=width)
|
|
|
|
elif n.nodeName == 'simplesect' and 'return' == n.getAttribute('kind'):
|
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)
|
lsp: vim.lsp.diagnostic (#12655)
Breaking Changes:
- Deprecated all `vim.lsp.util.{*diagnostics*}()` functions.
- Instead, all functions must be found in vim.lsp.diagnostic
- For now, they issue a warning ONCE per neovim session. In a
"little while" we will remove them completely.
- `vim.lsp.callbacks` has moved to `vim.lsp.handlers`.
- For a "little while" we will just redirect `vim.lsp.callbacks` to
`vim.lsp.handlers`. However, we will remove this at some point, so
it is recommended that you change all of your references to
`callbacks` into `handlers`.
- This also means that for functions like |vim.lsp.start_client()|
and similar, keyword style arguments have moved from "callbacks"
to "handlers". Once again, these are currently being forward, but
will cease to be forwarded in a "little while".
- Changed the highlight groups for LspDiagnostic highlight as they were
inconsistently named.
- For more information, see |lsp-highlight-diagnostics|
- Changed the sign group names as well, to be consistent with
|lsp-highlight-diagnostics|
General Enhancements:
- Rewrote much of the getting started help document for lsp. It also
provides a much nicer configuration strategy, so as to not recommend
globally overwriting builtin neovim mappings.
LSP Enhancements:
- Introduced the concept of |lsp-handlers| which will allow much better
customization for users without having to copy & paste entire files /
functions / etc.
Diagnostic Enhancements:
- "goto next diagnostic" |vim.lsp.diagnostic.goto_next()|
- "goto prev diagnostic" |vim.lsp.diagnostic.goto_prev()|
- For each of the gotos, auto open diagnostics is available as a
configuration option
- Configurable diagnostic handling:
- See |vim.lsp.diagnostic.on_publish_diagnostics()|
- Delay display until after insert mode
- Configure signs
- Configure virtual text
- Configure underline
- Set the location list with the buffers diagnostics.
- See |vim.lsp.diagnostic.set_loclist()|
- Better performance for getting counts and line diagnostics
- They are now cached on save, to enhance lookups.
- Particularly useful for checking in statusline, etc.
- Actual testing :)
- See ./test/functional/plugin/lsp/diagnostic_spec.lua
- Added `guisp` for underline highlighting
NOTE: "a little while" means enough time to feel like most plugins and
plugin authors have had a chance to refactor their code to use the
updated calls. Then we will remove them completely. There is no need to
keep them, because we don't have any released version of neovim that
exposes these APIs. I'm trying to be nice to people following HEAD :)
Co-authored: [Twitch Chat 2020](https://twitch.tv/teej_dv)
2020-11-12 20:21:34 -07:00
|
|
|
elif n.nodeName == 'computeroutput':
|
|
|
|
return get_text(n)
|
2019-03-03 07:01:16 -07:00
|
|
|
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
|
|
|
|
2023-12-28 15:50:05 -07:00
|
|
|
def para_as_map(parent: Element,
|
|
|
|
indent: str = '',
|
|
|
|
width: int = (text_width - indentation),
|
|
|
|
):
|
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
|
2023-07-06 13:47:27 -07:00
|
|
|
'note': List of @note strings
|
2019-11-17 23:49:28 -07:00
|
|
|
'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': '',
|
2023-07-06 13:47:27 -07:00
|
|
|
'note': [],
|
2019-11-17 23:49:28 -07:00
|
|
|
'params': collections.OrderedDict(),
|
|
|
|
'return': [],
|
|
|
|
'seealso': [],
|
2023-11-27 09:23:04 -07:00
|
|
|
'prerelease': False,
|
2019-11-17 23:49:28 -07:00
|
|
|
'xrefs': []
|
|
|
|
}
|
|
|
|
|
2019-03-03 07:01:16 -07:00
|
|
|
# Ordered dict of ordered lists.
|
|
|
|
groups = collections.OrderedDict([
|
2023-07-06 13:47:27 -07:00
|
|
|
('note', []),
|
2019-03-03 07:01:16 -07:00
|
|
|
('params', []),
|
|
|
|
('return', []),
|
|
|
|
('seealso', []),
|
|
|
|
('xrefs', []),
|
|
|
|
])
|
|
|
|
|
|
|
|
# Gather nodes into groups. Mostly this is because we want "parameterlist"
|
|
|
|
# nodes to appear together.
|
|
|
|
text = ''
|
|
|
|
kind = ''
|
2019-12-24 01:04:14 -07:00
|
|
|
if is_inline(parent):
|
|
|
|
# Flatten inline text from a tree of non-block nodes.
|
2023-12-28 15:50:05 -07:00
|
|
|
text = doc_wrap(render_node(parent, ""),
|
2022-05-15 02:23:56 -07:00
|
|
|
indent=indent, width=width)
|
2019-12-24 01:04:14 -07:00
|
|
|
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':
|
|
|
|
kind = child.getAttribute('kind')
|
2023-07-06 13:47:27 -07:00
|
|
|
if kind == 'note':
|
|
|
|
groups['note'].append(child)
|
|
|
|
elif kind == 'return':
|
2019-12-24 01:04:14 -07:00
|
|
|
groups['return'].append(child)
|
|
|
|
elif kind == 'see':
|
|
|
|
groups['seealso'].append(child)
|
2023-07-06 13:47:27 -07:00
|
|
|
elif kind == 'warning':
|
2023-12-28 15:50:05 -07:00
|
|
|
text += render_node(child, text, indent=indent, width=width)
|
2023-11-27 09:23:04 -07:00
|
|
|
elif kind == 'since':
|
|
|
|
since_match = re.match(r'^(\d+)', get_text(child))
|
|
|
|
since = int(since_match.group(1)) if since_match else 0
|
|
|
|
NVIM_API_LEVEL, NVIM_API_PRERELEASE = nvim_api_info()
|
|
|
|
if since > NVIM_API_LEVEL or (
|
|
|
|
since == NVIM_API_LEVEL and NVIM_API_PRERELEASE
|
|
|
|
):
|
|
|
|
chunks['prerelease'] = True
|
2019-12-24 01:04:14 -07:00
|
|
|
else:
|
|
|
|
raise RuntimeError('unhandled simplesect: {}\n{}'.format(
|
|
|
|
child.nodeName, child.toprettyxml(indent=' ', newl='\n')))
|
2017-01-03 05:11:19 -07:00
|
|
|
else:
|
2024-01-09 10:36:46 -07:00
|
|
|
child_text = render_node(child, text, indent=indent, width=width)
|
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()
|
lsp: vim.lsp.diagnostic (#12655)
Breaking Changes:
- Deprecated all `vim.lsp.util.{*diagnostics*}()` functions.
- Instead, all functions must be found in vim.lsp.diagnostic
- For now, they issue a warning ONCE per neovim session. In a
"little while" we will remove them completely.
- `vim.lsp.callbacks` has moved to `vim.lsp.handlers`.
- For a "little while" we will just redirect `vim.lsp.callbacks` to
`vim.lsp.handlers`. However, we will remove this at some point, so
it is recommended that you change all of your references to
`callbacks` into `handlers`.
- This also means that for functions like |vim.lsp.start_client()|
and similar, keyword style arguments have moved from "callbacks"
to "handlers". Once again, these are currently being forward, but
will cease to be forwarded in a "little while".
- Changed the highlight groups for LspDiagnostic highlight as they were
inconsistently named.
- For more information, see |lsp-highlight-diagnostics|
- Changed the sign group names as well, to be consistent with
|lsp-highlight-diagnostics|
General Enhancements:
- Rewrote much of the getting started help document for lsp. It also
provides a much nicer configuration strategy, so as to not recommend
globally overwriting builtin neovim mappings.
LSP Enhancements:
- Introduced the concept of |lsp-handlers| which will allow much better
customization for users without having to copy & paste entire files /
functions / etc.
Diagnostic Enhancements:
- "goto next diagnostic" |vim.lsp.diagnostic.goto_next()|
- "goto prev diagnostic" |vim.lsp.diagnostic.goto_prev()|
- For each of the gotos, auto open diagnostics is available as a
configuration option
- Configurable diagnostic handling:
- See |vim.lsp.diagnostic.on_publish_diagnostics()|
- Delay display until after insert mode
- Configure signs
- Configure virtual text
- Configure underline
- Set the location list with the buffers diagnostics.
- See |vim.lsp.diagnostic.set_loclist()|
- Better performance for getting counts and line diagnostics
- They are now cached on save, to enhance lookups.
- Particularly useful for checking in statusline, etc.
- Actual testing :)
- See ./test/functional/plugin/lsp/diagnostic_spec.lua
- Added `guisp` for underline highlighting
NOTE: "a little while" means enough time to feel like most plugins and
plugin authors have had a chance to refactor their code to use the
updated calls. Then we will remove them completely. There is no need to
keep them, because we don't have any released version of neovim that
exposes these APIs. I'm trying to be nice to people following HEAD :)
Co-authored: [Twitch Chat 2020](https://twitch.tv/teej_dv)
2020-11-12 20:21:34 -07:00
|
|
|
and text
|
2024-01-09 10:36:46 -07:00
|
|
|
and text[-1] not in (' ', '(', '|')
|
|
|
|
and not child_text.startswith(')')):
|
2019-12-24 01:04:14 -07:00
|
|
|
text += ' '
|
2020-07-02 04:09:17 -07:00
|
|
|
|
2024-01-09 10:36:46 -07:00
|
|
|
text += child_text
|
2019-12-24 01:04:14 -07:00
|
|
|
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)
|
2023-07-06 13:47:27 -07:00
|
|
|
for child in groups['note']:
|
|
|
|
chunks['note'].append(render_node(
|
2023-12-28 15:50:05 -07:00
|
|
|
child, '', indent=indent, width=width).rstrip())
|
2019-11-17 23:49:28 -07:00
|
|
|
for child in groups['return']:
|
|
|
|
chunks['return'].append(render_node(
|
2023-12-28 15:50:05 -07:00
|
|
|
child, '', indent=indent, width=width))
|
2019-11-17 23:49:28 -07:00
|
|
|
for child in groups['seealso']:
|
2023-03-15 04:51:44 -07:00
|
|
|
# Example:
|
|
|
|
# <simplesect kind="see">
|
|
|
|
# <para>|autocommand|</para>
|
|
|
|
# </simplesect>
|
2019-11-17 23:49:28 -07:00
|
|
|
chunks['seealso'].append(render_node(
|
2023-12-28 15:50:05 -07:00
|
|
|
child, '', indent=indent, width=width))
|
2022-05-15 02:23:56 -07:00
|
|
|
|
|
|
|
xrefs = set()
|
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
|
|
|
|
2022-05-15 02:23:56 -07:00
|
|
|
return chunks, xrefs
|
2017-01-03 05:11:19 -07:00
|
|
|
|
2023-12-28 11:04:34 -07:00
|
|
|
|
2023-09-14 06:23:01 -07:00
|
|
|
def is_program_listing(para):
|
|
|
|
"""
|
|
|
|
Return True if `para` contains a "programlisting" (i.e. a Markdown code
|
|
|
|
block ```).
|
|
|
|
|
|
|
|
Sometimes a <para> element will have only a single "programlisting" child
|
|
|
|
node, but othertimes it will have extra whitespace around the
|
|
|
|
"programlisting" node.
|
|
|
|
|
|
|
|
@param para XML <para> node
|
|
|
|
@return True if <para> is a programlisting
|
|
|
|
"""
|
|
|
|
|
|
|
|
# Remove any child text nodes that are only whitespace
|
|
|
|
children = [
|
|
|
|
n for n in para.childNodes
|
|
|
|
if n.nodeType != n.TEXT_NODE or n.data.strip() != ''
|
|
|
|
]
|
|
|
|
|
|
|
|
return len(children) == 1 and children[0].nodeName == 'programlisting'
|
|
|
|
|
2023-12-28 11:04:34 -07:00
|
|
|
|
2023-12-28 12:11:13 -07:00
|
|
|
FunctionParam = Tuple[
|
|
|
|
str, # type
|
|
|
|
str, # parameter name
|
|
|
|
]
|
|
|
|
|
|
|
|
@dataclasses.dataclass
|
|
|
|
class FunctionDoc:
|
|
|
|
"""Data structure for function documentation. Also exported as msgpack."""
|
|
|
|
|
|
|
|
annotations: List[str]
|
|
|
|
"""Attributes, e.g., FUNC_API_REMOTE_ONLY. See annotation_map"""
|
|
|
|
|
2023-12-28 15:50:05 -07:00
|
|
|
notes: List[Docstring]
|
|
|
|
"""Notes: (@note strings)"""
|
|
|
|
|
2023-12-28 12:11:13 -07:00
|
|
|
signature: str
|
|
|
|
"""Function signature with *tags*."""
|
|
|
|
|
|
|
|
parameters: List[FunctionParam]
|
|
|
|
"""Parameters: (type, name)"""
|
|
|
|
|
|
|
|
parameters_doc: Dict[str, Docstring]
|
|
|
|
"""Parameters documentation. Key is parameter name, value is doc."""
|
|
|
|
|
|
|
|
doc: List[Docstring]
|
|
|
|
"""Main description for the function. Separated by paragraph."""
|
|
|
|
|
|
|
|
return_: List[Docstring]
|
|
|
|
"""Return:, or Return (multiple): (@return strings)"""
|
|
|
|
|
|
|
|
seealso: List[Docstring]
|
|
|
|
"""See also: (@see strings)"""
|
|
|
|
|
2023-12-28 15:50:05 -07:00
|
|
|
xrefs: List[Docstring]
|
|
|
|
"""XRefs. Currently only used to track Deprecated functions."""
|
2023-12-28 12:11:13 -07:00
|
|
|
|
|
|
|
# for INCLUDE_C_DECL
|
|
|
|
c_decl: str | None = None
|
|
|
|
|
2023-12-28 15:50:05 -07:00
|
|
|
prerelease: bool = False
|
|
|
|
|
|
|
|
def export_mpack(self) -> Dict[str, Any]:
|
|
|
|
"""Convert a dict to be exported as mpack data."""
|
|
|
|
exported = self.__dict__.copy()
|
|
|
|
del exported['notes']
|
|
|
|
del exported['c_decl']
|
|
|
|
del exported['prerelease']
|
|
|
|
del exported['xrefs']
|
|
|
|
exported['return'] = exported.pop('return_')
|
|
|
|
return exported
|
|
|
|
|
|
|
|
def doc_concatenated(self) -> Docstring:
|
|
|
|
"""Concatenate all the paragraphs in `doc` into a single string, but
|
|
|
|
remove blank lines before 'programlisting' blocks. #25127
|
|
|
|
|
|
|
|
BEFORE (without programlisting processing):
|
|
|
|
```vimdoc
|
|
|
|
Example:
|
|
|
|
|
|
|
|
>vim
|
|
|
|
:echo nvim_get_color_by_name("Pink")
|
|
|
|
<
|
|
|
|
```
|
|
|
|
|
|
|
|
AFTER:
|
|
|
|
```vimdoc
|
|
|
|
Example: >vim
|
|
|
|
:echo nvim_get_color_by_name("Pink")
|
|
|
|
<
|
|
|
|
```
|
|
|
|
"""
|
|
|
|
def is_program_listing(paragraph: str) -> bool:
|
|
|
|
lines = paragraph.strip().split('\n')
|
|
|
|
return lines[0].startswith('>') and lines[-1] == '<'
|
|
|
|
|
|
|
|
rendered = []
|
|
|
|
for paragraph in self.doc:
|
|
|
|
if is_program_listing(paragraph):
|
|
|
|
rendered.append(' ') # Example: >vim
|
|
|
|
elif rendered:
|
|
|
|
rendered.append('\n\n')
|
|
|
|
rendered.append(paragraph)
|
|
|
|
return ''.join(rendered)
|
|
|
|
|
|
|
|
def render(self) -> Docstring:
|
|
|
|
"""Renders function documentation as Vim :help text."""
|
|
|
|
rendered_blocks: List[Docstring] = []
|
|
|
|
|
|
|
|
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():
|
|
|
|
if name == 'self':
|
|
|
|
continue
|
|
|
|
name = ' • {}'.format('{{{}}}'.format(name).ljust(max_name_len))
|
|
|
|
out += '{}{}\n'.format(name, desc)
|
|
|
|
return out.rstrip()
|
|
|
|
|
|
|
|
# Generate text from the gathered items.
|
|
|
|
chunks: List[Docstring] = [self.doc_concatenated()]
|
|
|
|
|
|
|
|
notes = []
|
|
|
|
if self.prerelease:
|
|
|
|
notes = [" This API is pre-release (unstable)."]
|
|
|
|
notes += self.notes
|
|
|
|
if len(notes) > 0:
|
|
|
|
chunks.append('\nNote: ~')
|
|
|
|
for s in notes:
|
|
|
|
chunks.append(' ' + s)
|
|
|
|
|
|
|
|
if self.parameters_doc:
|
|
|
|
chunks.append('\nParameters: ~')
|
|
|
|
chunks.append(fmt_param_doc(self.parameters_doc))
|
|
|
|
|
|
|
|
if self.return_:
|
|
|
|
chunks.append('\nReturn (multiple): ~' if len(self.return_) > 1
|
|
|
|
else '\nReturn: ~')
|
|
|
|
for s in self.return_:
|
|
|
|
chunks.append(' ' + s)
|
|
|
|
|
|
|
|
if self.seealso:
|
|
|
|
chunks.append('\nSee also: ~')
|
|
|
|
for s in self.seealso:
|
|
|
|
chunks.append(' ' + s)
|
|
|
|
|
|
|
|
# Note: xrefs are currently only used to remark "Deprecated: "
|
|
|
|
# for deprecated functions; visible when INCLUDE_DEPRECATED is set
|
|
|
|
for s in self.xrefs:
|
|
|
|
chunks.append('\n' + s)
|
|
|
|
|
|
|
|
rendered_blocks.append(clean_lines('\n'.join(chunks).strip()))
|
|
|
|
rendered_blocks.append('')
|
2023-12-28 12:11:13 -07:00
|
|
|
|
2023-12-28 15:50:05 -07:00
|
|
|
return clean_lines('\n'.join(rendered_blocks).strip())
|
|
|
|
|
|
|
|
|
|
|
|
def fmt_node_as_vimhelp(parent: Element, width=text_width - indentation, indent=''):
|
2019-12-19 20:42:24 -07:00
|
|
|
"""Renders (nested) Doxygen <para> nodes as Vim :help text.
|
2017-01-03 05:11:19 -07:00
|
|
|
|
2023-12-28 15:50:05 -07:00
|
|
|
Only handles "text" nodes. Used for individual elements (see render_node())
|
|
|
|
and in extract_defgroups().
|
|
|
|
|
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
|
|
|
|
2019-12-19 20:42:24 -07:00
|
|
|
for child in parent.childNodes:
|
2023-12-28 15:50:05 -07:00
|
|
|
para, _ = para_as_map(child, indent, width)
|
2019-12-19 20:42:24 -07:00
|
|
|
|
2023-09-13 06:38:28 -07:00
|
|
|
# 'programlisting' blocks are Markdown code blocks. Do not include
|
|
|
|
# these as a separate paragraph, but append to the last non-empty line
|
|
|
|
# in the text
|
2023-09-14 06:23:01 -07:00
|
|
|
if is_program_listing(child):
|
2023-09-13 06:38:28 -07:00
|
|
|
while rendered_blocks and rendered_blocks[-1] == '':
|
|
|
|
rendered_blocks.pop()
|
|
|
|
rendered_blocks[-1] += ' ' + para['text']
|
|
|
|
continue
|
|
|
|
|
2019-12-19 20:42:24 -07:00
|
|
|
# Generate text from the gathered items.
|
|
|
|
chunks = [para['text']]
|
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
|
|
|
|
|
|
|
|
2023-12-28 15:50:05 -07:00
|
|
|
def extract_from_xml(filename, target, *,
|
|
|
|
width: int, fmt_vimhelp: bool) -> Tuple[
|
2023-12-28 12:11:13 -07:00
|
|
|
Dict[FunctionName, FunctionDoc],
|
|
|
|
Dict[FunctionName, FunctionDoc],
|
|
|
|
]:
|
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
|
|
|
|
2022-05-15 02:23:56 -07:00
|
|
|
The `fmt_vimhelp` variable 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
|
|
|
"""
|
2023-12-28 11:04:34 -07:00
|
|
|
config: Config = CONFIG[target]
|
|
|
|
|
2023-12-28 12:11:13 -07:00
|
|
|
fns: Dict[FunctionName, FunctionDoc] = {}
|
|
|
|
deprecated_fns: Dict[FunctionName, FunctionDoc] = {}
|
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
|
|
|
|
|
2023-07-18 07:42:30 -07:00
|
|
|
if 'local_function' in return_type: # Special from lua2dox.lua.
|
|
|
|
continue
|
|
|
|
|
|
|
|
istbl = return_type.startswith('table') # Special from lua2dox.lua.
|
2023-12-28 11:04:34 -07:00
|
|
|
if istbl and not config.include_tables:
|
2023-07-18 07:42:30 -07:00
|
|
|
continue
|
|
|
|
|
2017-01-03 05:11:19 -07:00
|
|
|
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-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()
|
2023-12-28 11:04:34 -07:00
|
|
|
elif config.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
|
2021-05-01 05:19:48 -07:00
|
|
|
|
2019-03-03 07:01:16 -07:00
|
|
|
type_length = max(type_length, len(param_type))
|
|
|
|
params.append((param_type, param_name))
|
2017-01-03 05:11:19 -07:00
|
|
|
|
2021-05-01 05:19:48 -07:00
|
|
|
# Handle Object Oriented style functions here.
|
|
|
|
# We make sure they have "self" in the parameters,
|
|
|
|
# and a parent function
|
|
|
|
if return_type.startswith('function') \
|
|
|
|
and len(return_type.split(' ')) >= 2 \
|
|
|
|
and any(x[1] == 'self' for x in params):
|
|
|
|
split_return = return_type.split(' ')
|
|
|
|
name = f'{split_return[1]}:{name}'
|
2023-07-17 02:39:52 -07:00
|
|
|
params = [x for x in params if x[1] != 'self']
|
2021-05-01 05:19:48 -07:00
|
|
|
|
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
|
|
|
|
2021-05-01 05:19:48 -07:00
|
|
|
if not fmt_vimhelp:
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
fstem = '?'
|
|
|
|
if '.' in compoundname:
|
|
|
|
fstem = compoundname.split('.')[0]
|
2023-12-28 11:04:34 -07:00
|
|
|
fstem = config.module_override.get(fstem, fstem)
|
|
|
|
vimtag = config.fn_helptag_fmt(fstem, name, istbl)
|
2021-05-01 05:19:48 -07:00
|
|
|
|
2023-12-28 11:04:34 -07:00
|
|
|
if config.fn_name_fmt:
|
|
|
|
name = config.fn_name_fmt(fstem, name)
|
2023-07-15 08:55:32 -07:00
|
|
|
|
2023-07-18 07:42:30 -07:00
|
|
|
if istbl:
|
|
|
|
aopen, aclose = '', ''
|
|
|
|
else:
|
|
|
|
aopen, aclose = '(', ')'
|
|
|
|
|
|
|
|
prefix = name + aopen
|
|
|
|
suffix = ', '.join('{%s}' % a[1] for a in params
|
|
|
|
if a[0] not in ('void', 'Error', 'Arena',
|
|
|
|
'lua_State')) + aclose
|
2021-05-01 05:19:48 -07:00
|
|
|
|
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'
|
lsp: vim.lsp.diagnostic (#12655)
Breaking Changes:
- Deprecated all `vim.lsp.util.{*diagnostics*}()` functions.
- Instead, all functions must be found in vim.lsp.diagnostic
- For now, they issue a warning ONCE per neovim session. In a
"little while" we will remove them completely.
- `vim.lsp.callbacks` has moved to `vim.lsp.handlers`.
- For a "little while" we will just redirect `vim.lsp.callbacks` to
`vim.lsp.handlers`. However, we will remove this at some point, so
it is recommended that you change all of your references to
`callbacks` into `handlers`.
- This also means that for functions like |vim.lsp.start_client()|
and similar, keyword style arguments have moved from "callbacks"
to "handlers". Once again, these are currently being forward, but
will cease to be forwarded in a "little while".
- Changed the highlight groups for LspDiagnostic highlight as they were
inconsistently named.
- For more information, see |lsp-highlight-diagnostics|
- Changed the sign group names as well, to be consistent with
|lsp-highlight-diagnostics|
General Enhancements:
- Rewrote much of the getting started help document for lsp. It also
provides a much nicer configuration strategy, so as to not recommend
globally overwriting builtin neovim mappings.
LSP Enhancements:
- Introduced the concept of |lsp-handlers| which will allow much better
customization for users without having to copy & paste entire files /
functions / etc.
Diagnostic Enhancements:
- "goto next diagnostic" |vim.lsp.diagnostic.goto_next()|
- "goto prev diagnostic" |vim.lsp.diagnostic.goto_prev()|
- For each of the gotos, auto open diagnostics is available as a
configuration option
- Configurable diagnostic handling:
- See |vim.lsp.diagnostic.on_publish_diagnostics()|
- Delay display until after insert mode
- Configure signs
- Configure virtual text
- Configure underline
- Set the location list with the buffers diagnostics.
- See |vim.lsp.diagnostic.set_loclist()|
- Better performance for getting counts and line diagnostics
- They are now cached on save, to enhance lookups.
- Particularly useful for checking in statusline, etc.
- Actual testing :)
- See ./test/functional/plugin/lsp/diagnostic_spec.lua
- Added `guisp` for underline highlighting
NOTE: "a little while" means enough time to feel like most plugins and
plugin authors have had a chance to refactor their code to use the
updated calls. Then we will remove them completely. There is no need to
keep them, because we don't have any released version of neovim that
exposes these APIs. I'm trying to be nice to people following HEAD :)
Co-authored: [Twitch Chat 2020](https://twitch.tv/teej_dv)
2020-11-12 20:21:34 -07:00
|
|
|
signature += doc_wrap(suffix, width=width, 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
|
|
|
|
2022-05-15 02:23:56 -07:00
|
|
|
# Tracks `xrefsect` titles. As of this writing, used only for separating
|
|
|
|
# deprecated functions.
|
|
|
|
xrefs_all = set()
|
2023-12-28 15:50:05 -07:00
|
|
|
paras: List[Dict[str, Any]] = [] # paras means paragraphs!
|
2020-07-02 04:09:17 -07:00
|
|
|
brief_desc = find_first(member, 'briefdescription')
|
|
|
|
if brief_desc:
|
|
|
|
for child in brief_desc.childNodes:
|
2022-05-15 02:23:56 -07:00
|
|
|
para, xrefs = para_as_map(child)
|
2023-12-28 15:50:05 -07:00
|
|
|
paras.append(para)
|
2022-05-15 02:23:56 -07:00
|
|
|
xrefs_all.update(xrefs)
|
2020-07-02 04:09:17 -07:00
|
|
|
|
2017-01-03 05:11:19 -07:00
|
|
|
desc = find_first(member, 'detaileddescription')
|
|
|
|
if desc:
|
2023-12-28 15:50:05 -07:00
|
|
|
paras_detail = [] # override briefdescription
|
2019-11-17 23:49:28 -07:00
|
|
|
for child in desc.childNodes:
|
2022-05-15 02:23:56 -07:00
|
|
|
para, xrefs = para_as_map(child)
|
2023-12-28 15:50:05 -07:00
|
|
|
paras_detail.append(para)
|
2022-05-15 02:23:56 -07:00
|
|
|
xrefs_all.update(xrefs)
|
2021-02-28 07:49:43 -07:00
|
|
|
log.debug(
|
|
|
|
textwrap.indent(
|
2017-01-03 05:11:19 -07:00
|
|
|
re.sub(r'\n\s*\n+', '\n',
|
2022-08-08 11:24:50 -07:00
|
|
|
desc.toprettyxml(indent=' ', newl='\n')),
|
|
|
|
' ' * indentation))
|
2017-01-03 05:11:19 -07:00
|
|
|
|
2023-12-28 15:50:05 -07:00
|
|
|
# override briefdescription, if detaileddescription is not empty
|
|
|
|
# (note: briefdescription can contain some erroneous luadoc
|
|
|
|
# comments from preceding comments, this is a bug of lua2dox)
|
|
|
|
if any((para['text'] or para['note'] or para['params'] or
|
|
|
|
para['return'] or para['seealso']
|
|
|
|
) for para in paras_detail):
|
|
|
|
paras = paras_detail
|
|
|
|
|
2023-12-28 12:11:13 -07:00
|
|
|
fn = FunctionDoc(
|
|
|
|
annotations=list(annotations),
|
2023-12-28 15:50:05 -07:00
|
|
|
notes=[],
|
2023-12-28 12:11:13 -07:00
|
|
|
signature=signature,
|
|
|
|
parameters=params,
|
|
|
|
parameters_doc=collections.OrderedDict(),
|
|
|
|
doc=[],
|
|
|
|
return_=[],
|
|
|
|
seealso=[],
|
2023-12-28 15:50:05 -07:00
|
|
|
xrefs=[],
|
2023-12-28 12:11:13 -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
|
|
|
|
2019-11-17 23:49:28 -07:00
|
|
|
for m in paras:
|
2023-12-28 12:11:13 -07:00
|
|
|
if m.get('text', ''):
|
|
|
|
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.
|
2023-12-28 12:11:13 -07:00
|
|
|
fn.parameters_doc.update(m['params'])
|
2019-12-19 17:52:37 -07:00
|
|
|
if 'return' in m and len(m['return']) > 0:
|
2023-12-28 12:11:13 -07:00
|
|
|
fn.return_ += m['return']
|
2019-12-19 18:48:40 -07:00
|
|
|
if 'seealso' in m and len(m['seealso']) > 0:
|
2023-12-28 12:11:13 -07:00
|
|
|
fn.seealso += m['seealso']
|
2023-12-28 15:50:05 -07:00
|
|
|
if m.get('prerelease', False):
|
|
|
|
fn.prerelease = True
|
|
|
|
if 'note' in m:
|
|
|
|
fn.notes += m['note']
|
|
|
|
if 'xrefs' in m:
|
|
|
|
fn.xrefs += m['xrefs']
|
[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:
|
2023-12-28 12:11:13 -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
|
|
|
|
2022-05-15 02:23:56 -07:00
|
|
|
if 'Deprecated' in str(xrefs_all):
|
2019-12-24 01:04:14 -07:00
|
|
|
deprecated_fns[name] = fn
|
2023-12-28 11:04:34 -07:00
|
|
|
elif name.startswith(config.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
|
|
|
|
2023-12-28 12:11:13 -07:00
|
|
|
# sort functions by name (lexicographically)
|
2021-05-01 05:19:48 -07:00
|
|
|
fns = collections.OrderedDict(sorted(
|
|
|
|
fns.items(),
|
2023-12-28 12:11:13 -07:00
|
|
|
key=lambda key_item_tuple: key_item_tuple[0].lower(),
|
|
|
|
))
|
2019-12-28 04:27:25 -07:00
|
|
|
deprecated_fns = collections.OrderedDict(sorted(deprecated_fns.items()))
|
2022-05-15 02:23:56 -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
|
|
|
|
|
|
|
|
2023-12-28 12:11:13 -07:00
|
|
|
def fmt_doxygen_xml_as_vimhelp(filename, target) -> Tuple[Docstring, Docstring]:
|
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
|
|
|
|
2022-09-25 04:45:41 -07:00
|
|
|
Returns 2 items:
|
2019-12-24 01:04:14 -07:00
|
|
|
1. Vim help text for functions found in `filename`.
|
|
|
|
2. Vim help text for deprecated functions.
|
2017-01-03 05:11:19 -07:00
|
|
|
"""
|
2023-12-28 11:04:34 -07:00
|
|
|
config: Config = CONFIG[target]
|
|
|
|
|
2019-12-24 01:04:14 -07:00
|
|
|
fns_txt = {} # Map of func_name:vim-help-text.
|
|
|
|
deprecated_fns_txt = {} # Map of func_name:vim-help-text.
|
2023-12-28 12:11:13 -07:00
|
|
|
|
|
|
|
fns: Dict[FunctionName, FunctionDoc]
|
2023-12-29 04:32:37 -07:00
|
|
|
deprecated_fns: Dict[FunctionName, FunctionDoc]
|
|
|
|
fns, deprecated_fns = extract_from_xml(
|
|
|
|
filename, target, width=text_width, fmt_vimhelp=True)
|
2017-01-03 05:11:19 -07:00
|
|
|
|
2023-12-29 04:32:37 -07:00
|
|
|
def _handle_fn(fn_name: FunctionName, fn: FunctionDoc,
|
|
|
|
fns_txt: Dict[FunctionName, Docstring], deprecated=False):
|
2019-12-19 20:42:24 -07:00
|
|
|
# Generate Vim :help for parameters.
|
2023-12-28 12:11:13 -07:00
|
|
|
|
2023-12-28 15:50:05 -07:00
|
|
|
# Generate body from FunctionDoc, not XML nodes
|
|
|
|
doc = fn.render()
|
2023-12-28 12:11:13 -07:00
|
|
|
if not doc and fn_name.startswith("nvim__"):
|
2023-12-29 04:32:37 -07:00
|
|
|
return
|
2017-01-03 05:11:19 -07:00
|
|
|
if not doc:
|
2023-12-29 04:32:37 -07:00
|
|
|
doc = ('TODO: Documentation' if not deprecated
|
|
|
|
else 'Deprecated.')
|
2017-01-03 05:11:19 -07:00
|
|
|
|
2023-12-28 12:11:13 -07:00
|
|
|
# Annotations: put before Parameters
|
|
|
|
annotations: str = '\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:]
|
|
|
|
|
2023-12-28 12:11:13 -07:00
|
|
|
# C Declaration: (debug only)
|
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'
|
2023-12-28 12:11:13 -07:00
|
|
|
assert fn.c_decl is not None
|
|
|
|
doc += fn.c_decl
|
2017-01-03 05:11:19 -07:00
|
|
|
doc += '\n<'
|
|
|
|
|
2023-12-28 12:11:13 -07:00
|
|
|
# Start of function documentations. e.g.,
|
|
|
|
# nvim_cmd({*cmd}, {*opts}) *nvim_cmd()*
|
|
|
|
func_doc = fn.signature + '\n'
|
2022-08-08 11:24:50 -07:00
|
|
|
func_doc += textwrap.indent(clean_lines(doc), ' ' * indentation)
|
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)
|
|
|
|
|
2023-12-28 12:11:13 -07:00
|
|
|
split_lines: List[str] = func_doc.split('\n')
|
2020-07-02 04:09:17 -07:00
|
|
|
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
|
|
|
|
|
2022-12-14 02:46:54 -07:00
|
|
|
func_doc = "\n".join(map(align_tags, split_lines))
|
2020-07-02 04:09:17 -07:00
|
|
|
|
2023-12-28 12:11:13 -07:00
|
|
|
if (fn_name.startswith(config.fn_name_prefix)
|
|
|
|
and fn_name != "nvim_error_event"):
|
|
|
|
fns_txt[fn_name] = func_doc
|
2017-01-03 05:11:19 -07:00
|
|
|
|
2023-12-29 04:32:37 -07:00
|
|
|
for fn_name, fn in fns.items():
|
|
|
|
_handle_fn(fn_name, fn, fns_txt)
|
|
|
|
for fn_name, fn in deprecated_fns.items():
|
|
|
|
_handle_fn(fn_name, fn, deprecated_fns_txt, deprecated=True)
|
|
|
|
|
2023-12-28 12:11:13 -07:00
|
|
|
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
|
|
|
|
2023-12-29 03:52:31 -07:00
|
|
|
def extract_defgroups(base: str, dom: Document) -> Dict[SectionName, Docstring]:
|
2023-07-17 07:22:44 -07:00
|
|
|
'''Generate module-level (section) docs (@defgroup).'''
|
|
|
|
section_docs = {}
|
|
|
|
|
|
|
|
for compound in dom.getElementsByTagName('compound'):
|
|
|
|
if compound.getAttribute('kind') != 'group':
|
|
|
|
continue
|
|
|
|
|
|
|
|
# Doxygen "@defgroup" directive.
|
|
|
|
groupname = get_text(find_first(compound, 'name'))
|
|
|
|
groupxml = os.path.join(base, '%s.xml' %
|
|
|
|
compound.getAttribute('refid'))
|
|
|
|
|
|
|
|
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')
|
|
|
|
if desc:
|
|
|
|
doc = fmt_node_as_vimhelp(desc)
|
|
|
|
|
|
|
|
if doc:
|
|
|
|
doc_list.append(doc)
|
|
|
|
|
|
|
|
# Can't use '.' in @defgroup, so convert to '--'
|
|
|
|
# "vim.json" => "vim-dot-json"
|
|
|
|
groupname = groupname.replace('-dot-', '.')
|
|
|
|
|
|
|
|
section_docs[groupname] = "\n".join(doc_list)
|
|
|
|
|
|
|
|
return section_docs
|
|
|
|
|
|
|
|
|
2023-12-29 03:52:31 -07:00
|
|
|
@dataclasses.dataclass
|
|
|
|
class Section:
|
|
|
|
"""Represents a section. Includes section heading (defgroup)
|
|
|
|
and all the FunctionDoc that belongs to this section."""
|
|
|
|
|
|
|
|
name: str
|
|
|
|
'''Name of the section. Usually derived from basename of lua/c src file.
|
|
|
|
Example: "Autocmd".'''
|
|
|
|
|
|
|
|
title: str
|
|
|
|
'''Formatted section config. see config.section_fmt().
|
|
|
|
Example: "Autocmd Functions". '''
|
|
|
|
|
|
|
|
helptag: str
|
|
|
|
'''see config.helptag_fmt(). Example: *api-autocmd*'''
|
|
|
|
|
|
|
|
@property
|
|
|
|
def id(self) -> str:
|
|
|
|
'''section id: Module/Section id matched against @defgroup.
|
|
|
|
e.g., "*api-autocmd*" => "api-autocmd"
|
|
|
|
'''
|
|
|
|
return self.helptag.strip('*')
|
|
|
|
|
|
|
|
doc: str = ""
|
|
|
|
'''Section heading docs extracted from @defgroup.'''
|
|
|
|
|
|
|
|
# TODO: Do not carry rendered text, but handle FunctionDoc for better OOP
|
|
|
|
functions_text: Docstring | None = None
|
|
|
|
'''(Rendered) doc of all the functions that belong to this section.'''
|
|
|
|
|
|
|
|
deprecated_functions_text: Docstring | None = None
|
|
|
|
'''(Rendered) doc of all the deprecated functions that belong to this
|
|
|
|
section.'''
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
return f"Section(title='{self.title}', helptag='{self.helptag}')"
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def make_from(cls, filename: str, config: Config,
|
|
|
|
section_docs: Dict[SectionName, str],
|
|
|
|
*,
|
|
|
|
functions_text: Docstring,
|
|
|
|
deprecated_functions_text: Docstring,
|
|
|
|
):
|
|
|
|
# filename: e.g., 'autocmd.c'
|
|
|
|
# name: e.g. 'autocmd'
|
|
|
|
name = os.path.splitext(filename)[0].lower()
|
|
|
|
|
|
|
|
# section name: e.g. "Autocmd"
|
|
|
|
sectname: SectionName
|
|
|
|
sectname = name.upper() if name == 'ui' else name.title()
|
|
|
|
sectname = config.section_name.get(filename, sectname)
|
|
|
|
|
|
|
|
# Formatted (this is what's going to be written in the vimdoc)
|
|
|
|
# e.g., "Autocmd Functions"
|
|
|
|
title: str = config.section_fmt(sectname)
|
|
|
|
|
|
|
|
# section tag: e.g., "*api-autocmd*"
|
|
|
|
section_tag: str = config.helptag_fmt(sectname)
|
|
|
|
|
|
|
|
section = cls(name=sectname, title=title, helptag=section_tag,
|
|
|
|
functions_text=functions_text,
|
|
|
|
deprecated_functions_text=deprecated_functions_text,
|
|
|
|
)
|
|
|
|
section.doc = section_docs.get(section.id) or ''
|
|
|
|
return section
|
|
|
|
|
|
|
|
def render(self, add_header=True) -> str:
|
|
|
|
"""Render as vimdoc."""
|
|
|
|
doc = ''
|
|
|
|
|
|
|
|
if add_header:
|
|
|
|
doc += SECTION_SEP
|
|
|
|
doc += '\n{}{}'.format(
|
|
|
|
self.title,
|
|
|
|
self.helptag.rjust(text_width - len(self.title))
|
|
|
|
)
|
|
|
|
|
|
|
|
if self.doc:
|
|
|
|
doc += '\n\n' + self.doc
|
|
|
|
|
|
|
|
if self.functions_text:
|
|
|
|
doc += '\n\n' + self.functions_text
|
|
|
|
|
|
|
|
if INCLUDE_DEPRECATED and self.deprecated_functions_text:
|
|
|
|
doc += f'\n\n\nDeprecated {self.name} Functions: ~\n\n'
|
|
|
|
doc += self.deprecated_functions_text
|
|
|
|
|
|
|
|
return doc
|
|
|
|
|
|
|
|
def __bool__(self) -> bool:
|
|
|
|
"""Whether this section has contents. Used for skipping empty ones."""
|
2023-12-29 04:32:37 -07:00
|
|
|
return bool(self.doc or self.functions_text or
|
|
|
|
(INCLUDE_DEPRECATED and self.deprecated_functions_text))
|
2023-12-29 03:52:31 -07:00
|
|
|
|
|
|
|
|
2021-09-20 19:00:50 -07:00
|
|
|
def main(doxygen_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
|
2023-12-28 11:04:34 -07:00
|
|
|
|
|
|
|
config: Config = CONFIG[target]
|
|
|
|
|
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',
|
2023-12-28 11:04:34 -07:00
|
|
|
config.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)
|
2021-07-10 08:55:45 -07:00
|
|
|
log.info("Generating documentation for %s in folder %s",
|
|
|
|
target, output_dir)
|
2021-02-28 07:49:43 -07:00
|
|
|
debug = args.log_level >= logging.DEBUG
|
2019-12-31 08:12:10 -07:00
|
|
|
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
|
2021-02-28 07:49:43 -07:00
|
|
|
stderr=(subprocess.STDOUT if debug else subprocess.DEVNULL))
|
2019-03-29 13:54:34 -07:00
|
|
|
p.communicate(
|
2021-09-20 19:00:50 -07:00
|
|
|
doxygen_config.format(
|
2023-12-28 11:04:34 -07:00
|
|
|
input=' '.join([f'"{file}"' for file in config.files]),
|
2019-03-29 13:54:34 -07:00
|
|
|
output=output_dir,
|
|
|
|
filter=filter_cmd,
|
2023-12-28 11:04:34 -07:00
|
|
|
file_patterns=config.file_patterns)
|
2019-03-29 13:54:34 -07:00
|
|
|
.encode('utf8')
|
|
|
|
)
|
|
|
|
if p.returncode:
|
|
|
|
sys.exit(p.returncode)
|
|
|
|
|
2023-12-29 03:52:31 -07:00
|
|
|
# Collects all functions as each module is processed.
|
|
|
|
fn_map_full: Dict[FunctionName, FunctionDoc] = {}
|
|
|
|
# key: filename (e.g. autocmd.c)
|
|
|
|
sections: Dict[str, Section] = {}
|
2019-03-29 13:54:34 -07:00
|
|
|
|
|
|
|
base = os.path.join(output_dir, 'xml')
|
|
|
|
dom = minidom.parse(os.path.join(base, 'index.xml'))
|
|
|
|
|
2023-12-29 03:52:31 -07:00
|
|
|
# Collect all @defgroups (section headings after the '===...' separator
|
|
|
|
section_docs: Dict[SectionName, Docstring] = extract_defgroups(base, dom)
|
2018-07-24 21:07:55 -07:00
|
|
|
|
2023-03-05 16:15:29 -07:00
|
|
|
# Generate docs for all functions in the current module.
|
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'))
|
2023-12-29 03:52:31 -07:00
|
|
|
if not (
|
|
|
|
filename.endswith('.c') or
|
|
|
|
filename.endswith('.lua')
|
|
|
|
):
|
|
|
|
continue
|
2023-12-28 15:50:05 -07:00
|
|
|
|
2023-12-29 03:52:31 -07:00
|
|
|
xmlfile = os.path.join(base, '{}.xml'.format(compound.getAttribute('refid')))
|
2023-12-28 15:50:05 -07:00
|
|
|
|
2023-12-29 03:52:31 -07:00
|
|
|
# Extract unformatted (*.mpack).
|
|
|
|
fn_map, _ = extract_from_xml(
|
|
|
|
xmlfile, target, width=9999, fmt_vimhelp=False)
|
2017-01-03 05:11:19 -07:00
|
|
|
|
2023-12-29 03:52:31 -07:00
|
|
|
# Extract formatted (:help).
|
|
|
|
functions_text, deprecated_text = fmt_doxygen_xml_as_vimhelp(
|
|
|
|
xmlfile, target)
|
|
|
|
|
|
|
|
if not functions_text and not deprecated_text:
|
|
|
|
continue
|
|
|
|
|
|
|
|
filename = os.path.basename(filename)
|
|
|
|
|
|
|
|
section: Section = Section.make_from(
|
|
|
|
filename, config, section_docs,
|
|
|
|
functions_text=functions_text,
|
|
|
|
deprecated_functions_text=deprecated_text,
|
|
|
|
)
|
|
|
|
|
|
|
|
if section: # if not empty
|
|
|
|
sections[filename] = section
|
|
|
|
fn_map_full.update(fn_map)
|
|
|
|
else:
|
|
|
|
log.debug("Skipping empty section: %s", section)
|
2017-01-03 05:11:19 -07:00
|
|
|
|
2020-08-31 00:51:35 -07:00
|
|
|
if len(sections) == 0:
|
2021-09-20 19:00:50 -07:00
|
|
|
fail(f'no sections for target: {target} (look for errors near "Preprocessing" log lines above)')
|
2023-12-28 11:04:34 -07:00
|
|
|
if len(sections) > len(config.section_order):
|
2019-12-31 07:52:14 -07:00
|
|
|
raise RuntimeError(
|
2023-12-29 04:32:37 -07:00
|
|
|
'{}: found new modules {}; '
|
|
|
|
'update the "section_order" map'.format(
|
|
|
|
target,
|
|
|
|
set(sections).difference(config.section_order))
|
|
|
|
)
|
2023-12-29 03:52:31 -07:00
|
|
|
first_section_tag = sections[config.section_order[0]].helptag
|
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
|
|
|
|
2023-12-28 11:04:34 -07:00
|
|
|
for filename in config.section_order:
|
2020-08-19 09:17:08 -07:00
|
|
|
try:
|
2023-12-29 03:52:31 -07:00
|
|
|
section: Section = sections.pop(filename)
|
2020-08-19 09:17:08 -07:00
|
|
|
except KeyError:
|
2020-08-31 00:51:35 -07:00
|
|
|
msg(f'warning: empty docs, skipping (target={target}): {filename}')
|
2021-05-01 05:19:48 -07:00
|
|
|
msg(f' existing docs: {sections.keys()}')
|
2020-08-19 09:17:08 -07:00
|
|
|
continue
|
2023-12-29 03:52:31 -07:00
|
|
|
|
|
|
|
add_sep_and_header = filename not in config.append_only
|
|
|
|
docs += section.render(add_header=add_sep_and_header)
|
2019-05-18 13:04:31 -07:00
|
|
|
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'
|
2022-08-08 11:24:50 -07:00
|
|
|
docs += f' vim:tw=78:ts=8:sw={indentation}:sts={indentation}:et:ft=help:norl:\n'
|
2019-03-29 13:54:34 -07:00
|
|
|
|
2023-12-28 11:04:34 -07:00
|
|
|
doc_file = os.path.join(base_dir, 'runtime', 'doc', config.filename)
|
2019-03-29 13:54:34 -07:00
|
|
|
|
2022-03-13 05:13:42 -07:00
|
|
|
if os.path.exists(doc_file):
|
|
|
|
delete_lines_below(doc_file, first_section_tag)
|
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
|
|
|
|
2023-12-28 15:50:05 -07:00
|
|
|
fn_map_full_exported = collections.OrderedDict(sorted(
|
|
|
|
(name, fn_doc.export_mpack()) for (name, fn_doc) in fn_map_full.items()
|
2023-12-28 12:11:13 -07:00
|
|
|
))
|
2019-10-26 12:54:54 -07:00
|
|
|
with open(mpack_file, 'wb') as fp:
|
2023-12-28 15:50:05 -07:00
|
|
|
fp.write(msgpack.packb(fn_map_full_exported, use_bin_type=True)) # type: ignore
|
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
|
|
|
|
2023-03-03 05:49:22 -07:00
|
|
|
def filter_source(filename, keep_tmpfiles):
|
|
|
|
output_dir = out_dir.format(target='lua2dox')
|
2019-03-29 13:54:34 -07:00
|
|
|
name, extension = os.path.splitext(filename)
|
|
|
|
if extension == '.lua':
|
2023-03-03 05:49:22 -07:00
|
|
|
args = [str(nvim), '-l', lua2dox, filename] + (['--outdir', output_dir] if keep_tmpfiles else [])
|
|
|
|
p = subprocess.run(args, stdout=subprocess.PIPE)
|
2019-03-29 13:54:34 -07:00
|
|
|
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())
|
2021-07-10 08:55:45 -07:00
|
|
|
ap = argparse.ArgumentParser(
|
|
|
|
description="Generate helpdoc from source code")
|
2021-02-28 07:49:43 -07:00
|
|
|
ap.add_argument(
|
|
|
|
"--log-level", "-l", choices=LOG_LEVELS.keys(),
|
|
|
|
default=logging.getLevelName(logging.ERROR), help="Set log verbosity"
|
|
|
|
)
|
2020-08-08 12:47:59 -07:00
|
|
|
ap.add_argument('source_filter', nargs='*',
|
|
|
|
help="Filter source file(s)")
|
|
|
|
ap.add_argument('-k', '--keep-tmpfiles', action='store_true',
|
2023-03-03 05:49:22 -07:00
|
|
|
help="Keep temporary files (tmp-xx-doc/ directories, including tmp-lua2dox-doc/ for lua2dox.lua quasi-C output)")
|
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
|
2021-09-16 10:49:11 -07:00
|
|
|
EXCLUDE_PATTERNS = */private/* */health.lua */_*.lua
|
2019-11-17 23:49:28 -07:00
|
|
|
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()
|
2021-02-28 07:49:43 -07:00
|
|
|
print("Setting log level to %s" % args.log_level)
|
|
|
|
args.log_level = LOG_LEVELS[args.log_level]
|
|
|
|
log.setLevel(args.log_level)
|
2021-07-10 08:55:45 -07:00
|
|
|
log.addHandler(logging.StreamHandler())
|
2021-02-28 07:49:43 -07:00
|
|
|
|
2023-03-03 05:49:22 -07:00
|
|
|
# When invoked as a filter, args won't be passed, so use an env var.
|
|
|
|
if args.keep_tmpfiles:
|
|
|
|
os.environ['NVIM_KEEP_TMPFILES'] = '1'
|
|
|
|
keep_tmpfiles = ('NVIM_KEEP_TMPFILES' in os.environ)
|
|
|
|
|
2020-08-08 12:47:59 -07:00
|
|
|
if len(args.source_filter) > 0:
|
2023-03-03 05:49:22 -07:00
|
|
|
filter_source(args.source_filter[0], keep_tmpfiles)
|
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 :
|