refactor(gen_vimdoc): detect section_start_token automatically

This commit is contained in:
Daiki Mizukami 2022-03-13 21:03:38 +09:00
parent 4ba12b3dda
commit 2d28c40ef9
No known key found for this signature in database
GPG Key ID: 10478E598B944AA2

View File

@ -84,8 +84,6 @@ CONFIG = {
'api': { 'api': {
'mode': 'c', 'mode': 'c',
'filename': 'api.txt', 'filename': 'api.txt',
# String used to find the start of the generated part of the doc.
'section_start_token': '*api-global*',
# Section ordering. # Section ordering.
'section_order': [ 'section_order': [
'vim.c', 'vim.c',
@ -122,7 +120,6 @@ CONFIG = {
'lua': { 'lua': {
'mode': 'lua', 'mode': 'lua',
'filename': 'lua.txt', 'filename': 'lua.txt',
'section_start_token': '*lua-vim*',
'section_order': [ 'section_order': [
'_editor.lua', '_editor.lua',
'shared.lua', 'shared.lua',
@ -171,7 +168,6 @@ CONFIG = {
'lsp': { 'lsp': {
'mode': 'lua', 'mode': 'lua',
'filename': 'lsp.txt', 'filename': 'lsp.txt',
'section_start_token': '*lsp-core*',
'section_order': [ 'section_order': [
'lsp.lua', 'lsp.lua',
'buf.lua', 'buf.lua',
@ -214,7 +210,6 @@ CONFIG = {
'diagnostic': { 'diagnostic': {
'mode': 'lua', 'mode': 'lua',
'filename': 'diagnostic.txt', 'filename': 'diagnostic.txt',
'section_start_token': '*diagnostic-api*',
'section_order': [ 'section_order': [
'diagnostic.lua', 'diagnostic.lua',
], ],
@ -231,7 +226,6 @@ CONFIG = {
'treesitter': { 'treesitter': {
'mode': 'lua', 'mode': 'lua',
'filename': 'treesitter.txt', 'filename': 'treesitter.txt',
'section_start_token': '*lua-treesitter-core*',
'section_order': [ 'section_order': [
'treesitter.lua', 'treesitter.lua',
'language.lua', 'language.lua',
@ -1096,6 +1090,7 @@ def main(config, args):
raise RuntimeError( raise RuntimeError(
'found new modules "{}"; update the "section_order" map'.format( 'found new modules "{}"; update the "section_order" map'.format(
set(sections).difference(CONFIG[target]['section_order']))) set(sections).difference(CONFIG[target]['section_order'])))
first_section_tag = sections[CONFIG[target]['section_order'][0]][1]
docs = '' docs = ''
@ -1121,7 +1116,7 @@ def main(config, args):
doc_file = os.path.join(base_dir, 'runtime', 'doc', doc_file = os.path.join(base_dir, 'runtime', 'doc',
CONFIG[target]['filename']) CONFIG[target]['filename'])
delete_lines_below(doc_file, CONFIG[target]['section_start_token']) delete_lines_below(doc_file, first_section_tag)
with open(doc_file, 'ab') as fp: with open(doc_file, 'ab') as fp:
fp.write(docs.encode('utf8')) fp.write(docs.encode('utf8'))