From 214ce8d33c11f75b3500212258f09b58b3d42e80 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Tue, 8 Oct 2024 07:42:20 -0700 Subject: fix(gen_help_html): first tag in h2 is broken #30720 Problem: In h2 headings, the first tag points to an invalid anchor. This used to work but regressed a few months ago, possibly related to ceea6898a8bdcb6c4cfe06b8dc4739c144e6b1f8. Solution: - Simplify the logic, don't try to be clever: - Always use to_heading_tag() for the h2 `id`. - Also: - Render tags as ``, because `` is unnecessary and doesn't look great in headings. - In the main h1, use "foo.txt" as the anchor `name` (rarely used), prefer the next found tag for the `href`. --- scripts/gen_help_html.lua | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) (limited to 'scripts') diff --git a/scripts/gen_help_html.lua b/scripts/gen_help_html.lua index f6e799508b..b5dbce38f6 100644 --- a/scripts/gen_help_html.lua +++ b/scripts/gen_help_html.lua @@ -554,11 +554,8 @@ local function visit_node(root, level, lang_tree, headings, opt, stats) return '' -- Spurious "===" or "---" in the help doc. end - -- Use the first *tag* node as the heading anchor, if any. - local tagnode = first(heading_node, 'tag') - -- Use the *tag* as the heading anchor id, if possible. - local tagname = tagnode and url_encode(trim(node_text(tagnode:child(1), false))) - or to_heading_tag(hname) + -- Generate an anchor id from the heading text. + local tagname = to_heading_tag(hname) if node_name == 'h1' or #headings == 0 then ---@type nvim.gen_help_html.heading local heading = { name = hname, subheadings = {}, tag = tagname } @@ -678,7 +675,7 @@ local function visit_node(root, level, lang_tree, headings, opt, stats) table.insert(stats.first_tags, tagname) return '' end - local el = in_heading and 'span' or 'code' + local el = 'span' local encoded_tagname = url_encode(tagname) local s = ('%s<%s id="%s" class="%s">%s'):format( ws(), @@ -694,15 +691,6 @@ local function visit_node(root, level, lang_tree, headings, opt, stats) end if in_heading and prev ~= 'tag' then - -- Don't set "id", let the heading use the tag as its "id" (used by search engines). - s = ('%s<%s class="%s">%s'):format( - ws(), - el, - cssclass, - encoded_tagname, - trimmed, - el - ) -- Start the container for tags in a heading. -- This makes "justify-content:space-between" right-align the tags. --

foo bartag1 tag2

@@ -957,7 +945,7 @@ local function gen_one(fname, text, to_fname, old, commit, parser_path)
-

%s

+

%s

Nvim :help pages, generated @@ -970,8 +958,9 @@ local function gen_one(fname, text, to_fname, old, commit, parser_path)

]]):format( logo_svg, - stats.first_tags[2] or '', stats.first_tags[1] or '', + stats.first_tags[2] or '', + stats.first_tags[2] or '', title, vim.fs.basename(fname), main -- cgit From b5e69b32d7e299b8283f13f4f97081f6cf795f0a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 18 Oct 2024 17:38:29 +0800 Subject: vim-patch: make gen_opt_test.vim work with Nvim (#30850) Problem: Insufficient test coverage for validation of option values. Solution: Port Vim's gen_opt_test.vim and make it work with Nvim. vim-patch:9.1.0760: tests: no error reported, if gen_opt_test.vim fails vim-patch:9.1.0791: tests: errors in gen_opt_test.vim are not shown --- scripts/vim-patch.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'scripts') diff --git a/scripts/vim-patch.sh b/scripts/vim-patch.sh index bfa9f6d99c..b0ec225633 100755 --- a/scripts/vim-patch.sh +++ b/scripts/vim-patch.sh @@ -213,8 +213,8 @@ preprocess_patch() { # Remove "Last change ..." changes in doc files. 2>/dev/null $nvim --cmd 'set dir=/tmp' +'%s/^@@.*\n.*For Vim version.*Last change.*\n.*For Vim version.*Last change.*//' +w +q "$file" - # Remove gui, option, setup, screen dumps, testdir/Make_*.mak files - local na_src_testdir='gen_opt_test\.vim\|gui_.*\|Make_amiga\.mak\|Make_dos\.mak\|Make_ming\.mak\|Make_vms\.mms\|dumps/.*\.dump\|setup_gui\.vim' + # Remove gui, setup, screen dumps, testdir/Make_*.mak files + local na_src_testdir='gui_.*\|Make_amiga\.mak\|Make_dos\.mak\|Make_ming\.mak\|Make_vms\.mms\|dumps/.*\.dump\|setup_gui\.vim' 2>/dev/null $nvim --cmd 'set dir=/tmp' +'g@^diff --git a/src/testdir/\<\%('"${na_src_testdir}"'\)\>@exe "norm! d/\\v(^diff)|%$\r"' +w +q "$file" # Remove testdir/test_*.vim files -- cgit From 18b43c331d8a0ed87d7cbefe2a18543b8e4ad360 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Thu, 17 Oct 2024 11:16:16 +0200 Subject: refactor: rename vim.highlight => vim.hl Problem: - `vim.highlight` module does not follow `:help dev-name-common`, which documents the name for "highlight" as "hl". - Shorter names are usually preferred. Solution: Rename `vim.highlight` to `vim.hl`. This is not a breaking change until 2.0 (or maybe never). --- scripts/gen_vimdoc.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'scripts') diff --git a/scripts/gen_vimdoc.lua b/scripts/gen_vimdoc.lua index 8908097397..f7c95e222d 100755 --- a/scripts/gen_vimdoc.lua +++ b/scripts/gen_vimdoc.lua @@ -135,7 +135,7 @@ local config = { lua = { filename = 'lua.txt', section_order = { - 'highlight.lua', + 'hl.lua', 'diff.lua', 'mpack.lua', 'json.lua', @@ -174,7 +174,7 @@ local config = { 'runtime/lua/vim/filetype.lua', 'runtime/lua/vim/keymap.lua', 'runtime/lua/vim/fs.lua', - 'runtime/lua/vim/highlight.lua', + 'runtime/lua/vim/hl.lua', 'runtime/lua/vim/secure.lua', 'runtime/lua/vim/version.lua', 'runtime/lua/vim/_inspector.lua', @@ -221,7 +221,7 @@ local config = { end if contains(name, { - 'highlight', + 'hl', 'mpack', 'json', 'base64', -- cgit From 3572319b4cb1a4163624a5fe328886f1928dbc4a Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 18 Oct 2024 11:33:12 +0100 Subject: feat(vim.validate): improve fast form and deprecate spec form Problem: `vim.validate()` takes two forms when it only needs one. Solution: - Teach the fast form all the features of the spec form. - Deprecate the spec form. - General optimizations for both forms. - Add a `message` argument which can be used alongside or in place of the `optional` argument. --- scripts/bump_deps.lua | 6 ++---- scripts/gen_help_html.lua | 52 +++++++++++++++-------------------------------- 2 files changed, 18 insertions(+), 40 deletions(-) (limited to 'scripts') diff --git a/scripts/bump_deps.lua b/scripts/bump_deps.lua index e332ef475f..ad71da5150 100755 --- a/scripts/bump_deps.lua +++ b/scripts/bump_deps.lua @@ -325,10 +325,8 @@ function M.commit(dependency_name, commit) end function M.version(dependency_name, version) - vim.validate { - dependency_name = { dependency_name, 's' }, - version = { version, 's' }, - } + vim.validate('dependency_name', dependency_name, 'string') + vim.validate('version', version, 'string') local dependency = assert(get_dependency(dependency_name)) verify_cmakelists_committed() local commit_sha = get_gh_commit_sha(dependency.repo, version) diff --git a/scripts/gen_help_html.lua b/scripts/gen_help_html.lua index b5dbce38f6..21d865309d 100644 --- a/scripts/gen_help_html.lua +++ b/scripts/gen_help_html.lua @@ -1289,25 +1289,15 @@ end --- --- @return nvim.gen_help_html.gen_result result function M.gen(help_dir, to_dir, include, commit, parser_path) - vim.validate { - help_dir = { - help_dir, - function(d) - return vim.fn.isdirectory(vim.fs.normalize(d)) == 1 - end, - 'valid directory', - }, - to_dir = { to_dir, 's' }, - include = { include, 't', true }, - commit = { commit, 's', true }, - parser_path = { - parser_path, - function(f) - return f == nil or vim.fn.filereadable(vim.fs.normalize(f)) == 1 - end, - 'valid vimdoc.{so,dll} filepath', - }, - } + vim.validate('help_dir', help_dir, function(d) + return vim.fn.isdirectory(vim.fs.normalize(d)) == 1 + end, 'valid directory') + vim.validate('to_dir', to_dir, 'string') + vim.validate('include', include, 'table', true) + vim.validate('commit', commit, 'sring', true) + vim.validate('parser_path', parser_path, function(f) + return vim.fn.filereadable(vim.fs.normalize(f)) == 1 + end, true, 'valid vimdoc.{so,dll} filepath') local err_count = 0 local redirects_count = 0 @@ -1410,23 +1400,13 @@ end --- --- @return nvim.gen_help_html.validate_result result function M.validate(help_dir, include, parser_path) - vim.validate { - help_dir = { - help_dir, - function(d) - return vim.fn.isdirectory(vim.fs.normalize(d)) == 1 - end, - 'valid directory', - }, - include = { include, 't', true }, - parser_path = { - parser_path, - function(f) - return f == nil or vim.fn.filereadable(vim.fs.normalize(f)) == 1 - end, - 'valid vimdoc.{so,dll} filepath', - }, - } + vim.validate('help_dir', help_dir, function(d) + return vim.fn.isdirectory(vim.fs.normalize(d)) == 1 + end, 'valid directory') + vim.validate('include', include, 'table', true) + vim.validate('parser_path', parser_path, function(f) + return vim.fn.filereadable(vim.fs.normalize(f)) == 1 + end, true, 'valid vimdoc.{so,dll} filepath') local err_count = 0 ---@type integer local files_to_errors = {} ---@type table ensure_runtimepath() -- cgit From f663243e95f488b8f4224bdae2697ddac21d0ffb Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 22 Oct 2024 09:05:14 +0800 Subject: vim-patch:9.1.0797: testing of options can be further improved (#30893) Problem: testing of options can be further improved Solution: split the generated option test into test_options_all.vim, add more test cases, save and restore values, fix use-after-free closes: vim/vim#15894 https://github.com/vim/vim/commit/6eca04e9f1d446dc509ba51e32da56fa413fe2f0 Co-authored-by: Milly --- scripts/gen_eval_files.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts') diff --git a/scripts/gen_eval_files.lua b/scripts/gen_eval_files.lua index b9ea4e73f0..eb92e10401 100755 --- a/scripts/gen_eval_files.lua +++ b/scripts/gen_eval_files.lua @@ -670,7 +670,7 @@ local function scope_to_doc(s) return m[s[1]] end assert(s[1] == 'global') - return 'global or ' .. m[s[2]] .. ' |global-local|' + return 'global or ' .. m[s[2]] .. (s[2] ~= 'tab' and ' |global-local|' or '') end -- @param o vim.option_meta -- cgit From 07b4cb6ada2da108bbf8277bec63068234ceaa67 Mon Sep 17 00:00:00 2001 From: Famiu Haque Date: Tue, 22 Oct 2024 22:14:01 +0600 Subject: docs(options): remove description for hidden options #30903 Problem: Hidden options are documented despite being no-ops. Solution: Remove docs for hidden options. Move tags for options that we plan to restore, to ":help nvim-missing". Move tags for permanently removed options, to ":help nvim-removed". --- scripts/gen_eval_files.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts') diff --git a/scripts/gen_eval_files.lua b/scripts/gen_eval_files.lua index eb92e10401..2928361695 100755 --- a/scripts/gen_eval_files.lua +++ b/scripts/gen_eval_files.lua @@ -717,7 +717,7 @@ local function get_option_meta() local optinfo = vim.api.nvim_get_all_options_info() local ret = {} --- @type table for _, o in ipairs(opts) do - if o.desc then + if not o.immutable and not o.hidden and o.enable_if ~= false and o.desc then if o.full_name == 'cmdheight' then table.insert(o.scope, 'tab') end -- cgit From 3a86b60032bd659c2b12e984abb40cee93568558 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sun, 29 Sep 2024 14:07:21 +0200 Subject: docs: misc Co-authored-by: David Pedersen Co-authored-by: Gregory Anders Co-authored-by: Leo Schlosser Co-authored-by: zeertzjq --- scripts/gen_help_html.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts') diff --git a/scripts/gen_help_html.lua b/scripts/gen_help_html.lua index 21d865309d..b8f80e94be 100644 --- a/scripts/gen_help_html.lua +++ b/scripts/gen_help_html.lua @@ -1294,7 +1294,7 @@ function M.gen(help_dir, to_dir, include, commit, parser_path) end, 'valid directory') vim.validate('to_dir', to_dir, 'string') vim.validate('include', include, 'table', true) - vim.validate('commit', commit, 'sring', true) + vim.validate('commit', commit, 'string', true) vim.validate('parser_path', parser_path, function(f) return vim.fn.filereadable(vim.fs.normalize(f)) == 1 end, true, 'valid vimdoc.{so,dll} filepath') -- cgit From 3275ae830da97ef907ff3cfb0170706b6a430f57 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Thu, 24 Oct 2024 10:31:34 +0100 Subject: fix(lsp.protocal): improve typing of constants --- scripts/gen_vimdoc.lua | 3 +++ 1 file changed, 3 insertions(+) (limited to 'scripts') diff --git a/scripts/gen_vimdoc.lua b/scripts/gen_vimdoc.lua index f7c95e222d..9cd5b598da 100755 --- a/scripts/gen_vimdoc.lua +++ b/scripts/gen_vimdoc.lua @@ -289,6 +289,9 @@ local config = { }, fn_xform = function(fun) fun.name = fun.name:gsub('result%.', '') + if fun.module == 'vim.lsp.protocol' then + fun.classvar = nil + end end, section_fmt = function(name) if name:lower() == 'lsp' then -- cgit From 9b357e30fdd0a575480182872331fdb87e9cc331 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Tue, 29 Oct 2024 09:36:02 +0000 Subject: feat(lsp)!: remove client-server handlers from vim.lsp.handlers - Partition the handlers in vim.lsp.handlers as: - client to server response handlers (RCS) - server to client request handlers (RSC) - server to client notification handlers (NSC) Note use string indexes instead of protocol.methods for improved typing in LuaLS (tip: use hover on RCS, RSC or NSC). --- scripts/gen_lsp.lua | 43 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 8 deletions(-) (limited to 'scripts') diff --git a/scripts/gen_lsp.lua b/scripts/gen_lsp.lua index c8dcf8c018..8afbae239a 100644 --- a/scripts/gen_lsp.lua +++ b/scripts/gen_lsp.lua @@ -58,14 +58,6 @@ end ---@param protocol vim._gen_lsp.Protocol local function gen_methods(protocol) - local output = { - '-- Generated by gen_lsp.lua, keep at end of file.', - '---', - '---@enum vim.lsp.protocol.Methods', - '---@see https://microsoft.github.io/language-server-protocol/specification/#metaModel', - '--- LSP method names.', - 'protocol.Methods = {', - } local indent = (' '):rep(2) --- @class vim._gen_lsp.Request @@ -98,6 +90,41 @@ local function gen_methods(protocol) table.sort(all, function(a, b) return to_luaname(a.method) < to_luaname(b.method) end) + + local output = { + '-- Generated by gen_lsp.lua, keep at end of file.', + '--- @alias vim.lsp.protocol.Method.ClientToServer', + } + for _, item in ipairs(all) do + if item.method and item.messageDirection == 'clientToServer' then + output[#output + 1] = ("--- | '%s',"):format(item.method) + end + end + + vim.list_extend(output, { + '', + '--- @alias vim.lsp.protocol.Method.ServerToClient', + }) + for _, item in ipairs(all) do + if item.method and item.messageDirection == 'serverToClient' then + output[#output + 1] = ("--- | '%s',"):format(item.method) + end + end + + vim.list_extend(output, { + '', + '--- @alias vim.lsp.protocol.Method', + '--- | vim.lsp.protocol.Method.ClientToServer', + '--- | vim.lsp.protocol.Method.ServerToClient', + '', + '-- Generated by gen_lsp.lua, keep at end of file.', + '---', + '--- @enum vim.lsp.protocol.Methods', + '--- @see https://microsoft.github.io/language-server-protocol/specification/#metaModel', + '--- LSP method names.', + 'protocol.Methods = {', + }) + for _, item in ipairs(all) do if item.method then if item.documentation then -- cgit From a27419f3fc540f66567f4559a796cd6758f1bb1f Mon Sep 17 00:00:00 2001 From: Famiu Haque Date: Mon, 4 Nov 2024 19:00:12 +0600 Subject: feat(options)!: disallow setting hidden options #28400 Problem: There are three different ways of marking an option as hidden, `enable_if = false`, `hidden = true` and `immutable = true`. These also have different behaviors. Options hidden with `enable_if = false` can't have their value fetched using Vim script or the API, but options hidden with `hidden = true` or `immutable = true` can. On the other hand, options with `hidden = true` do not error when trying to set their value, but options with `immutable = true` do. Solution: Remove `enable_if = false`, remove the `hidden` property for options, and use `immutable = true` to mark an option as hidden instead. Also make hidden option variable pointers always point to the default value, which allows fetching the value of every hidden option using Vim script and the API. This does also mean that trying to set a hidden option will now give an error instead of just being ignored. --- scripts/gen_eval_files.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'scripts') diff --git a/scripts/gen_eval_files.lua b/scripts/gen_eval_files.lua index 2928361695..edf95043c5 100755 --- a/scripts/gen_eval_files.lua +++ b/scripts/gen_eval_files.lua @@ -717,7 +717,9 @@ local function get_option_meta() local optinfo = vim.api.nvim_get_all_options_info() local ret = {} --- @type table for _, o in ipairs(opts) do - if not o.immutable and not o.hidden and o.enable_if ~= false and o.desc then + local is_window_option = #o.scope == 1 and o.scope[1] == 'window' + local is_option_hidden = o.immutable and not o.varname and not is_window_option + if not is_option_hidden and o.desc then if o.full_name == 'cmdheight' then table.insert(o.scope, 'tab') end -- cgit From 29ded889579a9d590e8ea885a9a402ff4bae87be Mon Sep 17 00:00:00 2001 From: Famiu Haque Date: Sun, 17 Nov 2024 02:56:16 +0600 Subject: refactor(options): remove `.indir`, redesign option scopes #31066 Problem: The way option scopes currently work is inflexible and does not allow for nested option scopes or easily finding the value of an option at any arbitrary scope without having to do long handwritten switch-case statements like in `get_varp()`. `.indir` is also confusing and redundant since option indices for each scope can be autogenerated. Solution: Expand option scopes in such a way that an option can support any amount of scopes using a set of scope flags, similarly to how it's already done for option types. Also make options contain information about its index at each scope it supports. This allows for massively simplifying `get_varp()` and `get_varp_scope()` in the future by just using a struct for options at each scope. This would be done by creating a table that stores the offset of an option's variable at a scope by using the option's index at that scope as a key. This PR also autogenerates enums for option indices at each scope to remove the need for `.indir` entirely, and also to allow easily iterating over options all options that support any scope. Ref: #29314 --- scripts/gen_eval_files.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'scripts') diff --git a/scripts/gen_eval_files.lua b/scripts/gen_eval_files.lua index edf95043c5..a9431ae2e5 100755 --- a/scripts/gen_eval_files.lua +++ b/scripts/gen_eval_files.lua @@ -617,8 +617,8 @@ local function render_option_meta(_f, opt, write) end for _, s in pairs { - { 'wo', 'window' }, - { 'bo', 'buffer' }, + { 'wo', 'win' }, + { 'bo', 'buf' }, { 'go', 'global' }, } do local id, scope = s[1], s[2] @@ -661,8 +661,8 @@ end local function scope_to_doc(s) local m = { global = 'global', - buffer = 'local to buffer', - window = 'local to window', + buf = 'local to buffer', + win = 'local to window', tab = 'local to tab page', } @@ -717,7 +717,7 @@ local function get_option_meta() local optinfo = vim.api.nvim_get_all_options_info() local ret = {} --- @type table for _, o in ipairs(opts) do - local is_window_option = #o.scope == 1 and o.scope[1] == 'window' + local is_window_option = #o.scope == 1 and o.scope[1] == 'win' local is_option_hidden = o.immutable and not o.varname and not is_window_option if not is_option_hidden and o.desc then if o.full_name == 'cmdheight' then -- cgit