update-scripts: Extract the list of all servers from nvim-lspconfig

This commit is contained in:
Quentin Boyer 2024-09-29 19:04:07 +02:00
parent cab6b0c9fe
commit aa24b3f9d8
8 changed files with 1832 additions and 1 deletions

View file

@ -26,4 +26,5 @@ lib.fix (self: {
efmls-configs-sources = pkgs.callPackage ./efmls-configs.nix { };
none-ls-builtins = pkgs.callPackage ./none-ls.nix { };
rust-analyzer-options = pkgs.callPackage ./rust-analyzer { };
lspconfig-servers = pkgs.callPackage ./nvim-lspconfig { };
})

View file

@ -3,12 +3,17 @@
rust-analyzer-options,
efmls-configs-sources,
none-ls-builtins,
lspconfig-servers,
nixfmt-rfc-style,
nodePackages,
}:
writeShellApplication {
name = "generate";
runtimeInputs = [ nixfmt-rfc-style ];
runtimeInputs = [
nixfmt-rfc-style
nodePackages.prettier
];
text = ''
repo_root=$(git rev-parse --show-toplevel)
@ -37,6 +42,8 @@ writeShellApplication {
generate "${rust-analyzer-options}" "rust-analyzer"
generate "${efmls-configs-sources}" "efmls-configs"
generate "${none-ls-builtins}" "none-ls"
echo "lspconfig servers"
prettier --parser=json "${lspconfig-servers}" >"$generated_dir/lspconfig-servers.json"
if [ -n "$commit" ]; then
cd "$generated_dir"

View file

@ -0,0 +1,23 @@
#!/usr/bin/env python3
import json
import os
import subprocess
import sys
filter = os.environ.get("LUA_FILTER")
if filter is None:
filter = os.path.dirname(__file__) + "/desc-filter.lua"
with open(sys.argv[1]) as f:
data = json.load(f)
for d in data:
if "desc" in d:
if "#" in d["desc"]:
d["desc"] = subprocess.run(
["pandoc", "-t", "markdown", f"--lua-filter={filter}"],
input=d["desc"],
capture_output=True,
text=True,
).stdout
print(json.dumps(data, sort_keys=True))

View file

@ -0,0 +1,37 @@
{
lib,
vimPlugins,
neovimUtils,
wrapNeovimUnstable,
neovim-unwrapped,
runCommand,
pandoc,
python3,
}:
let
nvimConfig = neovimUtils.makeNeovimConfig {
plugins = [
{
plugin = vimPlugins.nvim-lspconfig;
config = null;
optional = false;
}
];
};
nvim = wrapNeovimUnstable neovim-unwrapped nvimConfig;
in
runCommand "lspconfig-servers"
{
lspconfig = "${vimPlugins.nvim-lspconfig}";
nativeBuildInputs = [
pandoc
python3
];
}
''
export HOME=$(realpath .)
# Generates `lsp.json`
${lib.getExe nvim} -u NONE -E -R --headless +'luafile ${./lspconfig-servers.lua}' +q
LUA_FILTER=${./desc-filter.lua} python3 ${./clean-desc.py} "lsp.json" >$out
''

View file

@ -0,0 +1,3 @@
function Header(elem)
return pandoc.Strong(elem.content)
end

View file

@ -0,0 +1,52 @@
-- This script is heavily inspired by https://github.com/neovim/nvim-lspconfig/blob/master/scripts/docgen.lua
require("lspconfig")
local configs = require("lspconfig.configs")
local util = require("lspconfig.util")
local function require_all_configs()
for _, v in ipairs(vim.fn.glob(vim.env.lspconfig .. "/lua/lspconfig/server_configurations/*.lua", 1, 1)) do
local module_name = v:gsub(".*/", ""):gsub("%.lua$", "")
configs[module_name] = require("lspconfig.server_configurations." .. module_name)
end
end
local function map_list(t, func)
local res = {}
for i, v in ipairs(t) do
local x = func(v, i)
if x ~= nil then
table.insert(res, x)
end
end
return res
end
local function sorted_map_table(t, func)
local keys = vim.tbl_keys(t)
table.sort(keys)
return map_list(keys, function(k)
return func(k, t[k])
end)
end
require_all_configs()
info = sorted_map_table(configs, function(server_name, server_info)
local description = nil
if server_info.document_config.docs ~= nil then
description = server_info.document_config.docs.description
end
local cmd = server_info.document_config.default_config.cmd
if type(cmd) == "function" then
cmd = "see source file"
end
return {
name = server_name,
cmd = cmd,
desc = description,
}
end)
local writer = io.open("lsp.json", "w")
writer:write(vim.json.encode(info))
writer:close()