rename "skeleton" to "configs" #100

`nvim_lsp/skeleton.lua` is not really a skeleton, it's a `configs`
class that provides

1. actual functionality
2. a bunch of configs

Each config is added to the `configs` object (FKA "skeleton") as
a property. Those configs are not "templates", they are "configs". So we
should clean up the wording in various places to say "config" instead of
"skeleton"/"template".

Closes #64
This commit is contained in:
Michael Lingelbach 2020-01-31 00:00:50 -08:00 committed by GitHub
parent 6ea517f5c3
commit b487481e19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
31 changed files with 120 additions and 120 deletions

View File

@ -18,15 +18,15 @@ To preview the generated `README.md` locally, source `scripts/docgen.lua` from
It **must** be run from the `.git`/project root. (TODO: try to find the `.git`
root with one of our `util.*` functions?)
# skeleton
# configs
skeleton has a `__newindex` metamethod which validates and creates
configs has a `__newindex` metamethod which validates and creates
an object containing `setup()`, which can then be retrieved and modified.
In `vim.validate` parlance, this is the "spec":
```
skeleton.SERVER_NAME = {
configs.SERVER_NAME = {
default_config = {'t'};
on_new_config = {'f', true};
on_attach = {'f', true};
@ -40,7 +40,7 @@ docs = {
```
- Keys of the `docs.default_config` table match those of
`skeleton.SERVER_NAME.default_config`, and can be used to specify custom
`configs.SERVER_NAME.default_config`, and can be used to specify custom
documentation. This is useful for functions, whose docs cannot be easily
auto-generated.
- The `commands` object is a table of `name:definition` key:value pairs, where
@ -63,12 +63,12 @@ Example:
```
After you create `skeleton.SERVER_NAME`, you may add arbitrary
After you create `configs.SERVER_NAME`, you may add arbitrary
language-specific functions to it if necessary.
Example:
skeleton.texlab.buf_build = buf_build
configs.texlab.buf_build = buf_build
Finally, add a `require 'nvim_lsp/SERVER_NAME'` line to `lua/nvim_lsp.lua`.

View File

@ -83,7 +83,7 @@ nvim_lsp.texlab.setup{
### Example: custom config
To configure a custom/private server, just require `nvim_lsp/skeleton` and do
To configure a custom/private server, just require `nvim_lsp/configs` and do
the same as we do if we were adding it to the repository itself.
1. Define the config: `configs.foo_lsp = { … }`
@ -91,7 +91,7 @@ the same as we do if we were adding it to the repository itself.
```lua
local nvim_lsp = require'nvim_lsp'
local configs = require'nvim_lsp/skeleton'
local configs = require'nvim_lsp/configs'
-- Check if it's already defined for when I reload this file.
if not nvim_lsp.foo_lsp then
configs.foo_lsp = {

View File

@ -1,4 +1,4 @@
local skeleton = require 'nvim_lsp/skeleton'
local configs = require 'nvim_lsp/configs'
require 'nvim_lsp/bashls'
require 'nvim_lsp/ccls'
@ -32,12 +32,12 @@ local M = {
}
function M.available_servers()
return vim.tbl_keys(skeleton)
return vim.tbl_keys(configs)
end
function M.installable_servers()
local res = {}
for k, v in pairs(skeleton) do
for k, v in pairs(configs) do
if v.install then table.insert(res, k) end
end
return res
@ -50,17 +50,17 @@ function M._root._setup()
M._root.commands = {
LspInstall = {
function(name)
local template = skeleton[name]
if not template then
local config = configs[name]
if not config then
return print("Invalid server name:", name)
end
if not template.install then
if not config.install then
return print(name, "can't be automatically installed (yet)")
end
if template.install_info().is_installed then
if config.install_info().is_installed then
return print(name, "is already installed")
end
template.install()
config.install()
end;
"-nargs=1";
"-complete=custom,v:lua.lsp_complete_installable_servers";
@ -70,18 +70,18 @@ function M._root._setup()
function(name)
if name == nil then
local res = {}
for k, v in pairs(skeleton) do
for k, v in pairs(configs) do
if v.install_info then
res[k] = v.install_info()
end
end
return print(vim.inspect(res))
end
local template = skeleton[name]
if not template then
local config = configs[name]
if not config then
return print("Invalid server name:", name)
end
return print(vim.inspect(template.install_info()))
return print(vim.inspect(config.install_info()))
end;
"-nargs=?";
"-complete=custom,v:lua.lsp_complete_servers";
@ -94,7 +94,7 @@ end
local mt = {}
function mt:__index(k)
return skeleton[k]
return configs[k]
end
return setmetatable(M, mt)

View File

@ -1,4 +1,4 @@
local skeleton = require 'nvim_lsp/skeleton'
local configs = require 'nvim_lsp/configs'
local util = require 'nvim_lsp/util'
local lsp = vim.lsp
@ -11,7 +11,7 @@ local installer = util.npm_installer {
binaries = {bin_name};
}
skeleton[server_name] = {
configs[server_name] = {
default_config = {
cmd = {"bash-language-server", "start"};
filetypes = {"sh"};
@ -43,6 +43,6 @@ Language server for bash, written using tree sitter in typescript.
};
};
skeleton[server_name].install = installer.install
skeleton[server_name].install_info = installer.info
configs[server_name].install = installer.install
configs[server_name].install_info = installer.info
-- vim:et ts=2 sw=2

View File

@ -1,8 +1,8 @@
local skeleton = require 'nvim_lsp/skeleton'
local configs = require 'nvim_lsp/configs'
local util = require 'nvim_lsp/util'
local lsp = vim.lsp
skeleton.ccls = {
configs.ccls = {
default_config = util.utf8_config {
cmd = {"ccls"};
filetypes = {"c", "cpp", "objc", "objcpp"};

View File

@ -1,8 +1,8 @@
local skeleton = require 'nvim_lsp/skeleton'
local configs = require 'nvim_lsp/configs'
local util = require 'nvim_lsp/util'
local lsp = vim.lsp
skeleton.clangd = {
configs.clangd = {
default_config = util.utf8_config {
cmd = {"clangd", "--background-index"};
filetypes = {"c", "cpp", "objc", "objcpp"};

View File

@ -2,19 +2,19 @@ local util = require 'nvim_lsp/util'
local api, validate, lsp = vim.api, vim.validate, vim.lsp
local tbl_extend = vim.tbl_extend
local skeleton = {}
local configs = {}
function skeleton.__newindex(t, template_name, template)
function configs.__newindex(t, config_name, config_definition)
validate {
name = {template_name, 's'};
default_config = {template.default_config, 't'};
on_new_config = {template.on_new_config, 'f', true};
on_attach = {template.on_attach, 'f', true};
commands = {template.commands, 't', true};
name = {config_name, 's'};
default_config = {config_definition.default_config, 't'};
on_new_config = {config_definition.on_new_config, 'f', true};
on_attach = {config_definition.on_attach, 'f', true};
commands = {config_definition.commands, 't', true};
}
if template.commands then
for k, v in pairs(template.commands) do
if config_definition.commands then
for k, v in pairs(config_definition.commands) do
validate {
['command.name'] = {k, 's'};
['command.fn'] = {v[1], 'f'};
@ -24,7 +24,7 @@ function skeleton.__newindex(t, template_name, template)
local M = {}
local default_config = tbl_extend("keep", template.default_config, {
local default_config = tbl_extend("keep", config_definition.default_config, {
log_level = lsp.protocol.MessageType.Warning;
settings = {};
init_options = {};
@ -32,7 +32,7 @@ function skeleton.__newindex(t, template_name, template)
})
-- Force this part.
default_config.name = template_name
default_config.name = config_name
-- The config here is the one which will be instantiated for the new server,
-- which is why this is a function, so that it can refer to the settings
@ -110,8 +110,8 @@ function skeleton.__newindex(t, template_name, template)
})
add_callbacks(new_config)
if template.on_new_config then
pcall(template.on_new_config, new_config)
if config_definition.on_new_config then
pcall(config_definition.on_new_config, new_config)
end
if config.on_new_config then
pcall(config.on_new_config, new_config)
@ -141,7 +141,7 @@ function skeleton.__newindex(t, template_name, template)
api.nvim_command(string.format(
"autocmd BufEnter <buffer=%d> ++once lua require'nvim_lsp'[%q]._setup_buffer(%d)"
, bufnr
, template_name
, config_name
, client.id
))
end
@ -166,20 +166,20 @@ function skeleton.__newindex(t, template_name, template)
if client.config._on_attach then
client.config._on_attach(client)
end
if template.commands then
if config_definition.commands then
-- Create the module commands
util.create_module_commands(template_name, M.commands)
util.create_module_commands(config_name, M.commands)
end
end
M.commands = template.commands
M.name = template_name
M.template_config = template
M.commands = config_definition.commands
M.name = config_name
M.document_config = config_definition
rawset(t, template_name, M)
rawset(t, config_name, M)
return M
end
return setmetatable({}, skeleton)
return setmetatable({}, configs)
-- vim:et ts=2 sw=2

View File

@ -1,4 +1,4 @@
local skeleton = require 'nvim_lsp/skeleton'
local configs = require 'nvim_lsp/configs'
local util = require 'nvim_lsp/util'
local lsp = vim.lsp
@ -13,7 +13,7 @@ local installer = util.npm_installer {
local root_pattern = util.root_pattern("package.json")
skeleton[server_name] = {
configs[server_name] = {
default_config = util.utf8_config {
cmd = {bin_name, "--stdio"};
filetypes = {"css", "scss", "less"};
@ -55,6 +55,6 @@ npm install -g vscode-css-languageserver-bin
};
}
skeleton[server_name].install = installer.install
skeleton[server_name].install_info = installer.info
configs[server_name].install = installer.install
configs[server_name].install_info = installer.info
-- vim:et ts=2 sw=2

View File

@ -1,4 +1,4 @@
local skeleton = require 'nvim_lsp/skeleton'
local configs = require 'nvim_lsp/configs'
local util = require 'nvim_lsp/util'
local lsp = vim.lsp
@ -11,7 +11,7 @@ local installer = util.npm_installer {
binaries = {bin_name};
}
skeleton[server_name] = {
configs[server_name] = {
default_config = {
cmd = {bin_name, "--stdio"};
filetypes = {"Dockerfile", "dockerfile"};
@ -45,6 +45,6 @@ npm install -g dockerfile-language-server-nodejs
};
};
skeleton[server_name].install = installer.install
skeleton[server_name].install_info = installer.info
configs[server_name].install = installer.install
configs[server_name].install_info = installer.info
-- vim:et ts=2 sw=2

View File

@ -1,4 +1,4 @@
local skeleton = require 'nvim_lsp/skeleton'
local configs = require 'nvim_lsp/configs'
local util = require 'nvim_lsp/util'
local lsp = vim.lsp
local api = vim.api
@ -16,7 +16,7 @@ local default_capabilities = lsp.protocol.make_client_capabilities()
default_capabilities.offsetEncoding = {"utf-8", "utf-16"}
local elm_root_pattern = util.root_pattern("elm.json")
skeleton[server_name] = {
configs[server_name] = {
default_config = util.utf8_config {
cmd = {bin_name};
-- TODO(ashkan) if we comment this out, it will allow elmls to operate on elm.json. It seems like it could do that, but no other editor allows it right now.
@ -70,7 +70,7 @@ npm install -g elm elm-test elm-format @elm-tooling/elm-language-server
};
}
skeleton[server_name].install = installer.install
skeleton[server_name].install_info = installer.info
configs[server_name].install = installer.install
configs[server_name].install_info = installer.info
-- vim:et ts=2 sw=2

View File

@ -1,8 +1,8 @@
local skeleton = require 'nvim_lsp/skeleton'
local configs = require 'nvim_lsp/configs'
local util = require 'nvim_lsp/util'
local lsp = vim.lsp
skeleton.flow = {
configs.flow = {
default_config = {
cmd = {"npm", "run", "flow","lsp"};
filetypes = {"javascript", "javascriptreact", "javascript.jsx"};

View File

@ -1,8 +1,8 @@
local skeleton = require 'nvim_lsp/skeleton'
local configs = require 'nvim_lsp/configs'
local util = require 'nvim_lsp/util'
local lsp = vim.lsp
skeleton.fortls = {
configs.fortls = {
default_config = {
cmd = {"fortls"};
filetypes = {"fortran"};

View File

@ -1,8 +1,8 @@
local skeleton = require 'nvim_lsp/skeleton'
local configs = require 'nvim_lsp/configs'
local util = require 'nvim_lsp/util'
local lsp = vim.lsp
skeleton.ghcide = {
configs.ghcide = {
default_config = {
cmd = { "ghcide", "--lsp" };
filetypes = { "haskell", "lhaskell" };

View File

@ -1,8 +1,8 @@
local skeleton = require 'nvim_lsp/skeleton'
local configs = require 'nvim_lsp/configs'
local util = require 'nvim_lsp/util'
local lsp = vim.lsp
skeleton.gopls = {
configs.gopls = {
default_config = {
cmd = {"gopls"};
filetypes = {"go"};

View File

@ -1,8 +1,8 @@
local skeleton = require 'nvim_lsp/skeleton'
local configs = require 'nvim_lsp/configs'
local util = require 'nvim_lsp/util'
local lsp = vim.lsp
skeleton.hie = {
configs.hie = {
default_config = {
cmd = {"hie-wrapper"};
filetypes = {"haskell"};

View File

@ -1,4 +1,4 @@
local skeleton = require 'nvim_lsp/skeleton'
local configs = require 'nvim_lsp/configs'
local util = require 'nvim_lsp/util'
local lsp = vim.lsp
@ -11,7 +11,7 @@ local installer = util.npm_installer {
binaries = {bin_name};
}
skeleton[server_name] = {
configs[server_name] = {
default_config = util.utf8_config {
cmd = {bin_name, "--stdio"};
filetypes = {"php"};
@ -67,6 +67,6 @@ npm install -g intelephense
};
}
skeleton[server_name].install = installer.install
skeleton[server_name].install_info = installer.info
configs[server_name].install = installer.install
configs[server_name].install_info = installer.info
-- vim:et ts=2 sw=2

View File

@ -1,8 +1,8 @@
local skeleton = require 'nvim_lsp/skeleton'
local configs = require 'nvim_lsp/configs'
local util = require 'nvim_lsp/util'
local lsp = vim.lsp
skeleton.leanls = {
configs.leanls = {
default_config = {
cmd = {"lean-language-server", "--stdio"};
filetypes = {"lean"};

View File

@ -1,4 +1,4 @@
local skeleton = require 'nvim_lsp/skeleton'
local configs = require 'nvim_lsp/configs'
local util = require 'nvim_lsp/util'
local lsp = vim.lsp
@ -11,7 +11,7 @@ local installer = util.npm_installer {
binaries = { bin_name };
}
skeleton[server_name] = {
configs[server_name] = {
default_config = {
cmd = { bin_name, "--stdio" };
filetypes = { "ocaml", "reason" };
@ -43,6 +43,6 @@ npm install -g ocaml-langauge-server
};
};
};
skeleton[server_name].install = installer.install
skeleton[server_name].install_info = installer.info
configs[server_name].install = installer.install
configs[server_name].install_info = installer.info
-- vim:et ts=2 sw=2

View File

@ -1,7 +1,7 @@
local skeleton = require 'nvim_lsp/skeleton'
local configs = require 'nvim_lsp/configs'
local lsp = vim.lsp
skeleton.pyls = {
configs.pyls = {
default_config = {
cmd = {"pyls"};
filetypes = {"python"};

View File

@ -1,4 +1,4 @@
local skeleton = require 'nvim_lsp/skeleton'
local configs = require 'nvim_lsp/configs'
local util = require 'nvim_lsp/util'
local lsp = vim.lsp
@ -76,7 +76,7 @@ end
local installer = make_installer()
skeleton[name] = {
configs[name] = {
default_config = {
filetypes = {"python"};
@ -133,5 +133,5 @@ This server accepts configuration via the `settings` key.
};
};
skeleton[name].install = installer.install
skeleton[name].install_info = installer.info
configs[name].install = installer.install
configs[name].install_info = installer.info

View File

@ -1,8 +1,8 @@
local skeleton = require 'nvim_lsp/skeleton'
local configs = require 'nvim_lsp/configs'
local util = require 'nvim_lsp/util'
local lsp = vim.lsp
skeleton.rls = {
configs.rls = {
default_config = {
cmd = {"rls"};
filetypes = {"rust"};

View File

@ -1,8 +1,8 @@
local skeleton = require 'nvim_lsp/skeleton'
local configs = require 'nvim_lsp/configs'
local util = require 'nvim_lsp/util'
local lsp = vim.lsp
skeleton.rust_analyzer = {
configs.rust_analyzer = {
default_config = util.utf8_config {
cmd = {"ra_lsp_server"};
filetypes = {"rust"};

View File

@ -1,8 +1,8 @@
local skeleton = require 'nvim_lsp/skeleton'
local configs = require 'nvim_lsp/configs'
local util = require 'nvim_lsp/util'
local lsp = vim.lsp
skeleton.solargraph = {
configs.solargraph = {
default_config = {
cmd = {"solargraph", "stdio"};
filetypes = {"ruby"};

View File

@ -1,4 +1,4 @@
local skeleton = require 'nvim_lsp/skeleton'
local configs = require 'nvim_lsp/configs'
local util = require 'nvim_lsp/util'
local vim = vim
@ -92,7 +92,7 @@ end
local installer = make_installer()
skeleton[name] = {
configs[name] = {
default_config = {
filetypes = {'lua'};
root_dir = function(fname)
@ -120,6 +120,6 @@ guide](https://github.com/sumneko/lua-language-server/wiki/Build-and-Run).
};
}
skeleton[name].install = installer.install
skeleton[name].install_info = installer.info
configs[name].install = installer.install
configs[name].install_info = installer.info
-- vim:et ts=2

View File

@ -1,8 +1,8 @@
local skeleton = require 'nvim_lsp/skeleton'
local configs = require 'nvim_lsp/configs'
local util = require 'nvim_lsp/util'
local lsp = vim.lsp
skeleton.terraformls = {
configs.terraformls = {
default_config = {
cmd = {"terraform-lsp"};
filetypes = {"terraform"};

View File

@ -1,4 +1,4 @@
local skeleton = require 'nvim_lsp/skeleton'
local configs = require 'nvim_lsp/configs'
local util = require 'nvim_lsp/util'
local lsp = vim.lsp
@ -31,7 +31,7 @@ end
-- end)
-- end
skeleton.texlab = {
configs.texlab = {
default_config = {
cmd = {"texlab"};
filetypes = {"tex", "bib"};
@ -86,5 +86,5 @@ See https://texlab.netlify.com/docs/reference/configuration for configuration op
};
}
skeleton.texlab.buf_build = buf_build
configs.texlab.buf_build = buf_build
-- vim:et ts=2 sw=2

View File

@ -1,4 +1,4 @@
local skeleton = require 'nvim_lsp/skeleton'
local configs = require 'nvim_lsp/configs'
local util = require 'nvim_lsp/util'
local lsp = vim.lsp
@ -11,7 +11,7 @@ local installer = util.npm_installer {
binaries = {bin_name};
}
skeleton[server_name] = {
configs[server_name] = {
default_config = util.utf8_config {
cmd = {bin_name, "--stdio"};
filetypes = {"javascript", "javascriptreact", "javascript.jsx", "typescript", "typescriptreact", "typescript.tsx"};
@ -47,6 +47,6 @@ npm install -g typescript-language-server
};
}
skeleton[server_name].install = installer.install
skeleton[server_name].install_info = installer.info
configs[server_name].install = installer.install
configs[server_name].install_info = installer.info
-- vim:et ts=2 sw=2

View File

@ -1,4 +1,4 @@
local skeleton = require "nvim_lsp/skeleton"
local configs = require "nvim_lsp/configs"
local util = require "nvim_lsp/util"
local lsp = vim.lsp
@ -11,7 +11,7 @@ local installer = util.npm_installer {
binaries = {bin_name}
}
skeleton[server_name] = {
configs[server_name] = {
default_config = {
cmd = {bin_name, "--stdio"},
filetypes = {"vim"},
@ -57,7 +57,7 @@ npm install -g vim-language-server
}
}
skeleton[server_name].install = installer.install
skeleton[server_name].install_info = installer.info
configs[server_name].install = installer.install
configs[server_name].install_info = installer.info
-- vim:et ts=2 sw=2

View File

@ -1,4 +1,4 @@
local skeleton = require 'nvim_lsp/skeleton'
local configs = require 'nvim_lsp/configs'
local util = require 'nvim_lsp/util'
local lsp = vim.lsp
@ -11,7 +11,7 @@ local installer = util.npm_installer {
binaries = {bin_name};
}
skeleton[server_name] = {
configs[server_name] = {
default_config = util.utf8_config {
cmd = {bin_name, "--stdio"};
filetypes = {"yaml"};
@ -45,6 +45,6 @@ npm install -g yaml-language-server
};
}
skeleton[server_name].install = installer.install
skeleton[server_name].install_info = installer.info
configs[server_name].install = installer.install
configs[server_name].install_info = installer.info
-- vim:et ts=2 sw=2

View File

@ -83,7 +83,7 @@ nvim_lsp.texlab.setup{
### Example: custom config
To configure a custom/private server, just require `nvim_lsp/skeleton` and do
To configure a custom/private server, just require `nvim_lsp/configs` and do
the same as we do if we were adding it to the repository itself.
1. Define the config: `configs.foo_lsp = { … }`
@ -91,7 +91,7 @@ the same as we do if we were adding it to the repository itself.
```lua
local nvim_lsp = require'nvim_lsp'
local configs = require'nvim_lsp/skeleton'
local configs = require'nvim_lsp/configs'
-- Check if it's already defined for when I reload this file.
if not nvim_lsp.foo_lsp then
configs.foo_lsp = {

View File

@ -1,5 +1,5 @@
require 'nvim_lsp'
local skeleton = require 'nvim_lsp/skeleton'
local configs = require 'nvim_lsp/configs'
local util = require 'nvim_lsp/util'
local inspect = vim.inspect
local uv = vim.loop
@ -75,7 +75,7 @@ require'nvim_lsp'.{{template_name}}.setup{}
]]
local function make_lsp_sections()
return make_section(0, '\n', sorted_map_table(skeleton, function(template_name, template_object)
return make_section(0, '\n', sorted_map_table(configs, function(template_name, template_object)
local template_def = template_object.template_config
local docs = template_def.docs
@ -222,7 +222,7 @@ local function make_lsp_sections()
end
local function make_implemented_servers_list()
return make_section(0, '\n', sorted_map_table(skeleton, function(k)
return make_section(0, '\n', sorted_map_table(configs, function(k)
return template("- [{{server}}](#{{server}})", {server=k})
end))
end