Skip to content

Commit

Permalink
update-scripts: Extract the list of all servers from nvim-lspconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
traxys committed Oct 8, 2024
1 parent cab6b0c commit aa24b3f
Show file tree
Hide file tree
Showing 8 changed files with 1,832 additions and 1 deletion.
1,705 changes: 1,705 additions & 0 deletions generated/lspconfig-servers.json

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions typos.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[files]
extend-exclude = ["**/lspconfig-servers.json"]

[default.extend-words]
tabe = "tabe"
noice = "noice"
Expand Down
1 change: 1 addition & 0 deletions update-scripts/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 { };
})
9 changes: 8 additions & 1 deletion update-scripts/generate.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"
Expand Down
23 changes: 23 additions & 0 deletions update-scripts/nvim-lspconfig/clean-desc.py
Original file line number Diff line number Diff line change
@@ -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))
37 changes: 37 additions & 0 deletions update-scripts/nvim-lspconfig/default.nix
Original file line number Diff line number Diff line change
@@ -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
''
3 changes: 3 additions & 0 deletions update-scripts/nvim-lspconfig/desc-filter.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function Header(elem)
return pandoc.Strong(elem.content)
end
52 changes: 52 additions & 0 deletions update-scripts/nvim-lspconfig/lspconfig-servers.lua
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit aa24b3f

Please sign in to comment.