From 9624fffcfa141335f772938d8c441bdb300e04e6 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Thu, 24 Oct 2024 15:34:52 +0200 Subject: feat(docs): autogenerate default_config docs Problem: Docs are manually maintained everywhere for no good reason. Solution: - revert commit 9dc02492c4a457479f8a0ec7a65aac1852ff59c0 - provide a "gF" friendly link to the source --- lua/lspconfig/configs/ada_ls.lua | 3 -- lua/lspconfig/configs/aiken.lua | 4 --- lua/lspconfig/configs/clangd.lua | 50 +++++++++++---------------------- lua/lspconfig/configs/ts_ls.lua | 3 -- lua/lspconfig/configs/ttags.lua | 3 -- lua/lspconfig/configs/typeprof.lua | 3 -- lua/lspconfig/configs/uiua.lua | 11 -------- lua/lspconfig/configs/wgsl_analyzer.lua | 3 -- lua/lspconfig/configs/yang_lsp.lua | 3 -- lua/lspconfig/configs/ziggy_schema.lua | 3 -- lua/lspconfig/configs/zk.lua | 3 -- lua/lspconfig/configs/zls.lua | 4 --- 12 files changed, 16 insertions(+), 77 deletions(-) (limited to 'lua') diff --git a/lua/lspconfig/configs/ada_ls.lua b/lua/lspconfig/configs/ada_ls.lua index 3a8c79b0..c532f641 100644 --- a/lua/lspconfig/configs/ada_ls.lua +++ b/lua/lspconfig/configs/ada_ls.lua @@ -25,8 +25,5 @@ require('lspconfig').ada_ls.setup{ } ``` ]], - default_config = { - root_dir = [[util.root_pattern("Makefile", ".git", "*.gpr", "*.adc")]], - }, }, } diff --git a/lua/lspconfig/configs/aiken.lua b/lua/lspconfig/configs/aiken.lua index 8025fe1e..3c9e2562 100644 --- a/lua/lspconfig/configs/aiken.lua +++ b/lua/lspconfig/configs/aiken.lua @@ -17,9 +17,5 @@ A language server for Aiken Programming Language. It can be i ]], - default_config = { - cmd = { 'aiken', 'lsp' }, - root_dir = [[root_pattern("aiken.toml", ".git")]], - }, }, } diff --git a/lua/lspconfig/configs/clangd.lua b/lua/lspconfig/configs/clangd.lua index f5fc804d..ffee2af7 100644 --- a/lua/lspconfig/configs/clangd.lua +++ b/lua/lspconfig/configs/clangd.lua @@ -46,33 +46,29 @@ local function symbol_info() end, bufnr) end -local root_files = { - '.clangd', - '.clang-tidy', - '.clang-format', - 'compile_commands.json', - 'compile_flags.txt', - 'configure.ac', -- AutoTools -} - -local default_capabilities = { - textDocument = { - completion = { - editsNearCursor = true, - }, - }, - offsetEncoding = { 'utf-8', 'utf-16' }, -} - return { default_config = { cmd = { 'clangd' }, filetypes = { 'c', 'cpp', 'objc', 'objcpp', 'cuda', 'proto' }, root_dir = function(fname) - return util.root_pattern(unpack(root_files))(fname) or util.find_git_ancestor(fname) + return util.root_pattern( + '.clangd', + '.clang-tidy', + '.clang-format', + 'compile_commands.json', + 'compile_flags.txt', + 'configure.ac' -- AutoTools + )(fname) or util.find_git_ancestor(fname) end, single_file_support = true, - capabilities = default_capabilities, + capabilities = { + textDocument = { + completion = { + editsNearCursor = true, + }, + }, + offsetEncoding = { 'utf-8', 'utf-16' }, + } }, commands = { ClangdSwitchSourceHeader = { @@ -101,19 +97,5 @@ https://clangd.llvm.org/installation.html - clangd relies on a [JSON compilation database](https://clang.llvm.org/docs/JSONCompilationDatabase.html) specified as compile_commands.json, see https://clangd.llvm.org/installation#compile_commandsjson ]], - default_config = { - root_dir = [[ - root_pattern( - '.clangd', - '.clang-tidy', - '.clang-format', - 'compile_commands.json', - 'compile_flags.txt', - 'configure.ac', - '.git' - ) - ]], - capabilities = [[default capabilities, with offsetEncoding utf-8]], - }, }, } diff --git a/lua/lspconfig/configs/ts_ls.lua b/lua/lspconfig/configs/ts_ls.lua index 38a7c800..1eafd91b 100644 --- a/lua/lspconfig/configs/ts_ls.lua +++ b/lua/lspconfig/configs/ts_ls.lua @@ -83,8 +83,5 @@ require'lspconfig'.ts_ls.setup{ `filetypes` is extended here to include Vue SFC. ]], - default_config = { - root_dir = [[root_pattern("tsconfig.json", "jsconfig.json", "package.json", ".git")]], - }, }, } diff --git a/lua/lspconfig/configs/ttags.lua b/lua/lspconfig/configs/ttags.lua index d57a7967..bbc762d5 100644 --- a/lua/lspconfig/configs/ttags.lua +++ b/lua/lspconfig/configs/ttags.lua @@ -10,8 +10,5 @@ return { description = [[ https://github.com/npezza93/ttags ]], - default_config = { - root_dir = [[root_pattern(".git")]], - }, }, } diff --git a/lua/lspconfig/configs/typeprof.lua b/lua/lspconfig/configs/typeprof.lua index ab9dc8ef..09ef2a2f 100644 --- a/lua/lspconfig/configs/typeprof.lua +++ b/lua/lspconfig/configs/typeprof.lua @@ -12,8 +12,5 @@ https://github.com/ruby/typeprof `typeprof` is the built-in analysis and LSP tool for Ruby 3.1+. ]], - default_config = { - root_dir = [[root_pattern("Gemfile", ".git")]], - }, }, } diff --git a/lua/lspconfig/configs/uiua.lua b/lua/lspconfig/configs/uiua.lua index b102f8c3..54d23ac9 100644 --- a/lua/lspconfig/configs/uiua.lua +++ b/lua/lspconfig/configs/uiua.lua @@ -16,16 +16,5 @@ The builtin language server of the Uiua interpreter. The Uiua interpreter can be installed with `cargo install uiua` ]], - default_config = { - cmd = { 'uiua', 'lsp' }, - filetypes = { 'uiua' }, - root_dir = [[ - root_pattern( - 'main.ua', - 'fmt.ua', - '.git' - ) - ]], - }, }, } diff --git a/lua/lspconfig/configs/wgsl_analyzer.lua b/lua/lspconfig/configs/wgsl_analyzer.lua index 2325cc6e..bfa2f5e9 100644 --- a/lua/lspconfig/configs/wgsl_analyzer.lua +++ b/lua/lspconfig/configs/wgsl_analyzer.lua @@ -16,8 +16,5 @@ https://github.com/wgsl-analyzer/wgsl-analyzer cargo install --git https://github.com/wgsl-analyzer/wgsl-analyzer wgsl_analyzer ``` ]], - default_config = { - root_dir = [[root_pattern(".git")]], - }, }, } diff --git a/lua/lspconfig/configs/yang_lsp.lua b/lua/lspconfig/configs/yang_lsp.lua index d4c9b8b6..13f6fa35 100644 --- a/lua/lspconfig/configs/yang_lsp.lua +++ b/lua/lspconfig/configs/yang_lsp.lua @@ -12,8 +12,5 @@ https://github.com/TypeFox/yang-lsp A Language Server for the YANG data modeling language. ]], - default_config = { - root_dir = [[util.find_git_ancestor]], - }, }, } diff --git a/lua/lspconfig/configs/ziggy_schema.lua b/lua/lspconfig/configs/ziggy_schema.lua index 2bd01cc8..cd19cf35 100644 --- a/lua/lspconfig/configs/ziggy_schema.lua +++ b/lua/lspconfig/configs/ziggy_schema.lua @@ -14,8 +14,5 @@ https://ziggy-lang.io/documentation/ziggy-lsp/ Language server for schema files of the Ziggy data serialization format ]], - default_config = { - root_dir = [[util.find_git_ancestor]], - }, }, } diff --git a/lua/lspconfig/configs/zk.lua b/lua/lspconfig/configs/zk.lua index 57a1ea1a..b24f1686 100644 --- a/lua/lspconfig/configs/zk.lua +++ b/lua/lspconfig/configs/zk.lua @@ -72,8 +72,5 @@ https://github.com/mickael-menu/zk A plain text note-taking assistant ]], - default_config = { - root_dir = [[root_pattern(".zk")]], - }, }, } diff --git a/lua/lspconfig/configs/zls.lua b/lua/lspconfig/configs/zls.lua index 8deeda97..540f4bd8 100644 --- a/lua/lspconfig/configs/zls.lua +++ b/lua/lspconfig/configs/zls.lua @@ -18,9 +18,5 @@ https://github.com/zigtools/zls Zig LSP implementation + Zig Language Server ]], - default_config = { - cmd = { 'zls' }, - root_dir = [[util.root_pattern("zls.json", "build.zig", ".git")]], - }, }, } -- cgit v1.2.3-70-g09d2 From 903866024cd6c93a6acefd359329364234a65754 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Thu, 24 Oct 2024 17:05:21 +0200 Subject: feat(docs): autogenerate default_config docs Problem: debug.info() is useless for some functions because they point to util.lua Solution: Provide a path to the source code instead of trying to inline the source code. --- lua/lspconfig/configs/clangd.lua | 2 +- scripts/docgen.lua | 44 ++++++++++++++++++++-------------------- 2 files changed, 23 insertions(+), 23 deletions(-) (limited to 'lua') diff --git a/lua/lspconfig/configs/clangd.lua b/lua/lspconfig/configs/clangd.lua index ffee2af7..06c75095 100644 --- a/lua/lspconfig/configs/clangd.lua +++ b/lua/lspconfig/configs/clangd.lua @@ -68,7 +68,7 @@ return { }, }, offsetEncoding = { 'utf-8', 'utf-16' }, - } + }, }, commands = { ClangdSwitchSourceHeader = { diff --git a/scripts/docgen.lua b/scripts/docgen.lua index 4a62562d..22abc294 100644 --- a/scripts/docgen.lua +++ b/scripts/docgen.lua @@ -83,7 +83,7 @@ require'lspconfig'.{{config_name}}.setup{} ``` {{commands}} -**Default values:** +**Default config:** {{default_values}} ]] @@ -113,6 +113,8 @@ local function make_lsp_sections() map_sorted(configs, function(config_name, template_object) local template_def = template_object.config_def local docs = template_def.docs + -- "lua/lspconfig/configs/xx.lua" + local config_file = ('lua/lspconfig/configs/%s.lua'):format(config_name) local params = { config_name = config_name, @@ -145,31 +147,29 @@ local function make_lsp_sections() end return make_section(0, '\n', { map_sorted(template_def.default_config, function(k, v) - local description = template_def.default_config[k] if type(v) ~= 'function' then - description = inspect(v) - else - local info = debug.getinfo(v) - local relname = relpath(info.source) - local file = assert(io.open(string.sub(info.source, 2), 'r')) + return ('- `%s` :\n```lua\n%s\n```'):format(k, inspect(v)) + end - local fnbody = '' - local linenr = 0 - for line in file:lines() do - linenr = linenr + 1 - if linenr >= info.linedefined and linenr <= info.lastlinedefined then - fnbody = ('%s\n%s'):format(fnbody, line) - end + local file = assert(io.open(config_file, 'r')) + local linenr = 0 + -- Find the line where `default_config` is defined. + for line in file:lines() do + linenr = linenr + 1 + if line:find('%sdefault_config%s') then + break end - io.close(file) - - description = ('-- Source (use "gF" to visit): %s:%d\n'):format( - relname, - info.linedefined, - string.gsub(fnbody, '.*function', 'function') - ) end - return string.format('- `%s` : \n```lua\n%s\n```', k, description or inspect(v)) + io.close(file) + + -- XXX: "../" because the path is outside of the doc/ dir. + return ('- `%s` source (use "gF" to visit): [../%s:%d](../%s#L%d)\n'):format( + k, + config_file, + linenr, + config_file, + linenr + ) end), }) end, -- cgit v1.2.3-70-g09d2