2021-09-30 19:31:57 +00:00
|
|
|
{ config, pkgs, lib, ... }:
|
|
|
|
|
2021-11-09 20:59:22 +00:00
|
|
|
with lib;
|
2021-09-30 19:31:57 +00:00
|
|
|
let
|
2021-11-09 20:59:22 +00:00
|
|
|
lspConfig =
|
|
|
|
{
|
2024-04-06 21:56:46 +00:00
|
|
|
language_ids = {
|
|
|
|
c = "c_cpp";
|
|
|
|
cpp = "c_cpp";
|
|
|
|
javascript = "javascriptreact";
|
|
|
|
typescript = "typescriptreact";
|
|
|
|
protobuf = "proto";
|
|
|
|
sh = "shellscript";
|
|
|
|
};
|
|
|
|
|
|
|
|
language_servers = {
|
|
|
|
ccls = {
|
2021-11-09 20:59:22 +00:00
|
|
|
args = [ "-v=2" "-log-file=/tmp/ccls.log" ];
|
|
|
|
command = "ccls";
|
|
|
|
filetypes = [ "c" "cpp" ];
|
|
|
|
roots = [ "compile_commands.json" ".cquery" ".git" ];
|
|
|
|
};
|
2024-04-06 21:56:46 +00:00
|
|
|
gopls = {
|
2021-11-09 20:59:22 +00:00
|
|
|
command = "gopls";
|
|
|
|
filetypes = [ "go" ];
|
|
|
|
offset_encoding = "utf-8";
|
|
|
|
roots = [ "Gopkg.toml" "go.mod" ".git" ".hg" ];
|
|
|
|
settings = { gopls = { hoverKind = "SynopsisDocumentation"; semanticTokens = true; }; };
|
|
|
|
settings_section = "gopls";
|
|
|
|
};
|
2024-04-06 21:56:46 +00:00
|
|
|
haskell-language-server = {
|
2021-11-09 20:59:22 +00:00
|
|
|
args = [ "--lsp" ];
|
|
|
|
command = "haskell-language-server-wrapper";
|
|
|
|
filetypes = [ "haskell" ];
|
2021-12-15 19:44:15 +00:00
|
|
|
roots = [ "Setup.hs" "stack.yaml" "*.cabal" "package.yaml" ];
|
2022-06-02 20:12:04 +00:00
|
|
|
settings_section = "haskell";
|
2021-11-09 20:59:22 +00:00
|
|
|
};
|
2024-04-06 21:56:46 +00:00
|
|
|
nil = {
|
2023-12-10 00:58:58 +00:00
|
|
|
command = "${pkgs.nil}/bin/nil";
|
2021-11-09 20:59:22 +00:00
|
|
|
filetypes = [ "nix" ];
|
|
|
|
roots = [ "flake.nix" "shell.nix" ".git" ];
|
2023-12-26 18:53:26 +00:00
|
|
|
settings.nil = {
|
|
|
|
formatting.command = [ "${getExe pkgs.nixpkgs-fmt}" ];
|
|
|
|
};
|
2021-11-09 20:59:22 +00:00
|
|
|
};
|
2024-04-06 21:56:46 +00:00
|
|
|
pyls = {
|
2021-11-09 20:59:22 +00:00
|
|
|
command = "pyls";
|
|
|
|
filetypes = [ "python" ];
|
|
|
|
offset_encoding = "utf-8";
|
|
|
|
roots = [ "requirements.txt" "setup.py" ".git" ".hg" ];
|
|
|
|
};
|
|
|
|
};
|
2022-05-06 17:40:27 +00:00
|
|
|
semantic_tokens.faces = [
|
|
|
|
## Items
|
|
|
|
# (Rust) Macros
|
|
|
|
{ face = "attribute"; token = "attribute"; }
|
|
|
|
{ face = "attribute"; token = "derive"; }
|
|
|
|
{ face = "macro"; token = "macro"; } # Function-like Macro
|
|
|
|
# Keyword and Fixed Tokens
|
|
|
|
{ face = "keyword"; token = "keyword"; }
|
|
|
|
{ face = "operator"; token = "operator"; }
|
|
|
|
# Functions and Methods
|
|
|
|
{ face = "function"; token = "function"; }
|
|
|
|
{ face = "method"; token = "method"; }
|
|
|
|
# Constants
|
|
|
|
{ face = "string"; token = "string"; }
|
|
|
|
{ face = "format_specifier"; token = "formatSpecifier"; }
|
|
|
|
# Variables
|
2023-10-10 11:53:39 +00:00
|
|
|
{ face = "variable"; token = "variable"; modifiers = [ "readonly" ]; }
|
|
|
|
{ face = "mutable_variable"; token = "variable"; }
|
2022-05-06 17:40:27 +00:00
|
|
|
{ face = "module"; token = "namespace"; }
|
|
|
|
{ face = "variable"; token = "type_parameter"; }
|
|
|
|
{ face = "class"; token = "enum"; }
|
|
|
|
{ face = "class"; token = "struct"; }
|
|
|
|
{ face = "class"; token = "trait"; }
|
|
|
|
{ face = "class"; token = "union"; }
|
2023-04-11 09:50:17 +00:00
|
|
|
{ face = "class"; token = "class"; }
|
2022-05-06 17:40:27 +00:00
|
|
|
|
|
|
|
## Comments
|
|
|
|
{ face = "documentation"; token = "comment"; modifiers = [ "documentation" ]; }
|
|
|
|
{ face = "comment"; token = "comment"; }
|
|
|
|
];
|
2021-11-09 20:59:22 +00:00
|
|
|
server = { timeout = 1800; };
|
|
|
|
snippet_support = false;
|
|
|
|
verbosity = 255;
|
|
|
|
};
|
|
|
|
|
2024-04-06 21:56:46 +00:00
|
|
|
languageServerOption = types.submodule {
|
2021-11-09 20:59:22 +00:00
|
|
|
options = {
|
|
|
|
filetypes = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
description = "The list of filetypes to assign the language to";
|
|
|
|
};
|
|
|
|
roots = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
description = "The list of root filenames that are used to determine the project root";
|
|
|
|
};
|
|
|
|
command = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
description = "The LSP server command to be called.";
|
|
|
|
};
|
|
|
|
args = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [ ];
|
|
|
|
description = "The arguments passed onto the LSP server.";
|
|
|
|
};
|
|
|
|
offset_encoding = mkOption {
|
|
|
|
type = types.nullOr (types.enum [ "utf-8" ]);
|
|
|
|
default = null;
|
|
|
|
description = "The offset encoding used by the LSP server.";
|
|
|
|
};
|
|
|
|
settings_section = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
description = "The settings section to be sent to LSP server.";
|
|
|
|
};
|
|
|
|
settings = mkOption {
|
|
|
|
type = types.nullOr (types.attrsOf types.anything);
|
|
|
|
default = null;
|
|
|
|
description = "Additional settings to be passed to the LSP server.";
|
|
|
|
};
|
2024-07-10 20:20:00 +00:00
|
|
|
package = mkOption {
|
|
|
|
type = types.nullOr types.package;
|
|
|
|
default = null;
|
|
|
|
description = "The default package of the language server. Will be appended as the ending segments of the PATH to kak-lsp";
|
|
|
|
};
|
2021-11-09 20:59:22 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
cfg = config.programs.kak-lsp;
|
2024-07-10 20:20:00 +00:00
|
|
|
|
|
|
|
serverPackages =
|
|
|
|
filter (v: v != null)
|
|
|
|
(lib.mapAttrsToList (_: serv: serv.package) cfg.languageServers);
|
|
|
|
|
|
|
|
wrappedPackage = pkgs.symlinkJoin {
|
|
|
|
name = "kak-lsp-wrapped";
|
|
|
|
nativeBuildInputs = [ pkgs.makeWrapper ];
|
|
|
|
paths = [ cfg.package ];
|
|
|
|
postBuild = ''
|
|
|
|
wrapProgram $out/bin/kak-lsp --suffix PATH ":" ${lib.makeBinPath serverPackages}
|
|
|
|
'';
|
|
|
|
};
|
2021-09-30 19:31:57 +00:00
|
|
|
in
|
|
|
|
{
|
2021-11-09 20:59:22 +00:00
|
|
|
options.programs.kak-lsp = {
|
|
|
|
enable = mkEnableOption "Enable kak-lsp support";
|
|
|
|
|
|
|
|
package = mkOption {
|
2022-01-12 20:55:53 +00:00
|
|
|
type = types.package;
|
2022-01-30 18:49:25 +00:00
|
|
|
default = pkgs.kak-lsp;
|
2021-11-09 20:59:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enableSnippets = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = "Enable snippet support";
|
|
|
|
};
|
|
|
|
|
2022-05-06 17:40:27 +00:00
|
|
|
semanticTokens.faces = mkOption {
|
|
|
|
type = types.listOf types.anything;
|
|
|
|
default = lspConfig.semantic_tokens.faces;
|
|
|
|
description = "The semantic tokens faces mapping given to kak";
|
2021-11-09 20:59:22 +00:00
|
|
|
};
|
2023-07-03 20:42:03 +00:00
|
|
|
semanticTokens.additionalFaces = mkOption {
|
|
|
|
type = types.listOf types.anything;
|
|
|
|
default = [ ];
|
|
|
|
description = "The semantic tokens faces mapping given to kak";
|
|
|
|
};
|
2021-11-09 20:59:22 +00:00
|
|
|
|
|
|
|
serverTimeout = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 1000;
|
|
|
|
description = "Server timeout";
|
|
|
|
};
|
|
|
|
|
2024-04-06 21:56:46 +00:00
|
|
|
languageServers = mkOption {
|
|
|
|
type = types.attrsOf languageServerOption;
|
2022-02-25 19:45:06 +00:00
|
|
|
default = { };
|
2021-11-09 20:59:22 +00:00
|
|
|
description = "The language options";
|
|
|
|
};
|
2024-04-06 21:56:46 +00:00
|
|
|
|
|
|
|
languageIds = mkOption {
|
|
|
|
type = types.attrsOf types.str;
|
|
|
|
default = { };
|
|
|
|
description = "Language IDs to be sent to the LSP";
|
|
|
|
};
|
2021-11-09 20:59:22 +00:00
|
|
|
};
|
|
|
|
|
2024-06-11 17:43:48 +00:00
|
|
|
config = mkIf cfg.enable
|
|
|
|
{
|
2024-07-10 20:20:00 +00:00
|
|
|
home.packages = [ wrappedPackage ];
|
2021-09-30 19:31:57 +00:00
|
|
|
|
2024-06-11 17:43:48 +00:00
|
|
|
# Configurations
|
|
|
|
xdg.configFile."kak-lsp/kak-lsp.toml" =
|
|
|
|
let
|
|
|
|
toml = pkgs.formats.toml { };
|
2024-07-10 20:20:00 +00:00
|
|
|
toLspConfig = lib.filterAttrsRecursive (n: v: n != "package" && v != null);
|
2024-06-11 17:43:48 +00:00
|
|
|
in
|
2021-11-09 20:59:22 +00:00
|
|
|
{
|
2024-06-11 17:43:48 +00:00
|
|
|
source = toml.generate "config.toml"
|
|
|
|
{
|
2023-07-03 20:42:03 +00:00
|
|
|
semantic_tokens.faces = cfg.semanticTokens.faces ++ cfg.semanticTokens.additionalFaces;
|
2021-11-09 20:59:22 +00:00
|
|
|
server.timeout = cfg.serverTimeout;
|
|
|
|
snippet_support = cfg.enableSnippets;
|
|
|
|
verbosity = 255;
|
2024-07-10 20:20:00 +00:00
|
|
|
language_server = toLspConfig (lspConfig.language_servers // cfg.languageServers);
|
2024-04-06 21:56:46 +00:00
|
|
|
language_ids = lspConfig.language_ids // cfg.languageIds;
|
2024-06-11 17:43:48 +00:00
|
|
|
};
|
|
|
|
};
|
2021-09-30 19:31:57 +00:00
|
|
|
};
|
|
|
|
}
|
2024-06-11 17:43:48 +00:00
|
|
|
|