plugins/nvim-lsp: internal rename (nvim-lsp -> lsp)

This commit is contained in:
Gaetan Lepage 2023-05-12 09:51:39 +02:00 committed by Gaétan Lepage
parent 079b0c30cd
commit 859ae3a843
17 changed files with 8 additions and 8 deletions

View file

@ -0,0 +1,359 @@
{
pkgs,
config,
lib,
...
} @ args:
with lib; let
lspHelpers = import ../helpers.nix args;
helpers = import ../../helpers.nix {inherit lib;};
optionWarnings = import ../../../lib/option-warnings.nix args;
basePluginPath = ["plugins" "lsp" "servers"];
servers = [
{
name = "astro";
description = "Enable astrols, for Astro";
package = pkgs.nodePackages."@astrojs/language-server";
cmd = cfg: ["${cfg.package}/bin/astro-ls" "--stdio"];
}
{
name = "bashls";
description = "Enable bashls, for bash.";
package = pkgs.nodePackages.bash-language-server;
}
{
name = "clangd";
description = "Enable clangd LSP, for C/C++.";
package = pkgs.clang-tools;
}
{
name = "cssls";
description = "Enable cssls, for CSS";
package = pkgs.nodePackages.vscode-langservers-extracted;
cmd = cfg: ["${cfg.package}/bin/vscode-css-language-server" "--stdio"];
}
{
name = "dartls";
description = "Enable dart language-server, for dart";
package = pkgs.dart;
settingsOptions = {
analysisExcludedFolders = mkOption {
type = types.nullOr (types.listOf types.str);
default = null;
description = ''
An array of paths (absolute or relative to each workspace folder) that should be
excluded from analysis.
'';
};
enableSdkFormatter = mkOption {
type = types.nullOr types.bool;
default = null;
description = ''
When set to false, prevents registration (or unregisters) the SDK formatter. When set
to true or not supplied, will register/reregister the SDK formatter
'';
};
lineLength = mkOption {
type = types.nullOr types.int;
default = null;
description = ''
The number of characters the formatter should wrap code at. If unspecified, code will
be wrapped at 80 characters.
'';
};
completeFunctionCalls = mkOption {
type = types.nullOr types.bool;
default = true;
description = ''
When set to true, completes functions/methods with their required parameters.
'';
};
showTodos = mkOption {
type = types.nullOr types.bool;
default = true;
description = ''
Whether to generate diagnostics for TODO comments. If unspecified, diagnostics will not
be generated.
'';
};
renameFilesWithClasses = mkOption {
type = types.nullOr (types.enum ["always" "prompt"]);
default = null;
description = ''
When set to "always", will include edits to rename files when classes are renamed if the
filename matches the class name (but in snake_form). When set to "prompt", a prompt will
be shown on each class rename asking to confirm the file rename. Otherwise, files will
not be renamed. Renames are performed using LSP's ResourceOperation edits - that means
the rename is simply included in the resulting WorkspaceEdit and must be handled by the
client.
'';
};
enableSnippets = mkOption {
type = types.nullOr types.bool;
default = null;
description = ''
Whether to include code snippets (such as class, stful, switch) in code completion. When
unspecified, snippets will be included.
'';
};
updateImportsOnRename = mkOption {
type = types.nullOr types.bool;
default = null;
description = ''
Whether to update imports and other directives when files are renamed. When unspecified,
imports will be updated if the client supports willRenameFiles requests
'';
};
documentation = mkOption {
type = types.nullOr (types.enum ["none" "summary" "full"]);
default = null;
description = ''
The typekind of dartdocs to include in Hovers, Code Completion, Signature Help and other
similar requests. If not set, defaults to full
'';
};
includeDependenciesInWorkspaceSymbols = mkOption {
type = types.nullOr types.bool;
default = null;
description = ''
Whether to include symbols from dependencies and Dart/Flutter SDKs in Workspace Symbol
results. If not set, defaults to true.
'';
};
};
settings = cfg: {dart = cfg;};
}
{
name = "denols";
description = "Enable denols, for Deno";
package = pkgs.deno;
}
{
name = "eslint";
description = "Enable eslint";
package = pkgs.nodePackages.vscode-langservers-extracted;
cmd = cfg: ["${cfg.package}/bin/vscode-eslint-language-server" "--stdio"];
}
{
name = "elixirls";
description = "Enable elixirls";
package = pkgs.elixir_ls;
cmd = cfg: ["${cfg.package}/bin/elixir-ls"];
}
{
name = "gdscript";
description = "Enable gdscript, for Godot";
package = null;
}
{
name = "gopls";
description = "Enable gopls, for Go.";
}
{
name = "hls";
description = "Enable haskell language server";
package = pkgs.haskell-language-server;
cmd = cfg: ["haskell-language-server-wrapper"];
}
{
name = "html";
description = "Enable html, for HTML";
package = pkgs.nodePackages.vscode-langservers-extracted;
cmd = cfg: ["${cfg.package}/bin/vscode-html-language-server" "--stdio"];
}
{
name = "jsonls";
description = "Enable jsonls, for JSON";
package = pkgs.nodePackages.vscode-langservers-extracted;
cmd = cfg: ["${cfg.package}/bin/vscode-json-language-server" "--stdio"];
}
{
name = "lua-ls";
description = "Enable lua LS, for lua";
# Use the old name of the lua LS if the user is on a stable branch of nixpkgs
# Rename occured here: https://github.com/NixOS/nixpkgs/pull/215057
package =
if (hasAttr "lua-language-server" pkgs)
then pkgs.lua-language-server
else pkgs.sumneko-lua-language-server;
serverName = "lua_ls";
# All available settings are documented here:
# https://github.com/LuaLS/lua-language-server/wiki/Settings
settingsOptions = {
runtime = {
version = mkOption {
type = types.nullOr types.str;
description = ''
Tell the language server which version of Lua you're using
(most likely LuaJIT in the case of Neovim)
'';
default = "LuaJIT";
};
};
diagnostics = {
globals = mkOption {
type = types.nullOr (types.listOf types.str);
description = ''
An array of variable names that will be declared as global.
'';
default = ["vim"];
};
};
workspace = {
library = mkOption {
type = types.nullOr (types.either types.str (helpers.rawType));
description = ''
An array of abosolute or workspace-relative paths that will be added to the workspace
diagnosis - meaning you will get completion and context from these library files.
Can be a file or directory.
Files included here will have some features disabled such as renaming fields to
prevent accidentally renaming your library files.
'';
default = helpers.mkRaw "vim.api.nvim_get_runtime_file('', true)";
};
checkThirdParty = mkOption {
type = types.nullOr types.bool;
description = ''
Whether third party libraries can be automatically detected and applied.
Third party libraries can set up the environment to be as close as possible to your
target runtime environment.
'';
# prevents an annoying warning
# https://github.com/LuaLS/lua-language-server/discussions/1688#discussioncomment-4185003
default = false;
};
};
telemetry = {
enable = mkEnableOption "telemetry";
};
};
settings = cfg: {Lua = cfg;};
}
{
name = "metals";
description = "Enable metals, for Scala";
}
{
name = "nil_ls";
description = "Enable nil, for Nix";
package = pkgs.nil;
settingsOptions = {
formatting.command = mkOption {
type = types.nullOr (types.listOf types.str);
default = null;
description = ''
External formatter command (with arguments).
It should accepts file content in stdin and print the formatted code into stdout.
'';
};
diagnostics = {
ignored = mkOption {
type = types.listOf types.str;
default = [];
description = ''
Ignored diagnostic kinds.
The kind identifier is a snake_cased_string usually shown together
with the diagnostic message.
'';
};
excludedFiles = mkOption {
type = types.listOf types.str;
default = [];
description = ''
Files to exclude from showing diagnostics. Useful for generated files.
It accepts an array of paths. Relative paths are joint to the workspace root.
Glob patterns are currently not supported.
'';
};
};
};
settings = cfg: {nil = {inherit (cfg) formatting diagnostics;};};
}
{
name = "pylsp";
description = "Enable pylsp, for Python.";
package = pkgs.python3Packages.python-lsp-server;
settings = cfg: {pylsp = cfg;};
}
{
name = "pyright";
description = "Enable pyright, for Python.";
}
{
name = "rnix-lsp";
description = "Enable rnix LSP, for Nix";
serverName = "rnix";
}
{
name = "ruff-lsp";
description = "Enable ruff-lsp, for Python.";
package = pkgs.python3Packages.ruff-lsp;
serverName = "ruff_lsp";
}
{
name = "rust-analyzer";
description = "Enable rust-analyzer, for Rust.";
serverName = "rust_analyzer";
settingsOptions = import ./rust-analyzer-config.nix lib;
settings = cfg: {rust-analyzer = cfg;};
}
{
name = "sourcekit";
description = "Enable the sourcekit language server, for Swift and C/C++/Objective-C";
package = pkgs.sourcekit-lsp;
}
{
name = "tailwindcss";
description = "Enable tailwindcss language server, for tailwindcss";
package = pkgs.nodePackages."@tailwindcss/language-server";
}
{
name = "terraformls";
description = "Enable terraform-ls, for terraform";
package = pkgs.terraform-ls;
}
{
name = "texlab";
description = "Enable texlab language server, for LaTeX";
}
{
name = "tsserver";
description = "Enable tsserver for typescript";
package = pkgs.nodePackages.typescript-language-server;
}
{
name = "typst-lsp";
serverName = "typst_lsp";
description = "Enable typst-lsp for typst";
package = pkgs.typst-lsp;
}
{
name = "vuels";
description = "Enable vuels, for Vue";
package = pkgs.nodePackages.vls;
}
{
name = "yamlls";
description = "Enable yamlls, for yaml";
package = pkgs.yaml-language-server;
}
{
name = "zls";
description = "Enable zls, for Zig.";
}
];
in {
imports =
lib.lists.map (lspHelpers.mkLsp) servers
++ [./pylsp.nix]
++ [
(optionWarnings.mkRenamedOption {
option = basePluginPath ++ ["sumneko-lua"];
newOption = basePluginPath ++ ["lua-ls"];
})
];
}

View file

@ -0,0 +1,447 @@
{
pkgs,
lib,
config,
...
}:
with lib; let
helpers = import ../../helpers.nix {inherit lib;};
cfg = config.plugins.lsp.servers.pylsp;
in {
# All settings are documented here:
# https://github.com/python-lsp/python-lsp-server/blob/develop/CONFIGURATION.md
options.plugins.lsp.servers.pylsp.settings = {
configurationSources = mkOption {
type = lib.types.nullOr (types.enum ["pycodestyle" "flake8"]);
description = "List of configuration sources to use.";
default = null;
apply = (
value:
if (value != null)
then [value]
else null
);
};
plugins = helpers.mkCompositeOption "pylsp plugins" {
autopep8 = helpers.mkCompositeOption "autopep8 settings" {
enabled = helpers.defaultNullOpts.mkBool true ''
Enable or disable the plugin.
Setting this explicitely to `true` will install the dependency for this plugin (autopep8).
'';
};
flake8 = helpers.mkCompositeOption "flake8 settings" {
config = helpers.mkNullOrOption types.str ''
Path to the config file that will be the authoritative config source.
'';
enabled = helpers.defaultNullOpts.mkBool false ''
Enable or disable the plugin.
Setting this explicitely to `true` will install the dependency for this plugin (flake8).
'';
exclude = helpers.defaultNullOpts.mkNullable (types.listOf types.str) "[]" ''
List of files or directories to exclude.
'';
executable = helpers.mkNullOrOption types.str ''
Path to the flake8 executable.
'';
filename = helpers.mkNullOrOption types.str ''
Only check for filenames matching the patterns in this list.
'';
hangClosing = helpers.mkNullOrOption types.bool ''
Hang closing bracket instead of matching indentation of opening bracket's line.
'';
ignore = helpers.defaultNullOpts.mkNullable (types.listOf types.str) "[]" ''
List of errors and warnings to ignore (or skip).
'';
maxComplexity = helpers.mkNullOrOption types.int ''
Maximum allowed complexity threshold.
'';
maxLineLength = helpers.mkNullOrOption types.int ''
Maximum allowed line length for the entirety of this run.
'';
indentSize = helpers.mkNullOrOption types.int ''
Set indentation spaces.
'';
perFileIgnores = helpers.defaultNullOpts.mkNullable (types.listOf types.str) "[]" ''
A pairing of filenames and violation codes that defines which violations to ignore in a
particular file.
For example: `["file_path.py:W305,W304"]`.
'';
select = helpers.mkNullOrOption (types.listOf types.str) ''
List of errors and warnings to enable.
'';
};
jedi = helpers.mkCompositeOption "jedi settings" {
auto_import_modules =
helpers.defaultNullOpts.mkNullable
(types.listOf types.str)
"[ \"numpy\" ]"
"List of module names for `jedi.settings.auto_import_modules`.";
extra_paths = helpers.defaultNullOpts.mkNullable (types.listOf types.str) "[]" ''
Define extra paths for jedi.Script.
'';
environment = helpers.mkNullOrOption types.str ''
Define environment for jedi.Script and Jedi.names.
'';
};
jedi_completion = helpers.mkCompositeOption "jedi_completion settings" {
enabled = helpers.defaultNullOpts.mkBool true "Enable or disable the plugin.";
include_params = helpers.defaultNullOpts.mkBool true ''
Auto-completes methods and classes with tabstops for each parameter.
'';
include_class_objects = helpers.defaultNullOpts.mkBool false ''
Adds class objects as a separate completion item.
'';
include_function_objects = helpers.defaultNullOpts.mkBool false ''
Adds function objects as a separate completion item.
'';
fuzzy = helpers.defaultNullOpts.mkBool false ''
Enable fuzzy when requesting autocomplete.
'';
eager = helpers.defaultNullOpts.mkBool false ''
Resolve documentation and detail eagerly.
'';
resolve_at_most = helpers.defaultNullOpts.mkInt 25 ''
How many labels and snippets (at most) should be resolved.
'';
cache_for =
helpers.defaultNullOpts.mkNullable
(types.listOf types.str)
"[ \"pandas\" \"numpy\" \"tensorflow\" \"matplotlib\" ]"
"Modules for which labels and snippets should be cached.";
};
jedi_definition = helpers.mkCompositeOption "jedi_definition settings" {
enabled = helpers.defaultNullOpts.mkBool true "Enable or disable the plugin.";
follow_imports = helpers.defaultNullOpts.mkBool true ''
The goto call will follow imports.
'';
follow_builtin_imports = helpers.defaultNullOpts.mkBool true ''
If follow_imports is true will decide if it follow builtin imports.
'';
follow_builtin_definitions = helpers.defaultNullOpts.mkBool true ''
Follow builtin and extension definitions to stubs.
'';
};
jedi_hover = helpers.mkCompositeOption "jedi_hover settings" {
enabled = helpers.defaultNullOpts.mkBool true "Enable or disable the plugin.";
};
jedi_references = helpers.mkCompositeOption "jedi_references settings" {
enabled = helpers.defaultNullOpts.mkBool true "Enable or disable the plugin.";
};
jedi_signature_help = helpers.mkCompositeOption "jedi_signature_help settings" {
enabled = helpers.defaultNullOpts.mkBool true "Enable or disable the plugin.";
};
jedi_symbols = helpers.mkCompositeOption "jedi_symbols settings" {
enabled = helpers.defaultNullOpts.mkBool true "Enable or disable the plugin.";
all_scopes = helpers.defaultNullOpts.mkBool true ''
If true lists the names of all scopes instead of only the module namespace.
'';
include_import_symbols = helpers.defaultNullOpts.mkBool true ''
If true includes symbols imported from other libraries.
'';
};
mccabe = helpers.mkCompositeOption "mccabe settings" {
enabled = helpers.defaultNullOpts.mkBool true ''
Enable or disable the plugin.
Setting this explicitely to `true` will install the dependency for this plugin (mccabe).
'';
threshold = helpers.defaultNullOpts.mkInt 15 ''
The minimum threshold that triggers warnings about cyclomatic complexity.
'';
};
preload = helpers.mkCompositeOption "preload settings" {
enabled = helpers.defaultNullOpts.mkBool true "Enable or disable the plugin.";
modules = helpers.defaultNullOpts.mkNullable (types.listOf types.str) "[]" ''
List of modules to import on startup.
'';
};
pycodestyle = helpers.mkCompositeOption "pycodestyle settings" {
enabled = helpers.defaultNullOpts.mkBool true ''
Enable or disable the plugin.
Setting this explicitely to `true` will install the dependency for this plugin
(pycodestyle).
'';
exclude = helpers.defaultNullOpts.mkNullable (types.listOf types.str) "[]" ''
Exclude files or directories which match these patterns.
'';
filename = helpers.defaultNullOpts.mkNullable (types.listOf types.str) "[]" ''
When parsing directories, only check filenames matching these patterns.
'';
ropeFolder = helpers.mkNullOrOption (types.listOf types.str) ''
Select errors and warnings.
'';
ignore = helpers.defaultNullOpts.mkNullable (types.listOf types.str) "[]" ''
Ignore errors and warnings.
'';
hangClosing = helpers.mkNullOrOption types.bool ''
Hang closing bracket instead of matching indentation of opening bracket's line.
'';
maxLineLength = helpers.mkNullOrOption types.int ''
Set maximum allowed line length.
'';
indentSize = helpers.mkNullOrOption types.int ''
Set indentation spaces.
'';
};
pydocstyle = helpers.mkCompositeOption "pydocstyle settings" {
enabled = helpers.defaultNullOpts.mkBool false ''
Enable or disable the plugin.
Setting this explicitely to `true` will install the dependency for this plugin
(pydocstyle).
'';
convention =
helpers.mkNullOrOption
(types.enum [
"pep257"
"numpy"
"google"
"None"
])
"Choose the basic list of checked errors by specifying an existing convention.";
addIgnore = helpers.defaultNullOpts.mkNullable (types.listOf types.str) "[]" ''
Ignore errors and warnings in addition to the specified convention.
'';
addSelect = helpers.defaultNullOpts.mkNullable (types.listOf types.str) "[]" ''
Select errors and warnings in addition to the specified convention.
'';
ignore = helpers.defaultNullOpts.mkNullable (types.listOf types.str) "[]" ''
Ignore errors and warnings.
'';
select = helpers.mkNullOrOption (types.listOf types.str) ''
Select errors and warnings.
'';
match = helpers.defaultNullOpts.mkStr "(?!test_).*\\.py" ''
Check only files that exactly match the given regular expression;
default is to match files that don't start with 'test_' but end with '.py'.
'';
matchDir = helpers.defaultNullOpts.mkStr "[^\\.].*" ''
Search only dirs that exactly match the given regular expression;
default is to match dirs which do not begin with a dot.
'';
};
pyflakes = helpers.mkCompositeOption "pyflakes settings" {
enabled = helpers.defaultNullOpts.mkBool true ''
Enable or disable the plugin.
Setting this explicitely to `true` will install the dependency for this plugin (pyflakes).
'';
};
pylint = helpers.mkCompositeOption "pylint settings" {
enabled = helpers.defaultNullOpts.mkBool false ''
Enable or disable the plugin.
Setting this explicitely to `true` will install the dependency for this plugin (pylint).
'';
args = helpers.defaultNullOpts.mkNullable (types.listOf types.str) "[]" ''
Arguments to pass to pylint.
'';
executable = helpers.mkNullOrOption types.str ''
Executable to run pylint with.
Enabling this will run pylint on unsaved files via stdin.
Can slow down workflow. Only works with python3.
'';
};
rope_autoimport = helpers.mkCompositeOption "rope_autoimport settings" {
enabled = helpers.defaultNullOpts.mkBool false ''
Enable or disable the plugin.
Setting this explicitely to `true` will install the dependency for this plugin (rope).
'';
memory = helpers.defaultNullOpts.mkBool false ''
Make the autoimport database memory only.
Drastically increases startup time.
'';
};
rope_completion = helpers.mkCompositeOption "rope_completion settings" {
enabled = helpers.defaultNullOpts.mkBool false ''
Enable or disable the plugin.
Setting this explicitely to `true` will install the dependency for this plugin (rope).
'';
eager = helpers.defaultNullOpts.mkBool false ''
Resolve documentation and detail eagerly.
'';
};
yapf = helpers.mkCompositeOption "yapf settings" {
enabled = helpers.defaultNullOpts.mkBool true ''
Enable or disable the plugin.
Setting this explicitely to `true` will install the dependency for this plugin (yapf).
'';
};
### THIRD-PARTY PLUGINS
pylsp_mypy = helpers.mkCompositeOption "pylsp_mypy settings" {
enabled = helpers.defaultNullOpts.mkBool false ''
Enable or disable the plugin.
Setting this explicitely to `true` will install the dependency for this plugin
(pylsp-mypy).
'';
live_mode = helpers.defaultNullOpts.mkBool true ''
Provides type checking as you type.
This writes to a tempfile every time a check is done.
Turning off live_mode means you must save your changes for mypy diagnostics to update
correctly.
'';
dmypy = helpers.defaultNullOpts.mkBool false ''
Executes via dmypy run rather than mypy.
This uses the dmypy daemon and may dramatically improve the responsiveness of the pylsp
server, however this currently does not work in live_mode.
Enabling this disables live_mode, even for conflicting configs.
'';
strict = helpers.defaultNullOpts.mkBool false ''
Refers to the strict option of mypy.
This option often is too strict to be useful.
'';
overrides =
helpers.defaultNullOpts.mkNullable
(with types; listOf (either bool str))
"[true]"
''
Specifies a list of alternate or supplemental command-line options.
This modifies the options passed to mypy or the mypy-specific ones passed to dmypy run.
When present, the special boolean member true is replaced with the command-line options that
would've been passed had overrides not been specified.
Later options take precedence, which allows for replacing or negating individual default
options (see mypy.main:process_options and mypy --help | grep inverse).
'';
dmypy_status_file = helpers.defaultNullOpts.mkStr ".dmypy.json" ''
Specifies which status file dmypy should use.
This modifies the --status-file option passed to dmypy given dmypy is active.
'';
config_sub_paths = helpers.defaultNullOpts.mkNullable (types.listOf types.str) "[]" ''
Specifies sub paths under which the mypy configuration file may be found.
For each directory searched for the mypy config file, this also searches the sub paths
specified here.
'';
report_progress = helpers.defaultNullOpts.mkBool false ''
Report basic progress to the LSP client.
With this option, pylsp-mypy will report when mypy is running, given your editor supports
LSP progress reporting.
For small files this might produce annoying flashing in your editor, especially in with
live_mode.
For large projects, enabling this can be helpful to assure yourself whether mypy is still
running.
'';
};
### END OF THIRD-PARTY PLUGINS
};
rope = helpers.mkCompositeOption "rope settings" {
extensionModules = helpers.mkNullOrOption types.str ''
Builtin and c-extension modules that are allowed to be imported and inspected by rope.
'';
ropeFolder = helpers.mkNullOrOption (types.listOf types.str) ''
The name of the folder in which rope stores project configurations and data.
Pass null for not using such a folder at all.
'';
};
};
config =
mkIf cfg.enable
{
extraPackages = with cfg.settings; let
isNotNullAndEnabled = x: (!isNull x) && x.enabled;
in
optionals (!isNull cfg.settings.plugins) (
lists.flatten (map
(
pluginName: (
optionals (isNotNullAndEnabled plugins.${pluginName})
cfg.package.optional-dependencies.${pluginName}
)
)
[
"autopep8"
"flake8"
"mccabe"
"pycodestyle"
"pydocstyle"
"pyflakes"
"pylint"
"yapf"
])
++ (
optionals
(
(isNotNullAndEnabled plugins.rope_autoimport)
|| (isNotNullAndEnabled plugins.rope_completion)
)
cfg.package.optional-dependencies.rope
)
++ (
optional (isNotNullAndEnabled plugins.pylsp_mypy)
pkgs.python3Packages.pylsp-mypy
)
);
};
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,13 @@
# Updating rust-analyzer options
Because there a large number of rust-analyzer options it's difficult to handle them by hand.
The options can be fetched from the [rust-analyzer package.json](https://github.com/rust-lang/rust-analyzer/blob/master/editors/code/package.json).
There is a derivation on the top-level flake that allows to build it easily, you just have to run:
```bash
nix build .#rustAnalyzerOptions
```
You can then copy the `result/share/rust-analyzer-config.nix` to the correct location.