docs: support @since for api level #25574

close #25416
This commit is contained in:
LW 2023-11-27 08:23:04 -08:00 committed by GitHub
parent 72ed99319d
commit 9fa9b3cad9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 53 additions and 5 deletions

View File

@ -1468,13 +1468,15 @@ Lua module: vim.lsp.inlay_hint *lsp-inlay_hint*
enable({bufnr}, {enable}) *vim.lsp.inlay_hint.enable()* enable({bufnr}, {enable}) *vim.lsp.inlay_hint.enable()*
Enable/disable/toggle inlay hints for a buffer Enable/disable/toggle inlay hints for a buffer
Note: ~
This API is pre-release (unstable).
Parameters: ~ Parameters: ~
• {bufnr} (integer|nil) Buffer handle, or 0 or nil for current • {bufnr} (integer|nil) Buffer handle, or 0 or nil for current
• {enable} (boolean|nil) true/nil to enable, false to disable • {enable} (boolean|nil) true/nil to enable, false to disable
get({filter}) *vim.lsp.inlay_hint.get()* get({filter}) *vim.lsp.inlay_hint.get()*
Get the list of inlay hints, (optionally) restricted by buffer, client, or Get the list of inlay hints, (optionally) restricted by buffer or range.
range.
Example usage: >lua Example usage: >lua
local hint = vim.lsp.inlay_hint.get({ bufnr = 0 })[1] -- 0 for current buffer local hint = vim.lsp.inlay_hint.get({ bufnr = 0 })[1] -- 0 for current buffer
@ -1490,6 +1492,9 @@ get({filter}) *vim.lsp.inlay_hint.get()*
}) })
< <
Note: ~
This API is pre-release (unstable).
Parameters: ~ Parameters: ~
• {filter} vim.lsp.inlay_hint.get.filter ? Optional filters |kwargs|: • {filter} vim.lsp.inlay_hint.get.filter ? Optional filters |kwargs|:
• bufnr (integer?): 0 for current buffer • bufnr (integer?): 0 for current buffer
@ -1502,6 +1507,9 @@ get({filter}) *vim.lsp.inlay_hint.get()*
• inlay_hint (lsp.InlayHint) • inlay_hint (lsp.InlayHint)
is_enabled({bufnr}) *vim.lsp.inlay_hint.is_enabled()* is_enabled({bufnr}) *vim.lsp.inlay_hint.is_enabled()*
Note: ~
This API is pre-release (unstable).
Parameters: ~ Parameters: ~
• {bufnr} (integer|nil) Buffer handle, or 0 or nil for current • {bufnr} (integer|nil) Buffer handle, or 0 or nil for current

View File

@ -107,7 +107,7 @@ end
--- @field client_id integer --- @field client_id integer
--- @field inlay_hint lsp.InlayHint --- @field inlay_hint lsp.InlayHint
--- Get the list of inlay hints, (optionally) restricted by buffer, client, or range. --- Get the list of inlay hints, (optionally) restricted by buffer or range.
--- ---
--- Example usage: --- Example usage:
--- ---
@ -135,6 +135,8 @@ end
--- - bufnr (integer) --- - bufnr (integer)
--- - client_id (integer) --- - client_id (integer)
--- - inlay_hint (lsp.InlayHint) --- - inlay_hint (lsp.InlayHint)
---
--- @since 12
function M.get(filter) function M.get(filter)
vim.validate({ filter = { filter, 'table', true } }) vim.validate({ filter = { filter, 'table', true } })
filter = filter or {} filter = filter or {}
@ -349,6 +351,7 @@ api.nvim_set_decoration_provider(namespace, {
--- @param bufnr (integer|nil) Buffer handle, or 0 or nil for current --- @param bufnr (integer|nil) Buffer handle, or 0 or nil for current
--- @return boolean --- @return boolean
--- @since 12
function M.is_enabled(bufnr) function M.is_enabled(bufnr)
vim.validate({ bufnr = { bufnr, 'number', true } }) vim.validate({ bufnr = { bufnr, 'number', true } })
if bufnr == nil or bufnr == 0 then if bufnr == nil or bufnr == 0 then
@ -361,6 +364,7 @@ end
--- ---
--- @param bufnr (integer|nil) Buffer handle, or 0 or nil for current --- @param bufnr (integer|nil) Buffer handle, or 0 or nil for current
--- @param enable (boolean|nil) true/nil to enable, false to disable --- @param enable (boolean|nil) true/nil to enable, false to disable
--- @since 12
function M.enable(bufnr, enable) function M.enable(bufnr, enable)
vim.validate({ enable = { enable, 'boolean', true }, bufnr = { bufnr, 'number', true } }) vim.validate({ enable = { enable, 'boolean', true }, bufnr = { bufnr, 'number', true } })
if enable == false then if enable == false then

View File

@ -42,6 +42,7 @@ import subprocess
import collections import collections
import msgpack import msgpack
import logging import logging
from typing import Tuple
from pathlib import Path from pathlib import Path
from xml.dom import minidom from xml.dom import minidom
@ -363,6 +364,30 @@ annotation_map = {
} }
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
# Raises an error with details about `o`, if `cond` is in object `o`, # Raises an error with details about `o`, if `cond` is in object `o`,
# or if `cond()` is callable and returns True. # or if `cond()` is callable and returns True.
def debug_this(o, cond=True): def debug_this(o, cond=True):
@ -691,6 +716,7 @@ def para_as_map(parent, indent='', width=text_width - indentation, fmt_vimhelp=F
'params': collections.OrderedDict(), 'params': collections.OrderedDict(),
'return': [], 'return': [],
'seealso': [], 'seealso': [],
'prerelease': False,
'xrefs': [] 'xrefs': []
} }
@ -729,6 +755,14 @@ def para_as_map(parent, indent='', width=text_width - indentation, fmt_vimhelp=F
elif kind == 'warning': elif kind == 'warning':
text += render_node(child, text, indent=indent, text += render_node(child, text, indent=indent,
width=width, fmt_vimhelp=fmt_vimhelp) width=width, fmt_vimhelp=fmt_vimhelp)
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
else: else:
raise RuntimeError('unhandled simplesect: {}\n{}'.format( raise RuntimeError('unhandled simplesect: {}\n{}'.format(
child.nodeName, child.toprettyxml(indent=' ', newl='\n'))) child.nodeName, child.toprettyxml(indent=' ', newl='\n')))
@ -837,9 +871,11 @@ def fmt_node_as_vimhelp(parent: Element, width=text_width - indentation, indent=
# Generate text from the gathered items. # Generate text from the gathered items.
chunks = [para['text']] chunks = [para['text']]
if len(para['note']) > 0: notes = [" This API is pre-release (unstable)."] if para['prerelease'] else []
notes += para['note']
if len(notes) > 0:
chunks.append('\nNote: ~') chunks.append('\nNote: ~')
for s in para['note']: for s in notes:
chunks.append(s) chunks.append(s)
if len(para['params']) > 0 and has_nonexcluded_params(para['params']): if len(para['params']) > 0 and has_nonexcluded_params(para['params']):
chunks.append('\nParameters: ~') chunks.append('\nParameters: ~')