Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

treewide: language refactor #382

Draft
wants to merge 5 commits into
base: v0.7
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,18 @@
flake = false;
};

# Formatters
plugin-conform-nvim = {
url = "github:stevearc/conform.nvim";
flake = false;
};

# Diagnostics
plugin-nvim-lint = {
url = "github:mfussenegger/nvim-lint";
flake = false;
};

# Copying/Registers
plugin-registers = {
url = "github:tversteeg/registers.nvim";
Expand Down
16 changes: 9 additions & 7 deletions lib/languages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@
inherit (lib.types) bool;
inherit (lib.nvim.attrsets) mapListToAttrs;
in {
# A wrapper around `mkOption` to create a boolean option that is
# used for Language Server modules.
mkEnable = desc:
mkOption {
description = "Turn on ${desc} for enabled languages by default";
type = bool;
default = false;
};

# Converts a boolean to a yes/no string. This is used in lots of
# configuration formats.
diagnosticsToLua = {
Expand All @@ -27,11 +36,4 @@ in {
value = diagnosticsProviders.${type}.nullConfig package;
})
config;

mkEnable = desc:
mkOption {
description = "Turn on ${desc} for enabled languages by default";
type = bool;
default = false;
};
}
1 change: 1 addition & 0 deletions modules/modules.nix
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"dashboard"
"debugger"
"filetree"
"formatter"
"git"
"languages"
"lsp"
Expand Down
3 changes: 3 additions & 0 deletions modules/plugins/diagnostics/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
imports = [./nvim-lint];
}
20 changes: 20 additions & 0 deletions modules/plugins/diagnostics/nvim-lint/config.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
config,
lib,
...
}: let
inherit (lib.modules) mkIf;
inherit (lib.nvim.dag) entryAnywhere;
inherit (lib.nvim.lua) toLuaObject;

cfg = config.vim.diagnostics.nvim-lint;
in {
config = mkIf cfg.enable {
vim = {
startPlugins = ["nvim-lint"];
pluginRC.nvim-lint = entryAnywhere ''
require("lint").setup(${toLuaObject cfg.setupOpts})
'';
};
};
}
6 changes: 6 additions & 0 deletions modules/plugins/diagnostics/nvim-lint/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
imports = [
./nvim-lint.nix
./config.nix
];
}
36 changes: 36 additions & 0 deletions modules/plugins/diagnostics/nvim-lint/nvim-lint.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
pkgs,
lib,
...
}: let
inherit (lib.options) mkOption mkEnableOption literalExpression;
inherit (lib.types) attrs attrsOf listOf str;
inherit (lib.nvim.types) mkPluginSetupOption;
in {
options.vim.diagnostics.nvim-lint = {
enable = mkEnableOption "asynchronous linter plugin for Neovim [nvim-lint]";
setupOpts = mkPluginSetupOption "conform.nvim" {
linters_by_ft = mkOption {
type = attrsOf (listOf str);
default = {};
example = {
text = ["vale"];
markdown = ["vale"];
};
description = ''
Map of filetype to formatters. This option takes a set of
`key = value` format where the `value will` be converted
to its Lua equivalent. You are responsible for passing the
correct Nix data types to generate a correct Lua value that
conform is able to accept.
'';
};

default_format_opts = mkOption {
type = attrs;
default = {lsp_format = "fallback";};
description = "Default values when calling `conform.format()`";
};
};
};
}
20 changes: 20 additions & 0 deletions modules/plugins/formatter/conform-nvim/config.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
config,
lib,
...
}: let
inherit (lib.modules) mkIf;
inherit (lib.nvim.dag) entryAnywhere;
inherit (lib.nvim.lua) toLuaObject;

cfg = config.vim.formatter.conform-nvim;
in {
config = mkIf cfg.enable {
vim = {
startPlugins = ["conform-nvim"];
pluginRC.conform-nvim = entryAnywhere ''
require("conform").setup(${toLuaObject cfg.setupOpts})
'';
};
};
}
61 changes: 61 additions & 0 deletions modules/plugins/formatter/conform-nvim/conform-nvim.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
pkgs,
lib,
...
}: let
inherit (lib.options) mkOption mkEnableOption literalExpression;
inherit (lib.types) attrs enum;
inherit (lib.nvim.types) mkPluginSetupOption;
in {
options.vim.formatter.conform-nvim = {
enable = mkEnableOption "lightweight yet powerful formatter plugin for Neovim [conform-nvim]";
setupOpts = mkPluginSetupOption "conform.nvim" {
formatters_by_ft = mkOption {
type = attrs;
default = {};
example = literalExpression "lua = [\"${pkgs.stylua}/bin/stylua\"]";
description = ''
Map of filetype to formatters. This option takes a set of
`key = value` format where the `value will` be converted
to its Lua equivalent. You are responsible for passing the
correct Nix data types to generate a correct Lua value that
conform is able to accept.
'';
};

default_format_opts = mkOption {
type = attrs;
default = {lsp_format = "fallback";};
description = "Default values when calling `conform.format()`";
};

format_on_save = mkOption {
type = attrs;
default = {
lsp_format = "fallback";
timeout_ms = 500;
};
description = ''
Table that will be passed to `conform.format()`. If this
is set, Conform will run the formatter on save.
'';
};

format_after_save = mkOption {
type = attrs;
default = {lsp_format = "fallback";};
description = ''
Table that will be passed to `conform.format()`. If this
is set, Conform will run the formatter asynchronously after
save.
'';
};

log_level = mkOption {
type = enum ["vim.log.levels.ERROR" "vim.log.levels.WARN" "vim.log.levels.INFO" "vim.log.levels.DEBUG"];
default = "vim.log.levels.ERROR"; # TODO: make this luaInline
description = "Logging level for conform-nvim";
};
};
};
}
6 changes: 6 additions & 0 deletions modules/plugins/formatter/conform-nvim/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
imports = [
./conform-nvim.nix
./config.nix
];
}
3 changes: 3 additions & 0 deletions modules/plugins/formatter/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
imports = [./conform-nvim];
}
48 changes: 45 additions & 3 deletions modules/plugins/languages/html.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,54 @@
lib,
...
}: let
inherit (lib.options) mkEnableOption mkOption;
inherit (builtins) attrNames;
inherit (lib.options) mkOption mkEnableOption;
inherit (lib.modules) mkIf mkMerge;
inherit (lib.types) bool;
inherit (lib.lists) optional;
inherit (lib.lists) optional isList;
inherit (lib.types) enum either package listOf str bool;
inherit (lib.nvim.types) mkGrammarOption;
inherit (lib.nvim.lua) expToLua;
inherit (lib.nvim.dag) entryAnywhere;

cfg = config.vim.languages.html;

defaultServer = "html";
servers = {
html = {
package = pkgs.vscode-langservers-extracted;
lspConfig = ''
lspconfig.html.setup{
capabilities = capabilities;
on_attach = default_on_attach;
cmd = ${
if isList cfg.lsp.package
then expToLua cfg.lsp.package
else ''{"${cfg.lsp.package}/bin/vscode-html-language-server", "--stdio"}''
};
}
'';
};
};
in {
options.vim.languages.html = {
enable = mkEnableOption "HTML language support";

lsp = {
enable = mkEnableOption "Enable HTML LSP support" // {default = config.vim.languages.enableLSP;};

server = mkOption {
type = enum (attrNames servers);
default = defaultServer;
description = "HTML LSP server to use";
};

package = mkOption {
type = either package (listOf str);
default = pkgs.vscode-langservers-extracted;
description = "html-language-server package, or the command to run as a list of strings";
};
};

treesitter = {
enable = mkEnableOption "HTML treesitter support" // {default = config.vim.languages.enableTreesitter;};
package = mkGrammarOption pkgs "html";
Expand All @@ -27,6 +64,11 @@ in {
};

config = mkIf cfg.enable (mkMerge [
(mkIf cfg.lsp.enable {
vim.lsp.lspconfig.enable = true;
vim.lsp.lspconfig.sources.html-lsp = servers.${cfg.lsp.server}.lspConfig;
})

(mkIf cfg.treesitter.enable {
vim = {
startPlugins = optional cfg.treesitter.autotagHtml "nvim-ts-autotag";
Expand Down
Loading