{ pkgs, lib, config, ... }: with builtins; with lib; let settingsFormat = pkgs.formats.json {}; in { config = { extraLua = let json_setup = settingsFormat.generate "nix-neovim-lsp-server-setup.json" config.lspconfig; in if config.isDesktop then '' local from_json = require('nix-neovim.utils').from_json for k, v in pairs(from_json("${json_setup}")) do require("lspconfig")[k].setup(v) end '' else ""; output.path.path = if config.isDesktop then config.lspconfigPath else []; output.plugins = if config.isDesktop then [pkgs.vimPlugins.nvim-lspconfig] else []; vim.keybindings.keybindings = if config.isDesktop then { "".l = { e = { command = "lua vim.diagnostic.open_float()"; label = "Open diagnostic float"; }; "[" = { command = "lua vim.diagnostic.goto_prev()"; label = "Prev diagnostic"; }; "]" = { command = "lua vim.diagnostic.goto_next()"; label = "Next diagnostic"; }; q = { command = "lua vim.diagnostic.setloclist"; label = "Add buffer diagnostics to loc list"; }; K = { command = "lua vim.lsp.buf.hover()"; label = "Hover"; }; "" = { command = "lua vim.lsp.buf.signature_help()"; label = "Signature help"; }; w = { a = { command = "lua vim.lsp.buf.add_workspace_folder()"; label = "Add workspace folder"; }; r = { command = "lua vim.lsp.buf.remove_workspace_folder()"; label = "Remove workspace folder"; }; l = { command = "lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))"; label = "List workspace folders"; }; }; D = { command = "lua vim.lsp.buf.type_definition()"; label = "Show type definition"; }; r.n = { command = "lua vim.lsp.buf.rename()"; label = "Rename buffer"; }; c.a = { command = "lua vim.lsp.buf.code_action()"; label = "Code action"; }; f = { command = "lua vim.lsp.buf.format({asyync = true})"; label = "Format buffer"; }; }; g = { D = { command = "lua vim.lsp.buf.declaration()"; label = "Declaration"; }; d = { command = "lua vim.lsp.buf.definition()"; label = "Definition"; }; i = { command = "lua vim.lsp.buf.implementation()"; label = "Implementation"; }; r = { command = "lua vim.lsp.buf.references()"; label = "References"; }; }; } else {}; }; options.lspconfig = mkOption { type = with types; attrsOf (submodule {freeformType = settingsFormat.type;}); default = {}; description = '' A set of options to `require("lspconfig").KEY.setup(VALUE)` in lua. ''; }; options.lspconfigPath = mkOption { type = with types; listOf package; default = []; description = "lspconfig binaries."; }; }